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:
+49
-17
@@ -5,12 +5,14 @@ using System.Linq;
|
||||
using static WFC;
|
||||
public partial class Layer : Node3D
|
||||
{
|
||||
Random rand = new Random();
|
||||
private Node3D decorationRoot;
|
||||
public Tile[,] tiles;
|
||||
int layerSize;
|
||||
Tile tile;
|
||||
int level;
|
||||
bool updateFailed = false;
|
||||
public bool hasContentGenerated = false;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
@@ -31,7 +33,7 @@ public partial class Layer : Node3D
|
||||
{
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
foreach (Node child in tile.DecorationNode.GetChildren())
|
||||
foreach (Node child in tile.ContentNode.GetChildren())
|
||||
{
|
||||
child.QueueFree();
|
||||
}
|
||||
@@ -63,10 +65,10 @@ public partial class Layer : Node3D
|
||||
float offsetZ;
|
||||
for (int x = 0; x < layerSize; x++)
|
||||
{
|
||||
offsetX = x * 4;
|
||||
offsetX = x * 6;
|
||||
for (int y = 0; y < layerSize; y++)
|
||||
{
|
||||
offsetZ = y * 4;
|
||||
offsetZ = y * 6;
|
||||
position = new Vector3(offsetX, offsetY, offsetZ);
|
||||
tile = new Tile();
|
||||
tile.SetMeshes(tileMeshes);
|
||||
@@ -87,7 +89,7 @@ public partial class Layer : Node3D
|
||||
};
|
||||
decorationRoot.AddChild(node);
|
||||
|
||||
tile.DecorationNode = node;
|
||||
tile.ContentNode = node;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +114,47 @@ public partial class Layer : Node3D
|
||||
{
|
||||
var tile = tiles[x, y];
|
||||
|
||||
string result = tile.Collapse("border");
|
||||
List<string> possibilities = new();
|
||||
|
||||
if(x == 0 && y == 0)
|
||||
{
|
||||
possibilities.Add("corner_down_right");
|
||||
}
|
||||
else if(x == 0 && y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("corner_up_right");
|
||||
}
|
||||
else if(x == layerSize - 1 && y == 0)
|
||||
{
|
||||
possibilities.Add("corner_down_left");
|
||||
}
|
||||
else if(x == layerSize - 1 && y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("corner_up_left");
|
||||
}
|
||||
else if(y == 0)
|
||||
{
|
||||
possibilities.Add("straight_left_right");
|
||||
possibilities.Add("t_down");
|
||||
}
|
||||
else if(y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("straight_left_right");
|
||||
possibilities.Add("t_up");
|
||||
}
|
||||
else if(x == 0)
|
||||
{
|
||||
possibilities.Add("straight_up_down");
|
||||
possibilities.Add("t_right");
|
||||
}
|
||||
else if(x == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("straight_up_down");
|
||||
possibilities.Add("t_left");
|
||||
}
|
||||
|
||||
string result = tile.Collapse(possibilities[rand.Next(0, possibilities.Count)]);
|
||||
|
||||
if (result == "ERR")
|
||||
return false;
|
||||
|
||||
@@ -135,15 +177,7 @@ public partial class Layer : Node3D
|
||||
Vector2I position = GetSmallestPossibilities();
|
||||
while (true)
|
||||
{
|
||||
string keyword;
|
||||
if (position.X == 0 || position.X == layerSize - 1 || position.Y == 0 || position.Y == layerSize - 1)
|
||||
{
|
||||
keyword = tiles[position.X, position.Y].Collapse("border");
|
||||
}
|
||||
else
|
||||
{
|
||||
keyword = tiles[position.X, position.Y].Collapse("");
|
||||
}
|
||||
string keyword = tiles[position.X, position.Y].Collapse("");
|
||||
if (keyword == "ERR") return false;
|
||||
if (keyword != "")
|
||||
{
|
||||
@@ -160,8 +194,6 @@ public partial class Layer : Node3D
|
||||
if (safetyCounter == layerSize * layerSize) return false;
|
||||
}
|
||||
if (updateFailed) return false;
|
||||
//Spawn is a tile border, redo world generation
|
||||
if (tiles[1, 1].collapsedMesh == "border") return false;
|
||||
//Player has over 80% of tiles available without destroying walls => Results in about 95% success rate
|
||||
//Not necessarily needed but improves the overall generation percentage at a low resource cost
|
||||
if (!WFC.IsMapConnected(tiles, 0.8f)) return false;
|
||||
@@ -186,7 +218,7 @@ public partial class Layer : Node3D
|
||||
for (int i = 0; i < dirs.Length; i++)
|
||||
{
|
||||
Vector2I newPos = currentPos + offsets[i];
|
||||
if (!InBounds(newPos, layerSize, true)) continue;
|
||||
if (!InBounds(newPos, layerSize)) continue;
|
||||
|
||||
Tile neighborTile = tiles[newPos.X, newPos.Y];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user