From 1bc3fc22c64eb5936c77c012348c5deb70a67966 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Tue, 20 Oct 2009 18:21:42 +1300 Subject: [PATCH] pulling IEffect out of Bullet in prep for Explosion --- OpenRa.Game/Bullet.cs | 28 ++++++++++++++++++--------- OpenRa.Game/Graphics/WorldRenderer.cs | 4 ++-- OpenRa.Game/MainWindow.cs | 2 +- OpenRa.Game/World.cs | 4 ++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/OpenRa.Game/Bullet.cs b/OpenRa.Game/Bullet.cs index 340f9d1e1e..0e3e255a06 100644 --- a/OpenRa.Game/Bullet.cs +++ b/OpenRa.Game/Bullet.cs @@ -4,13 +4,20 @@ using System.Linq; using System.Text; using OpenRa.Game.GameRules; using IjwFramework.Types; -using OpenRa.Game.Graphics; +using OpenRa.Game.Graphics; namespace OpenRa.Game -{ - class Bullet - { - public readonly Player Owner; +{ + interface IEffect + { + void Tick(Game g); + IEnumerable> Render(); + Player Owner { get; } + } + + class Bullet : IEffect + { + public Player Owner { get; private set; } readonly Actor FiredBy; readonly WeaponInfo Weapon; readonly ProjectileInfo Projectile; @@ -46,10 +53,13 @@ namespace OpenRa.Game if (t == 0) game.PlaySound(Weapon.Report + ".aud", false); - t += 40; - - if (t > TotalTime()) /* remove finished bullets */ - game.world.AddFrameEndTask(w => w.Remove(this)); + t += 40; + + if (t > TotalTime()) /* remove finished bullets */ + { + game.world.AddFrameEndTask(w => w.Remove(this)); + game.PlaySound("kaboom25.aud", false); + } } public IEnumerable> Render() diff --git a/OpenRa.Game/Graphics/WorldRenderer.cs b/OpenRa.Game/Graphics/WorldRenderer.cs index ab520609ba..c32ed17a2f 100644 --- a/OpenRa.Game/Graphics/WorldRenderer.cs +++ b/OpenRa.Game/Graphics/WorldRenderer.cs @@ -56,8 +56,8 @@ namespace OpenRa.Game.Graphics foreach (Actor a in game.world.Actors) DrawSpriteList(a.Owner, rect, a.Render()); - foreach (Bullet b in game.world.Bullets) - DrawSpriteList(b.Owner, rect, b.Render()); + foreach (IEffect e in game.world.Bullets) + DrawSpriteList(e.Owner, rect, e.Render()); uiOverlay.Draw(); diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 3c0102eb02..591bb644d9 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -62,7 +62,7 @@ using System.Runtime.InteropServices; game.world.Add( jeep ); var tank = new Actor( "3tnk", new int2( 12, 7 ), game.players[ 1 ] ); game.world.Add( tank ); - //tank.traits.Get().target = jeep; + tank.traits.Get().target = jeep; sidebar = new Sidebar(renderer, game); diff --git a/OpenRa.Game/World.cs b/OpenRa.Game/World.cs index 5b39e719c0..83533b21ee 100644 --- a/OpenRa.Game/World.cs +++ b/OpenRa.Game/World.cs @@ -8,7 +8,7 @@ namespace OpenRa.Game class World { List actors = new List(); - List bullets = new List(); + List bullets = new List(); List> frameEndActions = new List>(); readonly Game game; int lastTime = Environment.TickCount; @@ -53,6 +53,6 @@ namespace OpenRa.Game } public IEnumerable Actors { get { return actors; } } - public IEnumerable Bullets { get { return bullets; } } + public IEnumerable Bullets { get { return bullets; } } } }