Files
OpenRA/OpenRA.Mods.RA/WithMuzzleFlash.cs

48 lines
1.3 KiB
C#

#region Copyright & License Information
/*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see LICENSE.
*/
#endregion
using OpenRA.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.RA
{
class WithMuzzleFlashInfo : ITraitInfo, ITraitPrerequisite<RenderSimpleInfo>
{
public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); }
}
class WithMuzzleFlash : INotifyAttack
{
Animation muzzleFlash;
bool isShowing;
public WithMuzzleFlash(Actor self)
{
var move = self.traits.Get<IMove>();
var attackInfo = self.Info.Traits.Get<AttackBaseInfo>();
var render = self.traits.Get<RenderSimple>();
muzzleFlash = new Animation(render.GetImage(self), () => move.Facing);
muzzleFlash.Play("muzzle");
render.anims.Add("muzzle", new RenderSimple.AnimationWithOffset(
muzzleFlash,
() => attackInfo.PrimaryOffset.AbsOffset(),
() => !isShowing));
}
public void Attacking(Actor self)
{
isShowing = true;
muzzleFlash.PlayThen("muzzle", () => isShowing = false);
}
}
}