2020-05-06 16:22:30 +02:00
|
|
|
|
using Microsoft.Xna.Framework;
|
2020-05-10 19:21:52 +02:00
|
|
|
|
using System;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
|
|
|
|
|
class HandleRotation
|
|
|
|
|
{
|
|
|
|
|
int rotationSpeed = 5, Rotation = 180;
|
2020-05-10 19:39:38 +02:00
|
|
|
|
private float oldSpeed, movementSpeed;
|
2020-05-10 21:31:06 +02:00
|
|
|
|
private Vector2 oldTile, oldPosition, oldMovementSpeed;
|
|
|
|
|
private Vector2 Direction;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
|
2020-05-10 21:31:06 +02:00
|
|
|
|
public Vector2 UpdatePosition(int Destination, float tractorSpeed, Vector2 Position, Crops crops, Vector2 oldDeltaPosition, Vector2 Target)
|
2020-05-06 16:22:30 +02:00
|
|
|
|
{
|
2020-05-10 21:31:06 +02:00
|
|
|
|
|
2020-05-10 19:21:52 +02:00
|
|
|
|
if (oldSpeed != crops.getSpeedFactor(tractorSpeed))
|
|
|
|
|
{
|
|
|
|
|
Position = new Vector2((int)Math.Round(Position.X), (int)Math.Round(Position.Y));
|
|
|
|
|
}
|
2020-05-10 21:07:03 +02:00
|
|
|
|
if (Destination == 0) // down
|
2020-05-06 16:22:30 +02:00
|
|
|
|
{
|
|
|
|
|
if (Rotation == 0)
|
|
|
|
|
{
|
2020-05-10 19:39:38 +02:00
|
|
|
|
Direction = new Vector2(0, 1) * movementSpeed;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
Position = Position + Direction;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Rotation > 180)
|
|
|
|
|
{
|
|
|
|
|
if (Rotation >= 360)
|
|
|
|
|
{
|
|
|
|
|
Rotation = 0;
|
|
|
|
|
}
|
|
|
|
|
Rotation = Rotation + rotationSpeed;
|
|
|
|
|
}
|
|
|
|
|
else if (Rotation <= 180 && Rotation > 0)
|
|
|
|
|
{
|
|
|
|
|
Rotation = Rotation - rotationSpeed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-10 21:07:03 +02:00
|
|
|
|
else if (Destination == 1) // up
|
2020-05-06 16:22:30 +02:00
|
|
|
|
{
|
|
|
|
|
if (Rotation == 180)
|
|
|
|
|
{
|
2020-05-10 19:39:38 +02:00
|
|
|
|
Direction = new Vector2(0, -1) * movementSpeed;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
Position = Position + Direction;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (Rotation >= 0 && Rotation < 180)
|
|
|
|
|
{
|
|
|
|
|
Rotation = Rotation + rotationSpeed;
|
|
|
|
|
}
|
|
|
|
|
else if (Rotation < 360 && Rotation > 180)
|
|
|
|
|
{
|
|
|
|
|
Rotation = Rotation - rotationSpeed;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-05-10 21:07:03 +02:00
|
|
|
|
else if (Destination == 2) // right
|
2020-05-06 16:22:30 +02:00
|
|
|
|
{
|
|
|
|
|
if (Rotation == 270)
|
|
|
|
|
{
|
2020-05-10 19:39:38 +02:00
|
|
|
|
Direction = new Vector2(1, 0) * movementSpeed;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-10 21:07:03 +02:00
|
|
|
|
else if (Destination == 3) // left
|
2020-05-06 16:22:30 +02:00
|
|
|
|
{
|
|
|
|
|
if (Rotation == 90)
|
|
|
|
|
{
|
2020-05-10 19:39:38 +02:00
|
|
|
|
Direction = new Vector2(-1, 0) * movementSpeed;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-05-10 19:21:52 +02:00
|
|
|
|
oldSpeed = crops.getSpeedFactor(tractorSpeed);
|
2020-05-10 21:31:06 +02:00
|
|
|
|
if (oldDeltaPosition.X < 1 && oldDeltaPosition.X > -1 && oldDeltaPosition.Y < 1 && oldDeltaPosition.Y > -1)
|
|
|
|
|
{
|
|
|
|
|
Position = Target;
|
|
|
|
|
}
|
|
|
|
|
oldMovementSpeed = Direction;
|
2020-05-06 16:22:30 +02:00
|
|
|
|
return Position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getRotation()
|
|
|
|
|
{
|
|
|
|
|
return Rotation;
|
|
|
|
|
}
|
2020-05-10 19:39:38 +02:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-06 16:22:30 +02:00
|
|
|
|
}
|