Added new Tileset (Better walls and floors) and reworked layer generation. Working on placeholders next again (Need to fix rotation)
This commit is contained in:
+52
-7
@@ -6,8 +6,9 @@ using static GameData;
|
||||
|
||||
public partial class World : Node3D
|
||||
{
|
||||
Random rand = new Random();
|
||||
public Dictionary<string, MeshInstance3D> tileMeshes;
|
||||
public Dictionary<string, MeshInstance3D> decorationMeshes;
|
||||
public Dictionary<string, MeshInstance3D> contentMeshes;
|
||||
public Dictionary<string, List<Placeholder>> tilePlaceholders;
|
||||
PackedScene layerPrefab = ResourceLoader.LoadLayerPrefab();
|
||||
private Dictionary<string, MultiMeshInstance3D> multiMeshes = new();
|
||||
@@ -22,7 +23,7 @@ public partial class World : Node3D
|
||||
WFC.FillAdjacencies();
|
||||
|
||||
tileMeshes = ResourceLoader.LoadTiles();
|
||||
decorationMeshes = ResourceLoader.LoadDecorations();
|
||||
contentMeshes = ResourceLoader.LoadDecorations();
|
||||
|
||||
tilePlaceholders = new Dictionary<string, List<Placeholder>>();
|
||||
|
||||
@@ -31,7 +32,7 @@ public partial class World : Node3D
|
||||
tilePlaceholders[kvp.Key] = new List<Placeholder>();
|
||||
foreach (MeshInstance3D child in kvp.Value.GetChildren())
|
||||
{
|
||||
tilePlaceholders[kvp.Key].Add(new Placeholder(child.Name, child.Transform.Origin));
|
||||
tilePlaceholders[kvp.Key].Add(new Placeholder(child.Name, child.Transform));
|
||||
}
|
||||
meshLibrary[kvp.Key] = kvp.Value.Mesh;
|
||||
kvp.Value.QueueFree();
|
||||
@@ -39,7 +40,7 @@ public partial class World : Node3D
|
||||
|
||||
multiMeshes = CreateMultiMeshes(meshLibrary);
|
||||
multiMeshHandler = new MultiMeshHandler(multiMeshes);
|
||||
|
||||
|
||||
map = new Layer[ruinSize];
|
||||
GenerateWorld();
|
||||
|
||||
@@ -86,8 +87,8 @@ public partial class World : Node3D
|
||||
if (Input.IsActionJustPressed("spawn_robot"))
|
||||
{
|
||||
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
|
||||
robot.Position = map[0].tiles[1,1].Position;
|
||||
robot.Position -= new Vector3(0,1.5f,0);
|
||||
robot.Position = map[0].tiles[1, 1].Position;
|
||||
robot.Position -= new Vector3(0, 1.5f, 0);
|
||||
AddChild(robot);
|
||||
}
|
||||
}
|
||||
@@ -124,12 +125,56 @@ public partial class World : Node3D
|
||||
}
|
||||
}
|
||||
|
||||
if (!layer.hasContentGenerated)
|
||||
{
|
||||
DistributeTileContent(layer);
|
||||
layer.hasContentGenerated = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private void DistributeTileContent(Layer layer)
|
||||
{
|
||||
int currentDecoration = 0;
|
||||
int currentLight = 0;
|
||||
int currentResource = 0;
|
||||
|
||||
int posX, posY;
|
||||
|
||||
while(currentLight < layerSize * 2)
|
||||
{
|
||||
posX = rand.Next(layerSize);
|
||||
posY = rand.Next(layerSize);
|
||||
if(layer.tiles[posX, posY].containsLight) continue;
|
||||
layer.tiles[posX, posY].containsLight = true;
|
||||
currentLight++;
|
||||
}
|
||||
|
||||
while(currentDecoration < layerSize)
|
||||
{
|
||||
posX = rand.Next(layerSize);
|
||||
posY = rand.Next(layerSize);
|
||||
if(layer.tiles[posX, posY].containsDecoration) continue;
|
||||
layer.tiles[posX, posY].containsDecoration = true;
|
||||
currentDecoration++;
|
||||
}
|
||||
|
||||
while(currentResource < layerSize)
|
||||
{
|
||||
posX = rand.Next(layerSize);
|
||||
posY = rand.Next(layerSize);
|
||||
if(layer.tiles[posX, posY].containsResource) continue;
|
||||
layer.tiles[posX, posY].containsResource = true;
|
||||
currentResource++;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleRenderData(List<TileRenderData> renderData)
|
||||
{
|
||||
multiMeshHandler.Build(renderData);
|
||||
DecorationHandler.Spawn(renderData, decorationMeshes);
|
||||
foreach (TileRenderData data in renderData)
|
||||
{
|
||||
data.Tile.SpawnContent(contentMeshes, data.Transform, data.Placeholders);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user