multiple turrets; turret offsets
This commit is contained in:
@@ -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()
|
||||
{
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user