moving altitude onto Unit

This commit is contained in:
Chris Forbes
2009-12-17 09:44:22 +13:00
parent 26a797fb2d
commit bd2a2cefbb
3 changed files with 9 additions and 11 deletions

View File

@@ -6,7 +6,6 @@ namespace OpenRa.Game.Traits
{
class Helicopter : ITick, IOrder
{
public int altitude;
public int2 targetLocation;
const int CruiseAltitude = 20;
@@ -54,7 +53,7 @@ namespace OpenRa.Game.Traits
var angle = (unit.Facing - desiredFacing) / 128f * Math.PI;
var scale = .4f + .6f * (float)Math.Cos(angle);
if (altitude > CruiseAltitude / 2) // do some movement.
if (unit.Altitude > CruiseAltitude / 2) // do some movement.
{
self.CenterLocation += (rawSpeed * scale / dist.Length) * dist;
self.CenterLocation += (1f - scale) * rawSpeed
@@ -62,16 +61,16 @@ namespace OpenRa.Game.Traits
self.Location = ((1 / 24f) * self.CenterLocation).ToInt2();
}
if (altitude < CruiseAltitude)
if (unit.Altitude < CruiseAltitude)
{
++altitude;
++unit.Altitude;
return;
}
}
else if (altitude > 0 &&
else if (unit.Altitude > 0 &&
Game.IsCellBuildable( self.Location, UnitMovementType.Foot ))
{
--altitude;
--unit.Altitude;
}
/* todo: bob slightly when hovering */

View File

@@ -31,8 +31,7 @@ namespace OpenRa.Game.Traits
yield return Util.CenteredShadow(self, (secondRotorAnim ?? rotorAnim).Image, self.CenterLocation
+ Util.GetTurretPosition(self, unit, self.Info.SecondaryOffset, 0));
var heli = self.traits.Get<Helicopter>();
var p = self.CenterLocation - new float2( 0, heli.altitude );
var p = self.CenterLocation - new float2( 0, unit.Altitude );
yield return Util.Centered(self, anim.Image, p);
yield return Util.Centered(self, rotorAnim.Image, p
@@ -49,10 +48,9 @@ namespace OpenRa.Game.Traits
if (secondRotorAnim != null)
secondRotorAnim.Tick();
var heli = self.traits.GetOrDefault<Helicopter>();
if (heli == null) return;
var unit = self.traits.Get<Unit>();
var isFlying = heli.altitude > 0;
var isFlying = unit.Altitude > 0;
if (isFlying ^ (rotorAnim.CurrentSequence.Name != "rotor"))
return;

View File

@@ -4,6 +4,7 @@ namespace OpenRa.Game.Traits
class Unit
{
public int Facing;
public int Altitude;
public Unit( Actor self ) { }
}