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

@@ -23,6 +23,7 @@ namespace OpenRa
public int2 Sign() { return new int2(Math.Sign(X), Math.Sign(Y)); } public int2 Sign() { return new int2(Math.Sign(X), Math.Sign(Y)); }
public int2 Abs() { return new int2( Math.Abs( X ), Math.Abs( Y ) ); } public int2 Abs() { return new int2( Math.Abs( X ), Math.Abs( Y ) ); }
public int Length { get { return (int)Math.Sqrt(X * X + Y * Y); } }
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); } public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public override bool Equals(object obj) public override bool Equals(object obj)

View File

@@ -18,9 +18,14 @@ namespace OpenRa.Game
readonly int2 Src; readonly int2 Src;
readonly int2 Dest; readonly int2 Dest;
int t = 0;
Animation anim;
const int BaseBulletSpeed = 100; /* pixels / ms */
/* src, dest are *pixel* coords */ /* src, dest are *pixel* coords */
public Bullet(string weapon, Player owner, Actor firedBy, public Bullet(string weapon, Player owner, Actor firedBy,
int2 src, int2 dest) int2 src, int2 dest, Game game)
{ {
Owner = owner; Owner = owner;
FiredBy = firedBy; FiredBy = firedBy;
@@ -29,9 +34,30 @@ namespace OpenRa.Game
Weapon = Rules.WeaponInfo[weapon]; Weapon = Rules.WeaponInfo[weapon];
Projectile = Rules.ProjectileInfo[Weapon.Projectile]; Projectile = Rules.ProjectileInfo[Weapon.Projectile];
Warhead = Rules.WarheadInfo[Weapon.Warhead]; Warhead = Rules.WarheadInfo[Weapon.Warhead];
anim = new Animation(Projectile.Image);
anim.PlayRepeating("idle");
} }
public void Tick(Game game, int dt) { /* todo */ } int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public IEnumerable<Pair<Sprite, float2>> Render() { yield break; }
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( 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( 7, 5 ), game.players[ 2 ] ) );
game.world.Add( new Actor( "mcv", new int2( 9, 5 ), game.players[ 0 ] ) ); 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); sidebar = new Sidebar(renderer, game);

View File

@@ -330,5 +330,9 @@
<sequence name="move-minimap" start="29" length="6" /> <sequence name="move-minimap" start="29" length="6" />
<sequence name="repair" start="35" length="24" /> <sequence name="repair" start="35" length="24" />
</cursor> </cursor>
<unit name="120mm">
<sequence name="idle" start="0" length="1" />
</unit>
</sequences> </sequences>