bullet test

This commit is contained in:
Chris Forbes
2009-10-18 22:56:34 +13:00
parent 4aea82712f
commit 46d52d077c
4 changed files with 38 additions and 4 deletions

View File

@@ -18,9 +18,14 @@ namespace OpenRa.Game
readonly int2 Src;
readonly int2 Dest;
int t = 0;
Animation anim;
const int BaseBulletSpeed = 100; /* pixels / ms */
/* src, dest are *pixel* coords */
public Bullet(string weapon, Player owner, Actor firedBy,
int2 src, int2 dest)
int2 src, int2 dest, Game game)
{
Owner = owner;
FiredBy = firedBy;
@@ -29,9 +34,30 @@ namespace OpenRa.Game
Weapon = Rules.WeaponInfo[weapon];
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
Warhead = Rules.WarheadInfo[Weapon.Warhead];
anim = new Animation(Projectile.Image);
anim.PlayRepeating("idle");
}
public void Tick(Game game, int dt) { /* todo */ }
public IEnumerable<Pair<Sprite, float2>> Render() { yield break; }
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public void Tick(Game game, int dt)
{
if (t == 0)
game.PlaySound(Weapon.Report + ".aud", false);
t += dt;
if (t > TotalTime())
t = 0; /* temporary! loop the bullet forever */
}
public IEnumerable<Pair<Sprite, float2>> Render()
{
yield return Pair.New(anim.Image,
float2.Lerp(
Src.ToFloat2(),
Dest.ToFloat2(),
(float)t / TotalTime()));
}
}
}

View File

@@ -58,7 +58,10 @@ using System.Runtime.InteropServices;
game.world.Add( new Actor( "mcv", new int2( 5, 5 ), game.players[ 3 ]) );
game.world.Add( new Actor( "mcv", new int2( 7, 5 ), game.players[ 2 ] ) );
game.world.Add( new Actor( "mcv", new int2( 9, 5 ), game.players[ 0 ] ) );
game.world.Add( new Actor( "jeep", new int2( 9, 7 ), game.players[ 1 ] ) );
game.world.Add( new Actor( "jeep", new int2( 9, 7 ), game.players[ 1 ] ) );
game.world.Add(new Bullet("105mm", game.players[1], null,
new int2(200, 200), new int2(400, 200), game));
sidebar = new Sidebar(renderer, game);