diff --git a/OpenRa.Game/Actor.cs b/OpenRa.Game/Actor.cs index 94976b2067..bb935ea355 100755 --- a/OpenRa.Game/Actor.cs +++ b/OpenRa.Game/Actor.cs @@ -111,10 +111,7 @@ namespace OpenRa.Game Game.PlaySound("unitlst1.aud", false); if (traits.Contains()) - { 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()) nd.Damaged(this, DamageState.Half); } + + foreach (var ndx in traits.WithInterface()) + ndx.Damaged(this, damage); } } } diff --git a/OpenRa.Game/Traits/RenderUnit.cs b/OpenRa.Game/Traits/RenderUnit.cs index d0c6a20c11..efd2ac58ae 100644 --- a/OpenRa.Game/Traits/RenderUnit.cs +++ b/OpenRa.Game/Traits/RenderUnit.cs @@ -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().facing - / (256 / anim.CurrentSequence.Length)); + () => Util.QuantizeFacing( + self.traits.Get().facing, + anim.CurrentSequence.Length )); } public void PlayCustomAnimation(Actor self, string newAnim, Action after) @@ -30,6 +32,34 @@ namespace OpenRa.Game.Traits public override IEnumerable> 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(); } } } diff --git a/OpenRa.Game/Traits/TraitsInterfaces.cs b/OpenRa.Game/Traits/TraitsInterfaces.cs index 07964cb483..5fe90e2541 100644 --- a/OpenRa.Game/Traits/TraitsInterfaces.cs +++ b/OpenRa.Game/Traits/TraitsInterfaces.cs @@ -13,4 +13,5 @@ namespace OpenRa.Game.Traits interface IRender { IEnumerable> 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); } } diff --git a/sequences.xml b/sequences.xml index 078f0152ee..78faf4b299 100644 --- a/sequences.xml +++ b/sequences.xml @@ -510,4 +510,9 @@ + + + + + \ No newline at end of file