From 6af7d83fec45c818dca47005cd7e1ff155b0c8f7 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 22 Dec 2009 23:19:00 +1300 Subject: [PATCH] move flash --- OpenRa.Game/Controller.cs | 27 +++++++++++++++++---------- OpenRa.Game/Effects/MoveFlash.cs | 30 ++++++++++++++++++++++++++++++ OpenRa.Game/OpenRa.Game.csproj | 1 + sequences.xml | 13 ++++++++----- 4 files changed, 56 insertions(+), 15 deletions(-) create mode 100644 OpenRa.Game/Effects/MoveFlash.cs diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index 652017eb11..adf53bcb1c 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -25,17 +25,24 @@ namespace OpenRa.Game void ApplyOrders(float2 xy, MouseInput mi) { - var doVoice = null as Actor; - if (orderGenerator != null) - foreach (var order in orderGenerator.Order(xy.ToInt2(), mi)) - { - AddOrder( order ); - if (order.Subject != null && order.Player == Game.LocalPlayer) - doVoice = order.Subject; - } + if (orderGenerator == null) return; - if (doVoice != null && doVoice.traits.Contains()) - Sound.PlayVoice("Move", doVoice); + var orders = orderGenerator.Order(xy.ToInt2(), mi).ToArray(); + recentOrders.AddRange( orders ); + + var voicedActor = orders.Select(o => o.Subject) + .FirstOrDefault(a => a.Owner == Game.LocalPlayer && a.traits.Contains()); + + var isMove = orders.Any(o => o.OrderString == "Move"); + var isAttack = orders.Any( o => o.OrderString == "Attack" ); + + if (voicedActor != null) + { + Sound.PlayVoice(isAttack ? "Attack" : "Move", voicedActor); + + if (isMove) + Game.world.Add(new Effects.MoveFlash(Game.CellSize * xy)); + } } public void AddOrder(Order o) { recentOrders.Add(o); } diff --git a/OpenRa.Game/Effects/MoveFlash.cs b/OpenRa.Game/Effects/MoveFlash.cs new file mode 100644 index 0000000000..5a7a94b55b --- /dev/null +++ b/OpenRa.Game/Effects/MoveFlash.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using OpenRa.Game.Graphics; +using OpenRa.Game.Traits; + +namespace OpenRa.Game.Effects +{ + class MoveFlash : IEffect + { + Animation anim = new Animation("moveflsh"); + float2 pos; + + public MoveFlash( float2 pos ) + { + this.pos = pos; + anim.PlayThen( "idle", + () => Game.world.AddFrameEndTask( + w => w.Remove( this ) ) ); + } + + public void Tick() { anim.Tick(); } + + public IEnumerable Render() + { + yield return new Renderable(anim.Image, pos - .5f * anim.Image.size, 0); + } + } +} diff --git a/OpenRa.Game/OpenRa.Game.csproj b/OpenRa.Game/OpenRa.Game.csproj index 89375be11d..ca5f68d865 100644 --- a/OpenRa.Game/OpenRa.Game.csproj +++ b/OpenRa.Game/OpenRa.Game.csproj @@ -81,6 +81,7 @@ + diff --git a/sequences.xml b/sequences.xml index fcd5a1ed23..b250cfda16 100644 --- a/sequences.xml +++ b/sequences.xml @@ -1,4 +1,4 @@ - +