This commit is contained in:
Chris Forbes
2009-11-09 21:19:37 +13:00
parent 0e1e62eacc
commit 49f48bef6a
4 changed files with 42 additions and 6 deletions

View File

@@ -111,10 +111,7 @@ namespace OpenRa.Game
Game.PlaySound("unitlst1.aud", false);
if (traits.Contains<Building>())
{
Game.PlaySound("kaboom22.aud", false);
// todo: spawn explosion sprites
}
}
var halfStrength = unitInfo.Strength * Rules.General.ConditionYellow;
@@ -124,6 +121,9 @@ namespace OpenRa.Game
foreach (var nd in traits.WithInterface<INotifyDamage>())
nd.Damaged(this, DamageState.Half);
}
foreach (var ndx in traits.WithInterface<INotifyDamageEx>())
ndx.Damaged(this, damage);
}
}
}

View File

@@ -7,19 +7,21 @@ using IjwFramework.Types;
namespace OpenRa.Game.Traits
{
class RenderUnit : RenderSimple
class RenderUnit : RenderSimple, INotifyDamageEx
{
public RenderUnit(Actor self)
: base(self)
{
PlayFacingAnim(self);
smoke = new Animation("smoke_m");
}
void PlayFacingAnim(Actor self)
{
anim.PlayFetchIndex("idle",
() => self.traits.Get<Mobile>().facing
/ (256 / anim.CurrentSequence.Length));
() => Util.QuantizeFacing(
self.traits.Get<Mobile>().facing,
anim.CurrentSequence.Length ));
}
public void PlayCustomAnimation(Actor self, string newAnim, Action after)
@@ -30,6 +32,34 @@ namespace OpenRa.Game.Traits
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
{
yield return Util.Centered(anim.Image, self.CenterLocation);
if (isSmoking)
yield return Util.Centered(smoke.Image, self.CenterLocation);
}
bool isSmoking;
DamageState currentDs;
Animation smoke;
public void Damaged(Actor self, DamageState ds) { currentDs = ds; }
public void Damaged(Actor self, int damage)
{
if (currentDs != DamageState.Half) return;
if (!isSmoking)
{
isSmoking = true;
smoke.PlayThen("idle",
() => smoke.PlayThen("loop",
() => smoke.PlayBackwardsThen("end",
() => isSmoking = false)));
}
}
public override void Tick(Actor self)
{
base.Tick(self);
if (isSmoking)
smoke.Tick();
}
}
}

View File

@@ -13,4 +13,5 @@ namespace OpenRa.Game.Traits
interface IRender { IEnumerable<Pair<Sprite, float2>> Render(Actor self); }
interface IOrder { Order Order(Actor self, int2 xy, bool lmb, Actor underCursor); }
interface INotifyDamage { void Damaged(Actor self, DamageState ds); }
interface INotifyDamageEx : INotifyDamage { void Damaged(Actor self, int damage); }
}

View File

@@ -510,4 +510,9 @@
<unit name="flagfly">
<sequence name="idle" start="0" length="14" />
</unit>
<unit name="smoke_m">
<sequence name="idle" start="0" length="91" />
<sequence name="loop" start="49" length="42" />
<sequence name="end" start="0" length="26" />
</unit>
</sequences>