pulling IEffect out of Bullet in prep for Explosion

This commit is contained in:
Chris Forbes
2009-10-20 18:21:42 +13:00
parent 5a67220f0e
commit 1bc3fc22c6
4 changed files with 24 additions and 14 deletions

View File

@@ -4,13 +4,20 @@ using System.Linq;
using System.Text; using System.Text;
using OpenRa.Game.GameRules; using OpenRa.Game.GameRules;
using IjwFramework.Types; using IjwFramework.Types;
using OpenRa.Game.Graphics; using OpenRa.Game.Graphics;
namespace OpenRa.Game namespace OpenRa.Game
{ {
class Bullet interface IEffect
{ {
public readonly Player Owner; void Tick(Game g);
IEnumerable<Pair<Sprite, float2>> Render();
Player Owner { get; }
}
class Bullet : IEffect
{
public Player Owner { get; private set; }
readonly Actor FiredBy; readonly Actor FiredBy;
readonly WeaponInfo Weapon; readonly WeaponInfo Weapon;
readonly ProjectileInfo Projectile; readonly ProjectileInfo Projectile;
@@ -46,10 +53,13 @@ namespace OpenRa.Game
if (t == 0) if (t == 0)
game.PlaySound(Weapon.Report + ".aud", false); game.PlaySound(Weapon.Report + ".aud", false);
t += 40; t += 40;
if (t > TotalTime()) /* remove finished bullets */ if (t > TotalTime()) /* remove finished bullets */
game.world.AddFrameEndTask(w => w.Remove(this)); {
game.world.AddFrameEndTask(w => w.Remove(this));
game.PlaySound("kaboom25.aud", false);
}
} }
public IEnumerable<Pair<Sprite, float2>> Render() public IEnumerable<Pair<Sprite, float2>> Render()

View File

@@ -56,8 +56,8 @@ namespace OpenRa.Game.Graphics
foreach (Actor a in game.world.Actors) foreach (Actor a in game.world.Actors)
DrawSpriteList(a.Owner, rect, a.Render()); DrawSpriteList(a.Owner, rect, a.Render());
foreach (Bullet b in game.world.Bullets) foreach (IEffect e in game.world.Bullets)
DrawSpriteList(b.Owner, rect, b.Render()); DrawSpriteList(e.Owner, rect, e.Render());
uiOverlay.Draw(); uiOverlay.Draw();

View File

@@ -62,7 +62,7 @@ using System.Runtime.InteropServices;
game.world.Add( jeep ); game.world.Add( jeep );
var tank = new Actor( "3tnk", new int2( 12, 7 ), game.players[ 1 ] ); var tank = new Actor( "3tnk", new int2( 12, 7 ), game.players[ 1 ] );
game.world.Add( tank ); game.world.Add( tank );
//tank.traits.Get<Traits.AttackTurreted>().target = jeep; tank.traits.Get<Traits.AttackTurreted>().target = jeep;
sidebar = new Sidebar(renderer, game); sidebar = new Sidebar(renderer, game);

View File

@@ -8,7 +8,7 @@ namespace OpenRa.Game
class World class World
{ {
List<Actor> actors = new List<Actor>(); List<Actor> actors = new List<Actor>();
List<Bullet> bullets = new List<Bullet>(); List<IEffect> bullets = new List<IEffect>();
List<Action<World>> frameEndActions = new List<Action<World>>(); List<Action<World>> frameEndActions = new List<Action<World>>();
readonly Game game; readonly Game game;
int lastTime = Environment.TickCount; int lastTime = Environment.TickCount;
@@ -53,6 +53,6 @@ namespace OpenRa.Game
} }
public IEnumerable<Actor> Actors { get { return actors; } } public IEnumerable<Actor> Actors { get { return actors; } }
public IEnumerable<Bullet> Bullets { get { return bullets; } } public IEnumerable<IEffect> Bullets { get { return bullets; } }
} }
} }