131 lines
3.7 KiB
C#
131 lines
3.7 KiB
C#
using Microsoft.Xna.Framework;
|
|
using System;
|
|
|
|
class HandleRotation
|
|
{
|
|
int rotationSpeed = 5, Rotation = 180;
|
|
private float oldSpeed, movementSpeed;
|
|
private Vector2 oldTile;
|
|
|
|
public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops)
|
|
{
|
|
Vector2 Direction;
|
|
if (oldSpeed != crops.getSpeedFactor(tractorSpeed))
|
|
{
|
|
Position = new Vector2((int)Math.Round(Position.X), (int)Math.Round(Position.Y));
|
|
}
|
|
if (Destination == 0)
|
|
{
|
|
if (Rotation == 0)
|
|
{
|
|
Direction = new Vector2(0, 1) * movementSpeed;
|
|
Position = Position + Direction;
|
|
}
|
|
else
|
|
{
|
|
if (Rotation > 180)
|
|
{
|
|
if (Rotation >= 360)
|
|
{
|
|
Rotation = 0;
|
|
}
|
|
Rotation = Rotation + rotationSpeed;
|
|
}
|
|
else if (Rotation <= 180 && Rotation > 0)
|
|
{
|
|
Rotation = Rotation - rotationSpeed;
|
|
}
|
|
}
|
|
}
|
|
else if (Destination == 1)
|
|
{
|
|
if (Rotation == 180)
|
|
{
|
|
Direction = new Vector2(0, -1) * movementSpeed;
|
|
Position = Position + Direction;
|
|
}
|
|
else
|
|
{
|
|
if (Rotation >= 0 && Rotation < 180)
|
|
{
|
|
Rotation = Rotation + rotationSpeed;
|
|
}
|
|
else if (Rotation < 360 && Rotation > 180)
|
|
{
|
|
Rotation = Rotation - rotationSpeed;
|
|
}
|
|
}
|
|
|
|
}
|
|
else if (Destination == 2)
|
|
{
|
|
if (Rotation == 270)
|
|
{
|
|
Direction = new Vector2(1, 0) * movementSpeed;
|
|
Position = Position + Direction;
|
|
}
|
|
else
|
|
{
|
|
if (Rotation > 90 && Rotation < 270)
|
|
{
|
|
Rotation = Rotation + rotationSpeed;
|
|
}
|
|
else if (Rotation < 90 || Rotation < 360)
|
|
{
|
|
if (Rotation <= 0)
|
|
{
|
|
Rotation = 360;
|
|
}
|
|
Rotation = Rotation - rotationSpeed;
|
|
}
|
|
}
|
|
}
|
|
else if (Destination == 3)
|
|
{
|
|
if (Rotation == 90)
|
|
{
|
|
Direction = new Vector2(-1, 0) * movementSpeed;
|
|
Position = Position + Direction;
|
|
}
|
|
else
|
|
{
|
|
if (Rotation < 270 && Rotation > 90)
|
|
{
|
|
Rotation = Rotation - rotationSpeed;
|
|
}
|
|
else if (Rotation >= 0 || Rotation > 270)
|
|
{
|
|
if (Rotation >= 360)
|
|
{
|
|
Rotation = 0;
|
|
}
|
|
Rotation = Rotation + rotationSpeed;
|
|
}
|
|
}
|
|
|
|
}
|
|
oldSpeed = crops.getSpeedFactor(tractorSpeed);
|
|
return Position;
|
|
}
|
|
|
|
public int getRotation()
|
|
{
|
|
return Rotation;
|
|
}
|
|
|
|
public bool checkTile(Vector2 Position, int tileSize, int Spacing, float tractorSpeed, Crops crop)
|
|
{
|
|
Vector2 newTile = new Vector2((float)Math.Round(Position.X / (tileSize + Spacing)), (float)Math.Round(Position.Y / (tileSize + Spacing)));
|
|
if (oldTile != newTile)
|
|
{
|
|
oldTile = newTile;
|
|
movementSpeed = crop.getSpeedFactor(tractorSpeed);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|