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

@@ -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;
}
}
}