multiple turrets; turret offsets

This commit is contained in:
Chris Forbes
2009-10-31 14:46:04 +13:00
parent 816c927aa5
commit 4201f40f6b
8 changed files with 41 additions and 8 deletions

View File

@@ -57,7 +57,7 @@ namespace OpenRa.Game
}
public float2 CenterLocation;
public float2 SelectedSize { get { return Render().LastOrDefault().First.size; } }
public float2 SelectedSize { get { return Render().First().First.size; } }
public IEnumerable<Pair<Sprite, float2>> Render()
{

View File

@@ -19,7 +19,8 @@ namespace OpenRa.Game
anim = new Animation("explosion");
if (style != 0)
anim.PlayThen(style.ToString(), () => Game.world.AddFrameEndTask(w => w.Remove(this)));
anim.PlayThen(style.ToString(),
() => Game.world.AddFrameEndTask(w => w.Remove(this)));
else
Game.world.AddFrameEndTask(w => w.Remove(this));
}

View File

@@ -47,6 +47,8 @@ namespace OpenRa.Game.GameRules
public readonly int TechLevel = -1;
public readonly bool WaterBound = false;
public readonly string[] BuiltAt = { };
public readonly int[] PrimaryOffset = { 0, 0 };
public readonly int[] SecondaryOffset = null;
public UnitInfo(string name) { Name = name; }

View File

@@ -63,6 +63,7 @@ namespace OpenRa.Game
Game.world.Add( new Actor( "mcv", Game.map.Offset + new int2( 9, 5 ), Game.players[ 0 ] ) );
Game.world.Add( new Actor( "jeep", Game.map.Offset + new int2( 9, 15 ), Game.players[ 1 ] ) );
Game.world.Add( new Actor( "3tnk", Game.map.Offset + new int2( 12, 7 ), Game.players[ 1 ] ) );
Game.world.Add(new Actor("ca", Game.map.Offset + new int2(40, 7), Game.players[1]));
sidebar = new Sidebar(renderer, Game.LocalPlayer);

View File

@@ -26,16 +26,17 @@ namespace OpenRa.Game.Traits
protected void DoAttack( Actor self )
{
if( self.unitInfo.Primary != null && CheckFire( self, self.unitInfo.Primary, ref primaryFireDelay ) )
if( self.unitInfo.Primary != null && CheckFire( self, self.unitInfo.Primary, ref primaryFireDelay, self.unitInfo.PrimaryOffset ) )
{
secondaryFireDelay = Math.Max( 4, secondaryFireDelay );
return;
}
if( self.unitInfo.Secondary != null && CheckFire( self, self.unitInfo.Secondary, ref secondaryFireDelay ) )
if( self.unitInfo.Secondary != null && CheckFire( self, self.unitInfo.Secondary, ref secondaryFireDelay,
self.unitInfo.SecondaryOffset ?? self.unitInfo.PrimaryOffset) )
return;
}
bool CheckFire( Actor self, string weaponName, ref int fireDelay )
bool CheckFire( Actor self, string weaponName, ref int fireDelay, int[] offset )
{
if( fireDelay > 0 ) return false;
var weapon = Rules.WeaponInfo[ weaponName ];
@@ -44,7 +45,7 @@ namespace OpenRa.Game.Traits
fireDelay = weapon.ROF;
Game.world.Add( new Bullet( weaponName, self.Owner, self,
self.CenterLocation.ToInt2(),
self.CenterLocation.ToInt2() + Util.GetTurretPosition( self, offset ),
target.CenterLocation.ToInt2() ) );
return true;

View File

@@ -21,8 +21,13 @@ namespace OpenRa.Game.Traits
public override IEnumerable<Pair<Sprite, float2>> Render(Actor self)
{
var mobile = self.traits.Get<Mobile>();
yield return Centered(anim.Image, self.CenterLocation);
yield return Centered(turretAnim.Image, self.CenterLocation);
yield return Centered(turretAnim.Image, self.CenterLocation
+ Util.GetTurretPosition(self, self.unitInfo.PrimaryOffset).ToFloat2());
if (self.unitInfo.SecondaryOffset != null)
yield return Centered(turretAnim.Image, self.CenterLocation
+ Util.GetTurretPosition(self, self.unitInfo.SecondaryOffset).ToFloat2());
}
public override void Tick(Actor self)

View File

@@ -53,5 +53,26 @@ namespace OpenRa.Game.Traits
return facing + turn;
}
public static int2 GetTurretPosition(Actor self, int[] offset)
{
var ru = self.traits.WithInterface<RenderUnit>().FirstOrDefault();
if (ru == null) return int2.Zero; /* things that don't have a rotating base don't need the turrets repositioned */
var bodyFacing = self.traits.Get<Mobile>().facing;
var quantizedFacing = bodyFacing - bodyFacing % ru.anim.CurrentSequence.Length;
var angle = (quantizedFacing / 256f) * (2 * (float)Math.PI);
var sinAngle = Math.Sin(angle);
var cosAngle = Math.Cos(angle);
var pos = new int2(
(int)(cosAngle * offset[0] + sinAngle * offset[1]),
(int)(cosAngle * offset[1] - sinAngle * offset[0]));
pos.Y = (int)(.7f * pos.Y);
return pos;
}
}
}

View File

@@ -78,7 +78,9 @@ Traits=Mobile, RenderUnit
Description=Cruiser
WaterBound=yes
BuiltAt=syrd
Traits=Mobile, RenderUnit
Traits=Mobile, Turreted, RenderUnitTurreted, AttackTurreted
PrimaryOffset=0,17
SecondaryOffset=0,-17
[LST]
Description=Transport
WaterBound=yes