diff --git a/OpenRa.Game/Animation.cs b/OpenRa.Game/Animation.cs index a853183877..3875a4da7a 100644 --- a/OpenRa.Game/Animation.cs +++ b/OpenRa.Game/Animation.cs @@ -14,12 +14,22 @@ namespace OpenRa.Game public Animation( string name ) { this.name = name; - PlayToEnd( "idle" ); + Play( "idle" ); } public Sprite[] Images { get { return new Sprite[] { currentSequence.GetSprite( frame ) }; } } - public void PlayToEnd( string sequenceName ) + public void Play( string sequenceName ) + { + PlayThen( sequenceName, delegate { } ); + } + + public void PlayRepeating( string sequenceName ) + { + PlayThen( sequenceName, delegate { PlayRepeating( sequenceName ); } ); + } + + public void PlayThen( string sequenceName, MethodInvoker after ) { currentSequence = SequenceProvider.GetSequence( name, sequenceName ); frame = 0; @@ -30,20 +40,11 @@ namespace OpenRa.Game { frame = currentSequence.Length - 1; tickFunc = delegate { }; + after(); } }; } - public void PlayRepeating( string sequenceName ) - { - currentSequence = SequenceProvider.GetSequence( name, sequenceName ); - frame = 0; - tickFunc = delegate - { - frame = ( frame + 1 ) % currentSequence.Length; - }; - } - Action tickFunc; public void Tick( double t ) { diff --git a/OpenRa.Game/Building.cs b/OpenRa.Game/Building.cs new file mode 100644 index 0000000000..8c824359d8 --- /dev/null +++ b/OpenRa.Game/Building.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace OpenRa.Game +{ + class Building : Actor + { + protected Animation animation; + + public Building( string name, int2 location, int palette ) + { + this.renderLocation = 24.0f * location.ToFloat2(); + this.palette = palette; + + animation = new Animation( name ); + animation.PlayThen( "make", delegate { animation.Play( "idle" ); } ); + } + + public override void Tick( World world, double t ) + { + animation.Tick( t ); + } + + public override Sprite[] CurrentImages + { + get { return animation.Images; } + } + } +} diff --git a/OpenRa.Game/ConstructionYard.cs b/OpenRa.Game/ConstructionYard.cs index c55fff5cb7..f9be7c8f88 100644 --- a/OpenRa.Game/ConstructionYard.cs +++ b/OpenRa.Game/ConstructionYard.cs @@ -5,25 +5,12 @@ using BluntDirectX.Direct3D; namespace OpenRa.Game { - class ConstructionYard : Actor + class ConstructionYard : Building { - Animation animation = new Animation( "fact" ); - - public ConstructionYard(float2 location, int palette) + public ConstructionYard( int2 location, int palette ) + : base( "fact", location, palette ) { - this.renderLocation = location; - this.palette = palette; - animation.PlayToEnd( "make" ); - } - - public override Sprite[] CurrentImages - { - get { return animation.Images; } - } - - public override void Tick( World world, double t ) - { - animation.Tick( t ); + animation.PlayThen( "make", delegate { animation.PlayRepeating( "build" ); } ); } } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 15870843ca..46add3e4bf 100644 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -67,6 +67,7 @@ namespace OpenRa.Game Mcv mcv = new Mcv( new int2( 9, 5 ), 1 ); myUnit = mcv; world.Add( mcv ); + world.Add( new Refinery( new int2( 7, 5 ), 2 ) ); sidebar = new Sidebar(Race.Soviet, renderer, viewport); } diff --git a/OpenRa.Game/Mcv.cs b/OpenRa.Game/Mcv.cs index e4728e78a4..b1eecc1da5 100644 --- a/OpenRa.Game/Mcv.cs +++ b/OpenRa.Game/Mcv.cs @@ -133,8 +133,9 @@ namespace OpenRa.Game world.AddFrameEndTask(delegate { world.Remove( this ); - world.Add(new ConstructionYard((fromCell * 24 - new int2(24, 24)).ToFloat2(), palette)); - }); + world.Add( new ConstructionYard( fromCell - new int2( 1, 1 ), palette ) ); + world.Add( new Refinery( fromCell - new int2( 1, -2 ), palette ) ); + } ); currentOrder = null; } }; diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 90405a83c6..6f0b8e71e6 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -42,6 +42,7 @@ + diff --git a/OpenRa.Game/Refinery.cs b/OpenRa.Game/Refinery.cs index 1e38c9af28..6fa7cac46f 100644 --- a/OpenRa.Game/Refinery.cs +++ b/OpenRa.Game/Refinery.cs @@ -7,20 +7,11 @@ using System.Drawing; namespace OpenRa.Game { - class Refinery : Actor + class Refinery : Building { - Animation a = new Animation( "proc" ); - - public Refinery(float2 location, int palette) + public Refinery(int2 location, int palette) + : base( "proc", location, palette ) { - a.PlayToEnd( "idle" ); - this.renderLocation = location; - this.palette = palette; - } - - public override Sprite[] CurrentImages - { - get { return a.Images; } } } }