public virtual void Tick()
{
//ensure that the object is in the page.
//this is in case the window was resized
if (Location.X > Limits.Right)
{
Location = new Point(Limits.Right - 1, Location.Y);
}
if (Location.Y > Limits.Bottom)
{
Location = new Point(Location.X, Limits.Bottom - 1);
}
//Generate a new location adding in the vectors
//check the limits and switch vector directions as needed
var newX = Location.X + Vector.Width;
if (newX > Limits.Right || newX < Limits.Left)
{
Vector = new Size(-1 * Vector.Width, Vector.Height);
}
var newY = Location.Y + Vector.Height;
if (newY > Limits.Bottom || newY < Limits.Top)
{
Vector = new Size(Vector.Width, -1 * Vector.Height);
}
//This is the new position
Location = new Point(Location.X + Vector.Width, Location.Y + Vector.Height);
//Apply the rotation factor
Rotation += RotationDelta;
//Limit just to be neat
Rotation = (Rotation < 360f ? (Rotation >= 0 ? Rotation : Rotation + 360f) : Rotation - 360f);
}