Ditto for Corpse.

This commit is contained in:
Paul Chote
2013-02-24 15:18:34 +13:00
parent e33c783fc1
commit fa5cf96f40
3 changed files with 20 additions and 20 deletions

View File

@@ -13,10 +13,11 @@ using System.Linq;
using OpenRA.Traits;
using OpenRA.Mods.RA.Effects;
using OpenRA.Mods.RA.Move;
using OpenRA.Mods.RA.Render;
namespace OpenRA.Mods.RA
{
class CrushableInfantryInfo : ITraitInfo, Requires<MobileInfo>
class CrushableInfantryInfo : ITraitInfo, Requires<MobileInfo>, Requires<RenderInfantryInfo>
{
public readonly string CrushSound = "squish2.aud";
public readonly string CorpseSequence = "die-crushed";
@@ -29,11 +30,13 @@ namespace OpenRA.Mods.RA
{
readonly Actor self;
readonly CrushableInfantryInfo Info;
readonly RenderInfantry ri;
public CrushableInfantry(Actor self, CrushableInfantryInfo info)
{
this.self = self;
this.Info = info;
ri = self.Trait<RenderInfantry>();
}
public void WarnCrush(Actor crusher)
@@ -45,12 +48,7 @@ namespace OpenRA.Mods.RA
public void OnCrush(Actor crusher)
{
Sound.Play(Info.CrushSound, crusher.CenterLocation);
self.World.AddFrameEndTask(w =>
{
if (!self.Destroyed)
w.Add(new Corpse(self, Info.CorpseSequence));
});
ri.SpawnCorpse(self, Info.CorpseSequence);
self.Kill(crusher);
}

View File

@@ -19,25 +19,21 @@ namespace OpenRA.Mods.RA.Effects
{
readonly Animation anim;
readonly float2 pos;
readonly RenderSimple rs;
readonly Player p;
readonly string paletteName;
public Corpse(Actor fromActor, string sequence)
public Corpse(World world, float2 pos, string image, string sequence, string paletteName)
{
p = fromActor.Owner;
rs = fromActor.Trait<RenderSimple>();
anim = new Animation(rs.GetImage(fromActor));
anim.PlayThen(sequence,
() => fromActor.World.AddFrameEndTask(w => w.Remove(this)));
pos = fromActor.CenterLocation.ToFloat2();
this.pos = pos;
this.paletteName = paletteName;
anim = new Animation(image);
anim.PlayThen(sequence, () => world.AddFrameEndTask(w => w.Remove(this)));
}
public void Tick(World world) { anim.Tick(); }
public IEnumerable<Renderable> Render(WorldRenderer wr)
{
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, rs.Palette(p, wr), (int)pos.Y);
yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, wr.Palette(paletteName), (int)pos.Y);
}
}
}

View File

@@ -124,10 +124,16 @@ namespace OpenRA.Mods.RA.Render
return;
Sound.PlayVoice("Die", self, self.Owner.Country.Race);
SpawnCorpse(self, "die{0}".F(e.Warhead.InfDeath));
}
public void SpawnCorpse(Actor self, string sequence)
{
self.World.AddFrameEndTask(w =>
{
if (!self.Destroyed)
w.Add(new Corpse(self, "die{0}".F(e.Warhead.InfDeath)));
w.Add(new Corpse(w, self.CenterLocation.ToFloat2(), GetImage(self),
sequence, Info.PlayerPalette+self.Owner.InternalName));
});
}
}