made muzzleflash a lot saner; implemented E4 for cnc

This commit is contained in:
Chris Forbes
2010-04-17 13:13:18 +12:00
parent ac449e4b66
commit 22494d7e8b
6 changed files with 150 additions and 115 deletions

View File

@@ -22,27 +22,37 @@ using OpenRA.Graphics;
namespace OpenRA.Traits
{
class RenderUnitMuzzleFlashInfo : RenderUnitInfo
class WithMuzzleFlashInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
{
public override object Create(Actor self) { return new RenderUnitMuzzleFlash(self); }
public object Create(Actor self) { return new WithMuzzleFlash(self); }
}
class RenderUnitMuzzleFlash : RenderUnit
class WithMuzzleFlash : INotifyAttack
{
public RenderUnitMuzzleFlash(Actor self)
: base(self)
Animation muzzleFlash;
bool isShowing;
public WithMuzzleFlash(Actor self)
{
var unit = self.traits.Get<Unit>();
var attack = self.traits.Get<AttackBase>();
var attackInfo = self.Info.Traits.Get<AttackBaseInfo>();
var render = self.traits.Get<RenderSimple>();
var muzzleFlash = new Animation(GetImage(self), ()=>unit.Facing);
muzzleFlash.PlayFetchIndex("muzzle",
() => (int)(attack.primaryRecoil * 5.9f));
anims.Add( "muzzle", new AnimationWithOffset(
muzzleFlash = new Animation(render.GetImage(self), () => unit.Facing);
muzzleFlash.Play("muzzle");
var len = muzzleFlash.CurrentSequence.Length;
render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset(
muzzleFlash,
() => attackInfo.PrimaryOffset.AbsOffset(),
() => attack.primaryRecoil <= 0 ) );
() => !isShowing));
}
public void Attacking(Actor self)
{
isShowing = true;
muzzleFlash.PlayThen("muzzle", () => isShowing = false);
}
}
}