war factory behavior is sortof sane, if glitchy

This commit is contained in:
Chris Forbes
2009-10-24 19:41:16 +13:00
parent 4aa172a7a7
commit 801c47daa6
2 changed files with 35 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ namespace OpenRa.Game.Graphics
readonly string name; readonly string name;
Sequence currentSequence; Sequence currentSequence;
int frame = 0; int frame = 0;
bool backwards = false;
bool tickAlways; bool tickAlways;
public Animation( string name ) public Animation( string name )
@@ -15,7 +16,16 @@ namespace OpenRa.Game.Graphics
Play( "idle" ); Play( "idle" );
} }
public Sprite Image { get { return currentSequence.GetSprite( frame ); } } public Sprite Image
{
get
{
return backwards
? currentSequence.GetSprite(currentSequence.End - frame - 1)
: currentSequence.GetSprite(frame);
}
}
public float2 Center { get { return 0.25f * new float2(currentSequence.GetSprite(0).bounds.Size); } } public float2 Center { get { return 0.25f * new float2(currentSequence.GetSprite(0).bounds.Size); } }
public void Play( string sequenceName ) public void Play( string sequenceName )
@@ -23,6 +33,11 @@ namespace OpenRa.Game.Graphics
PlayThen(sequenceName, () => { }); PlayThen(sequenceName, () => { });
} }
public void PlayBackwards(string sequenceName)
{
PlayBackwardsThen(sequenceName, () => { });
}
public void PlayRepeating( string sequenceName ) public void PlayRepeating( string sequenceName )
{ {
PlayThen( sequenceName, () => PlayRepeating( sequenceName ) ); PlayThen( sequenceName, () => PlayRepeating( sequenceName ) );
@@ -30,6 +45,7 @@ namespace OpenRa.Game.Graphics
public void PlayThen( string sequenceName, Action after ) public void PlayThen( string sequenceName, Action after )
{ {
backwards = false;
tickAlways = false; tickAlways = false;
currentSequence = SequenceProvider.GetSequence( name, sequenceName ); currentSequence = SequenceProvider.GetSequence( name, sequenceName );
frame = 0; frame = 0;
@@ -45,8 +61,15 @@ namespace OpenRa.Game.Graphics
}; };
} }
public void PlayBackwardsThen(string sequenceName, Action after)
{
PlayThen(sequenceName, after);
backwards = true;
}
public void PlayFetchIndex( string sequenceName, Func<int> func ) public void PlayFetchIndex( string sequenceName, Func<int> func )
{ {
backwards = false;
tickAlways = true; tickAlways = true;
currentSequence = SequenceProvider.GetSequence( name, sequenceName ); currentSequence = SequenceProvider.GetSequence( name, sequenceName );
frame = func(); frame = func();

View File

@@ -11,6 +11,7 @@ namespace OpenRa.Game.Traits
{ {
public Animation roof; public Animation roof;
bool doneBuilding; bool doneBuilding;
bool isOpen;
public readonly Actor self; public readonly Actor self;
public RenderWarFactory(Actor self) public RenderWarFactory(Actor self)
@@ -37,14 +38,22 @@ namespace OpenRa.Game.Traits
{ {
base.Tick(self); base.Tick(self);
roof.Tick(); roof.Tick();
var b = self.Bounds;
if (isOpen && !Game.SelectUnitsInBox(
new float2(b.Left, b.Top),
new float2(b.Right, b.Bottom)).Any(a => a.traits.Contains<Mobile>()))
{
isOpen = false;
roof.PlayBackwardsThen("build-top", () => roof.Play("idle-top"));
}
} }
public void EjectUnit() public void EjectUnit()
{ {
/* todo: hold the door open */ /* todo: hold the door open */
roof.PlayThen("build-top", roof.PlayThen("build-top", () => isOpen = true);
() => roof.PlayRepeating("idle-top"));
} }
} }
} }