1
0
forked from s425077/PotatoPlan
JoelForkTest/Game1/Sources/Smart/SmartTractor.cs

64 lines
1.4 KiB
C#
Raw Normal View History

2020-05-03 13:05:05 +02:00
using System;
using Microsoft.Xna.Framework;
using System;
class SmartTractor
{
private Crops[,] crops;
private Vector2 housePos;
private Vector2 tractorPos;
private Vector2 Size;
private Vector2 Target;
2020-05-05 16:27:45 +02:00
2020-05-03 13:05:05 +02:00
private int tileSize;
private int Score;
private int Spacing;
private Astar astar = new Astar();
private int Rotation;
2020-05-05 16:27:45 +02:00
private AI ai = new AI();
2020-05-03 13:05:05 +02:00
//What to do next
2020-05-05 16:27:45 +02:00
public Path returnChoice()
2020-05-03 13:05:05 +02:00
{
2020-05-05 16:27:45 +02:00
ai.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
getTargetPosition(ai.newTarget());
astar.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target/(tileSize+Spacing), Rotation);
2020-05-05 16:27:45 +02:00
2020-05-03 17:06:03 +02:00
return astar.FindPath();
2020-05-03 13:05:05 +02:00
}
//Updates the variables every frame
public void updateMap(Vector2 newTractorPos, Vector2 newHousePos, Crops[,] newCropsStatus, Vector2 newSize, int newTileSize, int newSpacing, int newScore, int rotation)
2020-05-03 13:05:05 +02:00
{
crops = newCropsStatus;
housePos = newHousePos;
tractorPos = newTractorPos;
Size = newSize;
tileSize = newTileSize;
Spacing = newSpacing;
Score = newScore;
Rotation = rotation;
2020-05-03 13:05:05 +02:00
}
2020-05-05 16:27:45 +02:00
private void getTargetPosition(Vector2 newTarget)
2020-05-03 13:05:05 +02:00
{
2020-05-05 16:27:45 +02:00
Target = newTarget * (tileSize + Spacing);
2020-05-03 16:35:46 +02:00
}
2020-05-03 13:05:05 +02:00
}