forked from s425077/PotatoPlan
165f50b3fd
testin
108 lines
2.4 KiB
C#
108 lines
2.4 KiB
C#
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using Microsoft.Xna.Framework.Input;
|
|
using System;
|
|
|
|
|
|
class Tractor
|
|
{
|
|
private Vector2 Position;
|
|
private Vector2 TargetPosition;
|
|
private Vector2 Direction;
|
|
private int Spacing, sizeTile;
|
|
private int Speed = 1;
|
|
private Random r = new Random();
|
|
|
|
public void updateSizing(int newSize, int newSpacingSize)
|
|
{
|
|
Spacing = newSpacingSize;
|
|
sizeTile = newSize;
|
|
}
|
|
private void updateDirection(Vector2 Size) /// Runs when the tractor reaches a tile
|
|
{
|
|
Vector2 DeltaPosition = TargetPosition - Position;
|
|
if (DeltaPosition.X == 0)
|
|
{
|
|
if (DeltaPosition.Y == 0)
|
|
{
|
|
Direction = new Vector2(0, 0);
|
|
setTargetPosition(new Vector2(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y)) * (sizeTile + Spacing)); //Sets a random Target
|
|
/// Do Nothing - is currently located on the targetPos
|
|
return;
|
|
}
|
|
else if (DeltaPosition.Y > 0)
|
|
{
|
|
Direction = new Vector2(0, 1);
|
|
return;
|
|
}
|
|
else if (DeltaPosition.Y < 0)
|
|
{
|
|
Direction = new Vector2(0, -1);
|
|
return;
|
|
}
|
|
}
|
|
else if (DeltaPosition.X > 0)
|
|
{
|
|
Direction = new Vector2(1, 0);
|
|
return;
|
|
}
|
|
else if (DeltaPosition.X < 0)
|
|
{
|
|
Direction = new Vector2(-1, 0);
|
|
return;
|
|
}
|
|
|
|
}
|
|
|
|
public void updatePosition(Vector2 Size) /// updates the position
|
|
{
|
|
for (int i = 0; i < Speed; i++)
|
|
{
|
|
updateDirection(Size);
|
|
Position = Position + Direction;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public Vector2 getPos()
|
|
{
|
|
return Position;
|
|
}
|
|
|
|
public void increaseSpeed()
|
|
{
|
|
Speed++;
|
|
}
|
|
|
|
public void decreaseSpeed()
|
|
{
|
|
if (Speed > 0)
|
|
{
|
|
Speed--;
|
|
}
|
|
|
|
}
|
|
|
|
private void setTargetPosition(Vector2 newPosition) /// sets the TargetPosition once it reaches its destination
|
|
{
|
|
TargetPosition = newPosition;
|
|
}
|
|
public void setSpeed(int newSpeed)
|
|
{
|
|
Speed = newSpeed;
|
|
}
|
|
|
|
public int getSpeed()
|
|
{
|
|
return Speed;
|
|
}
|
|
|
|
public Vector2 getTargetPosition()
|
|
{
|
|
return TargetPosition;
|
|
}
|
|
}
|