If so, then I have some suggestions that may speed the game up a bit if they haven't already been implemented in some form;
The following is the code for a class that I usually use when I'm writing 2D games. It can be used to describe an object's location and any vectors that are relevant to it. For example, a Hestia's location, velocity, and acceleration could all be described as vectors. You can find the direction that a vector is pointing in using the UnitVector property.
This class makes it easier to work using similar triangles for geometric stuff rather than slow trigonometric functions, which can greatly speed up your algorithm
Code: Select all
class Vector
{
public float X, Y;
public float magnitude;
public Vector(float x_coordinate, float y_coordinate)
{
X = x_coordinate;
Y = y_coordinate;
updateMagnitude();
}
void updateMagnitude()
{
magnitude = Math.Sqrt(X * X + Y * Y);
}
public static Vector operator +(Vector I, Vector U)
{
return new Vector(I.x + U.x, I.y + U.y);
}
public static Vector operator -(Vector I, Vector U)
{
return new Vector(I.x - U.x, I.y - U.y);
}
public static Vector operator *(Vector I, Vector U)
{
return new Vector(I.x * U.x, I.y * U.y);
}
public static Vector operator *(Vector I, float U)
{
return new Vector(I.x * U, I.y * U);
}
public static Vector operator /(Vector I, float U)
{
return new Vector(I.x / U, I.y / U);
}
public static Vector rotate(Vector point, Vector origin, angle turn)
{
// Rotates "point" around "origin" by "turn", where "turn" is a multiple of 360 degrees.
if (turn == 0)
return point;
else
{
Vector delta = point - origin;
if (turn > 0)
point = new Vector(
delta.x * Math.Cos(turn) - delta.y * Math.Sin(turn),
delta.x * Math.Sin(turn) + delta.y * Math.Cos(turn)
);
else if (turn < 0)
point = new Vector(
delta.x * Math.Cos(turn) + delta.y * Math.Sin(turn),
delta.y * Math.Cos(turn) - delta.x * Math.Sin(turn)
);
updateMagnitude();
return point + delta;
}
}
public Vector toUnitVector
{
return new Vector(X / Math.Max(X, Y), Y / Math.Max(X, Y));
}
}