HAX IT DOES STUFFS

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1280 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
chrisf
2007-07-15 17:13:35 +00:00
parent b90f1859c2
commit 0a6eaeb26f
7 changed files with 105 additions and 5 deletions

View File

@@ -10,6 +10,8 @@ namespace OpenRa.Game
class Mcv : Actor
{
static Range<int>? mcvRange = null;
MoveOrder currentOrder = null;
int facing = 0;
public Mcv( float2 location, int palette )
{
@@ -20,20 +22,82 @@ namespace OpenRa.Game
mcvRange = UnitSheetBuilder.AddUnit("mcv");
}
int GetFacing() { return (Environment.TickCount >> 6) % 32; }
static float2[] fvecs;
static Mcv()
{
fvecs = new float2[32];
for (int i = 0; i < 32; i++)
{
float angle = i / 16.0f * (float)Math.PI;
fvecs[i] = new float2(-(float)Math.Sin(angle), -(float)Math.Cos(angle));
}
}
int GetFacing(float2 d)
{
if (float2.WithinEpsilon(d, float2.Zero, 0.001f))
return facing;
int highest = -1;
float highestDot = -1.0f;
for (int i = 0; i < 32; i++)
{
float dot = float2.Dot(fvecs[i], d);
if (dot > highestDot)
{
highestDot = dot;
highest = i;
}
}
return highest;
}
public override Sprite[] CurrentImages
{
get
{
return new Sprite[] { UnitSheetBuilder.sprites[GetFacing() + mcvRange.Value.Start] };
return new Sprite[] { UnitSheetBuilder.sprites[facing + mcvRange.Value.Start] };
}
}
public void Accept(MoveOrder o)
{
// HACK HACK HACK TELEPORT
this.location = o.Destination;
currentOrder = o;
}
const float Speed = 48.0f;
public override void Tick( double t )
{
if (currentOrder == null)
return;
if (float2.WithinEpsilon(location, currentOrder.Destination, 1.0f))
return;
Range<float2> r = new Range<float2>(
new float2(-Speed * (float)t, -Speed * (float)t),
new float2(Speed * (float)t, Speed * (float)t));
float2 d = (currentOrder.Destination - location).Constrain(r);
int desiredFacing = GetFacing(d);
if (desiredFacing == facing)
location += d;
else
{
int df = desiredFacing - facing;
if (df < 0)
df = 32 - df;
if (df < 32 - df)
facing = (facing + 1) % 32;
else
facing = (facing + 31) % 32;
}
}
}
}