1
0
forked from s425077/PotatoPlan

damnbroken

This commit is contained in:
BOTLester 2020-05-03 19:30:41 +02:00
parent 8db46409f1
commit 54205f0d7f
6 changed files with 26 additions and 13 deletions

View File

@ -34,7 +34,7 @@ namespace Game1
//Generates the map with some random values
input.init(graphics, new Vector2(16,16), 56, 1); //Generates the starting size
input.init(graphics, new Vector2(8,8), 56, 1); //Generates the starting size
houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position
tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor
tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the first Size of the Tractor
@ -106,10 +106,10 @@ namespace Game1
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getPath().getByIndex(i).getCords().X * (input.getSpacingTile()) + input.getTileSize() / 4, (int)tractorUnit.getPath().getByIndex(i).getCords().Y * (input.getSpacingTile()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.Green);
}
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getPath().getFinalDest().getCords().X * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), (int)tractorUnit.getPath().getFinalDest().getCords().Y * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), Convert.ToInt32(input.getTileSize()/1.5), Convert.ToInt32(input.getTileSize()/1.5)) , Color.Red); //Draws the current target of the tractor
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getPos().X, (int)tractorUnit.getPos().Y, input.getTileSize(), input.getTileSize()), Color.White);
spriteBatch.Draw(house, houseUnit.GetRectangle(), Color.White);
spriteBatch.DrawString(Bold, "Speed:" + tractorUnit.getSpeed().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20) , Color.White); //Draws the speed value
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getPath().getFinalDest().getCords().X * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), (int)tractorUnit.getPath().getFinalDest().getCords().Y * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), Convert.ToInt32(input.getTileSize() / 1.5), Convert.ToInt32(input.getTileSize() / 1.5)), Color.Red); //Draws the current target of the tractor
spriteBatch.DrawString(Bold, "Tractor Speed:" + tractorUnit.getTractorSpeed().ToString(), new Vector2(100, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20), Color.White);
spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 40), Color.White); //Draws the tile size
spriteBatch.DrawString(Bold, "Matrix Size: " + input.getSize().X.ToString() + " X " + input.getSize().Y.ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 60), Color.White);

View File

@ -37,15 +37,15 @@ class Crops
}
else if (Status == 2)
{
return 2;
return 20;
}
else if (Status == 3)
{
return 3;
return 30;
}
else
{
return 4;
return 40;
}
}

View File

@ -25,6 +25,10 @@ class Farm
{
x = r.Next(0, 2);
}
if (x == 2)
{
x = r.Next(1, 3);
}
crops[i, j] = new Crops();
crops[i, j].Status = x;
}

View File

@ -47,7 +47,7 @@ class Astar
adjacentNodes.Remove(adjacentNodes[i]);
else
{
if (adjacentNodes[i].getCords().X > Size.X || adjacentNodes[i].getCords().Y > Size.Y)
if (adjacentNodes[i].getCords().X > Size.X - 1 || adjacentNodes[i].getCords().Y > Size.Y - 1)
adjacentNodes.Remove(adjacentNodes[i]);
}
}
@ -77,21 +77,24 @@ class Astar
while (openList.Count > 0)
{
current = openList.Peek();
//g = current.getG();
closedList.Enqueue(current);
openList.Dequeue();
if (closedList.Peek().getCords() == target.getCords())
break;
if (closedList.Exists(target.getCords()))
break;
var adjacentNodes = GetAdjacentNodes(current.getCords());
g++;
//g++;
foreach(var adjacentNode in adjacentNodes)
{
g = g + crops[(int)adjacentNode.getCords().X, (int)adjacentNode.getCords().Y].getCostOnMovement();
if (closedList.Exists(adjacentNode.getCords()))
continue;
if (!(openList.Exists(adjacentNode.getCords())))
{
adjacentNode.setG(g);
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
adjacentNode.calculateF();
@ -115,7 +118,9 @@ class Astar
path.AddNode(current);
current = current.getParent();
}
path.FlipArray();
path = path.FlipArray();
openList.Clear();
closedList.Clear();
return path;
}

View File

@ -31,15 +31,19 @@ class Path
return temp;
}
public void FlipArray()
public Path FlipArray()
{
int j = Count;
Nodes[] tempp = nodes;
Nodes[] newnode = new Nodes[Count];
Path newPath = new Path();
for (int i = 0; i < Count; i++)
{
nodes[i] = tempp[j - 1];
newnode[i] = tempp[j - 1];
j--;
newPath.AddNode(newnode[i]);
}
return newPath;
}
public Nodes getFinalDest()

View File

@ -41,7 +41,7 @@ class PriorityQueue
{
Nodes min = Peek();
Nodes root = list[Count - 1];
list.RemoveAt(0);
list.RemoveAt(Count - 1);
int i = 0;