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

83 lines
2.1 KiB
C#
Raw Permalink Normal View History

2020-05-06 16:22:30 +02:00
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
2020-05-03 13:05:05 +02:00
class SmartTractor
{
2020-05-05 16:27:45 +02:00
private AI ai = new AI();
2020-05-06 16:22:30 +02:00
private Farm farm = new Farm();
private Astar astar = new Astar();
2020-05-03 13:05:05 +02:00
2020-05-06 16:22:30 +02:00
private Vector2 housePos, tractorPos, Size, Target;
2020-05-03 13:05:05 +02:00
2020-05-06 16:22:30 +02:00
private int Score, Rotation, tileSize = 56, Spacing = 1;
2020-05-05 16:27:45 +02:00
2020-05-06 16:22:30 +02:00
//What to do next
public Path returnChoice()
{
ai.update(farm, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target / (tileSize + Spacing), Rotation);
farm = ai.changeCropStatus();
2020-05-05 16:27:45 +02:00
getTargetPosition(ai.newTarget());
2020-05-06 16:22:30 +02:00
astar.update(farm.getCrops(), 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
2020-05-06 16:22:30 +02:00
public void updateMap(Vector2 newTractorPos, Vector2 newHousePos, Vector2 newSize, int newTileSize, int newSpacing, int rotation)
2020-05-03 13:05:05 +02:00
{
housePos = newHousePos;
tractorPos = newTractorPos;
Size = newSize;
tileSize = newTileSize;
Spacing = newSpacing;
Rotation = rotation;
2020-05-03 13:05:05 +02:00
}
2020-05-06 16:22:30 +02:00
public void init()
{
ai.init();
farm.init(new Vector2(100, (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / tileSize) - 125 / tileSize), housePos / (tileSize + Spacing));
}
public void drawInventory(Input input, SpriteBatch spriteBatch, SpriteFont Bold, Cargo itemStorageDefined)
{
ai.drawInventory(input, spriteBatch, Bold, itemStorageDefined);
}
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-06 16:22:30 +02:00
public Farm getFarm()
{
return farm;
}
public void setNewHousePos(Vector2 pos, bool newState)
{
farm.setNewHousePos(pos, newState);
}
public void UpdateCrops(int Speed)
{
for (int i = 0; i < Speed; i++)
{
farm.updateFarm(Size);
}
}
2020-05-06 20:26:33 +02:00
public Inventory getInventory()
{
return ai.getInventory();
}
2020-05-03 13:05:05 +02:00
}