#region Copyright & License Information /* * Copyright 2007-2011 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 COPYING. */ #endregion using System.Collections.Generic; using OpenRA.Graphics; using OpenRA.Traits; namespace OpenRA.Mods.RA.Render { class WithMuzzleFlashInfo : ITraitInfo, Requires { public object Create(ActorInitializer init) { return new WithMuzzleFlash(init.self); } } class WithMuzzleFlash : INotifyAttack { List muzzleFlashes = new List(); bool isShowing; public WithMuzzleFlash(Actor self) { var attack = self.Trait(); var render = self.Trait(); var facing = self.Trait(); foreach (var t in attack.Turrets) { var turret = t; var muzzleFlash = new Animation(render.GetImage(self), () => self.Trait().Facing); muzzleFlash.Play("muzzle"); render.anims.Add("muzzle{0}".F(muzzleFlashes.Count), new RenderSimple.AnimationWithOffset( muzzleFlash, () => Combat.GetTurretPosition(self, facing, turret), () => !isShowing)); muzzleFlashes.Add(muzzleFlash); } } public void Attacking(Actor self, Target target) { isShowing = true; foreach( var mf in muzzleFlashes ) mf.PlayThen("muzzle", () => isShowing = false); } } }