Implemented A* pathfinding. Adjusted movement node accordingly.
This commit is contained in:
@@ -14,6 +14,7 @@ public partial class World : Node3D
|
||||
private Dictionary<string, MultiMeshInstance3D> multiMeshes = new();
|
||||
private Dictionary<string, Mesh> meshLibrary = new();
|
||||
Layer layerNode;
|
||||
Pathfinding pathfinding;
|
||||
|
||||
private MultiMeshHandler multiMeshHandler;
|
||||
|
||||
@@ -43,6 +44,8 @@ public partial class World : Node3D
|
||||
map = new Layer[ruinSize];
|
||||
GenerateWorld();
|
||||
|
||||
Pathfinding.BuildAStarGraph();
|
||||
|
||||
HandleRenderData(BuildRenderData(0));
|
||||
}
|
||||
|
||||
@@ -106,9 +109,9 @@ public partial class World : Node3D
|
||||
}
|
||||
else
|
||||
{
|
||||
layerNode.SetupLayer(layerSize, layer, tileMeshes, map[layer-1].gateCoordinate);
|
||||
layerNode.SetupLayer(layerSize, layer, tileMeshes, map[layer - 1].gateCoordinate);
|
||||
}
|
||||
|
||||
|
||||
map[layer] = layerNode;
|
||||
}
|
||||
}
|
||||
@@ -150,31 +153,31 @@ public partial class World : Node3D
|
||||
|
||||
int posX, posY;
|
||||
|
||||
while(currentLight < layerSize * 3)
|
||||
while (currentLight < layerSize * 3)
|
||||
{
|
||||
posX = rand.Next(layerSize);
|
||||
posY = rand.Next(layerSize);
|
||||
//Skip already placed lights and skip junction and gate as they do not contain lights
|
||||
if(layer.tiles[posX, posY].collapsedMesh == "junction" || layer.tiles[posX, posY].collapsedMesh == "gate") continue;
|
||||
if(layer.tiles[posX, posY].containsLight) continue;
|
||||
if (layer.tiles[posX, posY].collapsedMesh == "junction" || layer.tiles[posX, posY].collapsedMesh == "gate") continue;
|
||||
if (layer.tiles[posX, posY].containsLight) continue;
|
||||
layer.tiles[posX, posY].containsLight = true;
|
||||
currentLight++;
|
||||
}
|
||||
|
||||
while(currentDecoration < layerSize)
|
||||
while (currentDecoration < layerSize)
|
||||
{
|
||||
posX = rand.Next(layerSize);
|
||||
posY = rand.Next(layerSize);
|
||||
if(layer.tiles[posX, posY].containsDecoration) continue;
|
||||
if (layer.tiles[posX, posY].containsDecoration) continue;
|
||||
layer.tiles[posX, posY].containsDecoration = true;
|
||||
currentDecoration++;
|
||||
}
|
||||
|
||||
while(currentResource < layerSize)
|
||||
while (currentResource < layerSize)
|
||||
{
|
||||
posX = rand.Next(layerSize);
|
||||
posY = rand.Next(layerSize);
|
||||
if(layer.tiles[posX, posY].containsResource) continue;
|
||||
if (layer.tiles[posX, posY].containsResource) continue;
|
||||
layer.tiles[posX, posY].containsResource = true;
|
||||
currentResource++;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user