bullet test
This commit is contained in:
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user