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:
@@ -13,5 +13,6 @@ namespace OpenRa.Game
|
|||||||
public float2 location;
|
public float2 location;
|
||||||
public int palette;
|
public int palette;
|
||||||
public abstract Sprite[] CurrentImages { get; }
|
public abstract Sprite[] CurrentImages { get; }
|
||||||
|
public abstract void Tick( double t );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace OpenRa.Game
|
|||||||
class Mcv : Actor
|
class Mcv : Actor
|
||||||
{
|
{
|
||||||
static Range<int>? mcvRange = null;
|
static Range<int>? mcvRange = null;
|
||||||
|
MoveOrder currentOrder = null;
|
||||||
|
int facing = 0;
|
||||||
|
|
||||||
public Mcv( float2 location, int palette )
|
public Mcv( float2 location, int palette )
|
||||||
{
|
{
|
||||||
@@ -20,20 +22,82 @@ namespace OpenRa.Game
|
|||||||
mcvRange = UnitSheetBuilder.AddUnit("mcv");
|
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
|
public override Sprite[] CurrentImages
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return new Sprite[] { UnitSheetBuilder.sprites[GetFacing() + mcvRange.Value.Start] };
|
return new Sprite[] { UnitSheetBuilder.sprites[facing + mcvRange.Value.Start] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Accept(MoveOrder o)
|
public void Accept(MoveOrder o)
|
||||||
{
|
{
|
||||||
// HACK HACK HACK TELEPORT
|
currentOrder = o;
|
||||||
this.location = o.Destination;
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public MoveOrder(float2 destination)
|
public MoveOrder(float2 destination)
|
||||||
{
|
{
|
||||||
this.Destination = destination;
|
this.Destination = destination - new float2(24,24); //HACK account for MCV size
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,5 +29,7 @@ namespace OpenRa.Game
|
|||||||
return new Sprite[] { UnitSheetBuilder.sprites[refineryRange.Value.Start + GetFrame()] };
|
return new Sprite[] { UnitSheetBuilder.sprites[refineryRange.Value.Start + GetFrame()] };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Tick(double t) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,7 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
get { return currentImages; }
|
get { return currentImages; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Tick(double t){}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,14 +25,22 @@ namespace OpenRa.Game
|
|||||||
|
|
||||||
public void Add(Actor a) { actors.Add(a); }
|
public void Add(Actor a) { actors.Add(a); }
|
||||||
|
|
||||||
|
double lastTime = Environment.TickCount / 1000.0;
|
||||||
|
|
||||||
void Draw()
|
void Draw()
|
||||||
{
|
{
|
||||||
|
double t = Environment.TickCount / 1000.0;
|
||||||
|
double dt = t - lastTime;
|
||||||
|
lastTime = t;
|
||||||
|
|
||||||
Range<float2> range = new Range<float2>(viewport.Location, viewport.Location + viewport.Size);
|
Range<float2> range = new Range<float2>(viewport.Location, viewport.Location + viewport.Size);
|
||||||
|
|
||||||
foreach (Actor a in actors)
|
foreach (Actor a in actors)
|
||||||
{
|
{
|
||||||
Sprite[] images = a.CurrentImages;
|
Sprite[] images = a.CurrentImages;
|
||||||
|
|
||||||
|
a.Tick( dt );
|
||||||
|
|
||||||
if (images == null)
|
if (images == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
|||||||
@@ -48,5 +48,28 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
return new float2(a.X / b.X, a.Y / b.Y);
|
return new float2(a.X / b.X, a.Y / b.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool WithinEpsilon(float2 a, float2 b, float e)
|
||||||
|
{
|
||||||
|
float2 d = a - b;
|
||||||
|
return Math.Abs(d.X) < e && Math.Abs(d.Y) < e;
|
||||||
|
}
|
||||||
|
|
||||||
|
static float Sign(float f)
|
||||||
|
{
|
||||||
|
if (f > 0) return 1;
|
||||||
|
if (f < 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float2 Sign()
|
||||||
|
{
|
||||||
|
return new float2(Sign(X), Sign(Y));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float Dot(float2 a, float2 b)
|
||||||
|
{
|
||||||
|
return a.X * b.X + a.Y * b.Y;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user