bullet test
This commit is contained in:
@@ -23,6 +23,7 @@ namespace OpenRa
|
||||
|
||||
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 int Length { get { return (int)Math.Sqrt(X * X + Y * Y); } }
|
||||
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
|
||||
|
||||
public override bool Equals(object obj)
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ using System.Runtime.InteropServices;
|
||||
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 Bullet("105mm", game.players[1], null,
|
||||
new int2(200, 200), new int2(400, 200), game));
|
||||
|
||||
sidebar = new Sidebar(renderer, game);
|
||||
|
||||
renderer.BuildPalette(game.map);
|
||||
|
||||
@@ -331,4 +331,8 @@
|
||||
<sequence name="repair" start="35" length="24" />
|
||||
</cursor>
|
||||
|
||||
<unit name="120mm">
|
||||
<sequence name="idle" start="0" length="1" />
|
||||
</unit>
|
||||
|
||||
</sequences>
|
||||
|
||||
Reference in New Issue
Block a user