Finished first EA Version #1
@@ -83,11 +83,11 @@ public partial class Layer : Node3D
|
||||
{
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
var node = new Node3D
|
||||
{
|
||||
Position = tile.Position
|
||||
};
|
||||
decorationRoot.AddChild(node);
|
||||
var node = new Node3D
|
||||
{
|
||||
Position = tile.Position
|
||||
};
|
||||
decorationRoot.AddChild(node);
|
||||
|
||||
tile.ContentNode = node;
|
||||
}
|
||||
@@ -116,38 +116,38 @@ public partial class Layer : Node3D
|
||||
|
||||
List<string> possibilities = new();
|
||||
|
||||
if(x == 0 && y == 0)
|
||||
if (x == 0 && y == 0)
|
||||
{
|
||||
possibilities.Add("corner_down_right");
|
||||
}
|
||||
else if(x == 0 && y == layerSize - 1)
|
||||
else if (x == 0 && y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("corner_up_right");
|
||||
}
|
||||
else if(x == layerSize - 1 && y == 0)
|
||||
else if (x == layerSize - 1 && y == 0)
|
||||
{
|
||||
possibilities.Add("corner_down_left");
|
||||
}
|
||||
else if(x == layerSize - 1 && y == layerSize - 1)
|
||||
else if (x == layerSize - 1 && y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("corner_up_left");
|
||||
}
|
||||
else if(y == 0)
|
||||
else if (y == 0)
|
||||
{
|
||||
possibilities.Add("straight_left_right");
|
||||
possibilities.Add("t_down");
|
||||
}
|
||||
else if(y == layerSize - 1)
|
||||
else if (y == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("straight_left_right");
|
||||
possibilities.Add("t_up");
|
||||
}
|
||||
else if(x == 0)
|
||||
else if (x == 0)
|
||||
{
|
||||
possibilities.Add("straight_up_down");
|
||||
possibilities.Add("t_right");
|
||||
}
|
||||
else if(x == layerSize - 1)
|
||||
else if (x == layerSize - 1)
|
||||
{
|
||||
possibilities.Add("straight_up_down");
|
||||
possibilities.Add("t_left");
|
||||
@@ -165,6 +165,24 @@ public partial class Layer : Node3D
|
||||
return true;
|
||||
}
|
||||
|
||||
private void GenerateNecessaryTiles()
|
||||
{
|
||||
int posX, posY;
|
||||
while (true)
|
||||
{
|
||||
posX = rand.Next(layerSize);
|
||||
posY = rand.Next(layerSize);
|
||||
|
||||
if (tiles[posX, posY].collapsedMesh != null) continue;
|
||||
if (tiles[posX, posY].tileMeshes.ContainsKey("gate"))
|
||||
{
|
||||
tiles[posX, posY].Collapse("gate");
|
||||
NewPropagate(new Vector2I(posX, posY));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool GenerateLayer()
|
||||
{
|
||||
bool result = true;
|
||||
@@ -174,10 +192,11 @@ public partial class Layer : Node3D
|
||||
return false;
|
||||
}
|
||||
|
||||
GenerateNecessaryTiles();
|
||||
Vector2I position = GetSmallestPossibilities();
|
||||
while (true)
|
||||
{
|
||||
string keyword = tiles[position.X, position.Y].Collapse("");
|
||||
string keyword = tiles[position.X, position.Y].Collapse("");
|
||||
if (keyword == "ERR") return false;
|
||||
if (keyword != "")
|
||||
{
|
||||
|
||||
@@ -9,11 +9,13 @@ public class WFC
|
||||
public static Random rand = new Random();
|
||||
public enum Direction
|
||||
{
|
||||
Up,
|
||||
Down,
|
||||
Backward,
|
||||
Forward,
|
||||
Left,
|
||||
Right,
|
||||
None
|
||||
None,
|
||||
Up,
|
||||
Down
|
||||
}
|
||||
|
||||
public static readonly Vector2I[] offsets =
|
||||
@@ -26,34 +28,34 @@ public class WFC
|
||||
|
||||
public static readonly Direction[] dirs =
|
||||
{
|
||||
Direction.Up,
|
||||
Direction.Down,
|
||||
Direction.Backward,
|
||||
Direction.Forward,
|
||||
Direction.Left,
|
||||
Direction.Right
|
||||
};
|
||||
|
||||
public static Dictionary<string, HashSet<Direction>> tileConnections = new Dictionary<string, HashSet<Direction>>
|
||||
{
|
||||
["t_right"] = new() { Direction.Up, Direction.Down, Direction.Right },
|
||||
["t_left"] = new() { Direction.Up, Direction.Down, Direction.Left },
|
||||
["t_up"] = new() { Direction.Left, Direction.Right, Direction.Up },
|
||||
["t_down"] = new() { Direction.Left, Direction.Right, Direction.Down },
|
||||
["t_right"] = new() { Direction.Backward, Direction.Forward, Direction.Right , Direction.Up},
|
||||
["t_left"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Up },
|
||||
["t_up"] = new() { Direction.Left, Direction.Right, Direction.Backward, Direction.Up },
|
||||
["t_down"] = new() { Direction.Left, Direction.Right, Direction.Forward, Direction.Up },
|
||||
|
||||
["end_up"] = new() { Direction.Up },
|
||||
["end_down"] = new() { Direction.Down },
|
||||
["end_left"] = new() { Direction.Left },
|
||||
["end_right"] = new() { Direction.Right },
|
||||
["end_up"] = new() { Direction.Backward, Direction.Up },
|
||||
["end_down"] = new() { Direction.Forward, Direction.Up },
|
||||
["end_left"] = new() { Direction.Left, Direction.Up },
|
||||
["end_right"] = new() { Direction.Right, Direction.Up },
|
||||
|
||||
["straight_left_right"] = new() { Direction.Left, Direction.Right },
|
||||
["straight_up_down"] = new() { Direction.Up, Direction.Down },
|
||||
["straight_left_right"] = new() { Direction.Left, Direction.Right, Direction.Up },
|
||||
["straight_up_down"] = new() { Direction.Backward, Direction.Forward, Direction.Up },
|
||||
|
||||
["corner_up_left"] = new() { Direction.Up, Direction.Left },
|
||||
["corner_up_right"] = new() { Direction.Up, Direction.Right },
|
||||
["corner_down_left"] = new() { Direction.Down, Direction.Left },
|
||||
["corner_down_right"] = new() { Direction.Down, Direction.Right },
|
||||
["corner_up_left"] = new() { Direction.Backward, Direction.Left, Direction.Up },
|
||||
["corner_up_right"] = new() { Direction.Backward, Direction.Right, Direction.Up },
|
||||
["corner_down_left"] = new() { Direction.Forward, Direction.Left, Direction.Up },
|
||||
["corner_down_right"] = new() { Direction.Forward, Direction.Right, Direction.Up },
|
||||
|
||||
["junction"] = new() { Direction.Up, Direction.Down, Direction.Left, Direction.Right },
|
||||
["gate"] = new() { Direction.Up, Direction.Down, Direction.Left, Direction.Right }
|
||||
["junction"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up},
|
||||
["gate"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up, Direction.Down}
|
||||
};
|
||||
|
||||
public static Dictionary<string, float> weights = new()
|
||||
@@ -77,17 +79,19 @@ public class WFC
|
||||
["end_left"] = 0.2f,
|
||||
["end_right"] = 0.3f,
|
||||
|
||||
["gate"] = 0.1f
|
||||
["gate"] = 0.0f
|
||||
};
|
||||
|
||||
public static Direction Opposite(Direction dir)
|
||||
{
|
||||
return dir switch
|
||||
{
|
||||
Direction.Up => Direction.Down,
|
||||
Direction.Down => Direction.Up,
|
||||
Direction.Backward => Direction.Forward,
|
||||
Direction.Forward => Direction.Backward,
|
||||
Direction.Left => Direction.Right,
|
||||
Direction.Right => Direction.Left,
|
||||
Direction.Up => Direction.Down,
|
||||
Direction.Down => Direction.Up,
|
||||
_ => dir
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user