This commit is contained in:
Bob
2009-10-24 19:49:27 +13:00
4 changed files with 58 additions and 11 deletions

View File

@@ -191,14 +191,16 @@ namespace OpenRa.Game
if (producer == null)
throw new InvalidOperationException("BuildUnit without suitable production structure!");
var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player);
var mobile = unit.traits.Get<Mobile>();
mobile.facing = 128;
var unit = new Actor(name, (1/24f * producer.CenterLocation).ToInt2(), player);
var mobile = unit.traits.Get<Mobile>();
mobile.facing = 128;
mobile.QueueAction( new Traits.Mobile.MoveTo( unit.Location + new int2( 0, 3 ) ) );
world.AddFrameEndTask(_ => world.Add(unit));
// todo: make the producing building play `build`
if (producer.traits.Contains<RenderWarFactory>())
producer.traits.Get<RenderWarFactory>().EjectUnit();
}
}
}

View File

@@ -7,6 +7,7 @@ namespace OpenRa.Game.Graphics
readonly string name;
Sequence currentSequence;
int frame = 0;
bool backwards = false;
bool tickAlways;
public Animation( string name )
@@ -15,7 +16,16 @@ namespace OpenRa.Game.Graphics
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 void Play( string sequenceName )
@@ -23,6 +33,11 @@ namespace OpenRa.Game.Graphics
PlayThen(sequenceName, () => { });
}
public void PlayBackwards(string sequenceName)
{
PlayBackwardsThen(sequenceName, () => { });
}
public void PlayRepeating( string sequenceName )
{
PlayThen( sequenceName, () => PlayRepeating( sequenceName ) );
@@ -30,6 +45,7 @@ namespace OpenRa.Game.Graphics
public void PlayThen( string sequenceName, Action after )
{
backwards = false;
tickAlways = false;
currentSequence = SequenceProvider.GetSequence( name, sequenceName );
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 )
{
backwards = false;
tickAlways = true;
currentSequence = SequenceProvider.GetSequence( name, sequenceName );
frame = func();

View File

@@ -44,8 +44,8 @@ namespace OpenRa.Game.Graphics
spriteRenderer.DrawSprite(image.First, loc,
(owner != null) ? owner.Palette : 0);
}
}
}
public void Draw()
{
var rect = new RectangleF((region.Position + Game.viewport.Location).ToPointF(),
@@ -54,6 +54,11 @@ namespace OpenRa.Game.Graphics
foreach (Actor a in Game.world.Actors.OrderBy( u => u.CenterLocation.Y ))
DrawSpriteList(a.Owner, rect, a.Render());
foreach (var a in Game.world.Actors
.Where(u => u.traits.Contains<Traits.RenderWarFactory>())
.Select(u => u.traits.Get<Traits.RenderWarFactory>()))
DrawSpriteList(a.self.Owner, rect, a.RenderRoof(a.self)); /* RUDE HACK */
foreach (IEffect e in Game.world.Effects)
DrawSpriteList(e.Owner, rect, e.Render());

View File

@@ -11,10 +11,14 @@ namespace OpenRa.Game.Traits
{
public Animation roof;
bool doneBuilding;
bool isOpen;
public readonly Actor self;
public RenderWarFactory(Actor self)
: base(self)
{
this.self = self;
roof = new Animation(self.unitInfo.Image ?? self.unitInfo.Name);
anim.PlayThen("make", () =>
{
@@ -24,19 +28,32 @@ namespace OpenRa.Game.Traits
});
}
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
public IEnumerable<Pair<Sprite, float2>> RenderRoof(Actor self)
{
if (doneBuilding)
return base.Render(self).Concat(
new[] { Pair.New(roof.Image, 24f * (float2)self.Location) });
else
return base.Render(self);
yield return Pair.New(roof.Image, 24f * (float2)self.Location);
}
public override void Tick(Actor self)
{
base.Tick(self);
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()
{
/* todo: hold the door open */
roof.PlayThen("build-top", () => isOpen = true);
}
}
}