Compare commits
2 Commits
4b460926c5
...
5e4e325ec7
| Author | SHA1 | Date | |
|---|---|---|---|
| 5e4e325ec7 | |||
| 83d9620e39 |
+14
-6
@@ -185,8 +185,8 @@ size_flags_horizontal = 3
|
|||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
theme_override_constants/separation = 10
|
theme_override_constants/separation = 10
|
||||||
|
|
||||||
[node name="Popup" type="PanelContainer" parent="CanvasLayer/Control" unique_id=311359170]
|
[node name="Popup" type="Control" parent="CanvasLayer" unique_id=1989677138]
|
||||||
layout_mode = 1
|
layout_mode = 3
|
||||||
anchors_preset = 8
|
anchors_preset = 8
|
||||||
anchor_left = 0.5
|
anchor_left = 0.5
|
||||||
anchor_top = 0.5
|
anchor_top = 0.5
|
||||||
@@ -199,22 +199,30 @@ offset_bottom = 20.0
|
|||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="RobotNaming" type="VBoxContainer" parent="CanvasLayer/Control/Popup" unique_id=39200128]
|
[node name="RobotNaming" type="PanelContainer" parent="CanvasLayer/Popup" unique_id=311359170]
|
||||||
visible = false
|
visible = false
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/Popup/RobotNaming" unique_id=39200128]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/Control/Popup/RobotNaming" unique_id=1964282829]
|
[node name="RichTextLabel" type="RichTextLabel" parent="CanvasLayer/Popup/RobotNaming/VBoxContainer" unique_id=1964282829]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Name your robot:"
|
text = "Name your robot:"
|
||||||
fit_content = true
|
fit_content = true
|
||||||
autowrap_mode = 0
|
autowrap_mode = 0
|
||||||
|
|
||||||
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/Control/Popup/RobotNaming" unique_id=1713423672]
|
[node name="LineEdit" type="LineEdit" parent="CanvasLayer/Popup/RobotNaming/VBoxContainer" unique_id=1713423672]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
placeholder_text = "Name..."
|
placeholder_text = "Name..."
|
||||||
max_length = 24
|
max_length = 24
|
||||||
|
|
||||||
[node name="Button" type="Button" parent="CanvasLayer/Control/Popup/RobotNaming" unique_id=279251707]
|
[node name="Button" type="Button" parent="CanvasLayer/Popup/RobotNaming/VBoxContainer" unique_id=279251707]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Submit"
|
text = "Submit"
|
||||||
|
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ public partial class UIHandler : Control
|
|||||||
|
|
||||||
public void ShowNamingPopup(Robot robot)
|
public void ShowNamingPopup(Robot robot)
|
||||||
{
|
{
|
||||||
VBoxContainer namingContainer = GetNode<VBoxContainer>("./Popup/RobotNaming");
|
PanelContainer namingContainer = GetNode<PanelContainer>("../Popup/RobotNaming");
|
||||||
namingContainer.Visible = true;
|
namingContainer.Visible = true;
|
||||||
GameData.canMove = false;
|
GameData.canMove = false;
|
||||||
LineEdit name = namingContainer.GetNode<LineEdit>("./LineEdit");
|
LineEdit name = namingContainer.GetNode<LineEdit>("./VBoxContainer/LineEdit");
|
||||||
Button button = namingContainer.GetNode<Button>("./Button");
|
Button button = namingContainer.GetNode<Button>("./VBoxContainer/Button");
|
||||||
|
|
||||||
Action handler = null;
|
Action handler = null;
|
||||||
handler = () =>
|
handler = () =>
|
||||||
|
|||||||
@@ -83,11 +83,11 @@ public partial class Layer : Node3D
|
|||||||
{
|
{
|
||||||
foreach (var tile in tiles)
|
foreach (var tile in tiles)
|
||||||
{
|
{
|
||||||
var node = new Node3D
|
var node = new Node3D
|
||||||
{
|
{
|
||||||
Position = tile.Position
|
Position = tile.Position
|
||||||
};
|
};
|
||||||
decorationRoot.AddChild(node);
|
decorationRoot.AddChild(node);
|
||||||
|
|
||||||
tile.ContentNode = node;
|
tile.ContentNode = node;
|
||||||
}
|
}
|
||||||
@@ -116,45 +116,45 @@ public partial class Layer : Node3D
|
|||||||
|
|
||||||
List<string> possibilities = new();
|
List<string> possibilities = new();
|
||||||
|
|
||||||
if(x == 0 && y == 0)
|
if (x == 0 && y == 0)
|
||||||
{
|
{
|
||||||
possibilities.Add("corner_down_right");
|
possibilities.Add("corner_down_right");
|
||||||
}
|
}
|
||||||
else if(x == 0 && y == layerSize - 1)
|
else if (x == 0 && y == layerSize - 1)
|
||||||
{
|
{
|
||||||
possibilities.Add("corner_up_right");
|
possibilities.Add("corner_up_right");
|
||||||
}
|
}
|
||||||
else if(x == layerSize - 1 && y == 0)
|
else if (x == layerSize - 1 && y == 0)
|
||||||
{
|
{
|
||||||
possibilities.Add("corner_down_left");
|
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");
|
possibilities.Add("corner_up_left");
|
||||||
}
|
}
|
||||||
else if(y == 0)
|
else if (y == 0)
|
||||||
{
|
{
|
||||||
possibilities.Add("straight_left_right");
|
possibilities.Add("straight_left_right");
|
||||||
possibilities.Add("t_down");
|
possibilities.Add("t_down");
|
||||||
}
|
}
|
||||||
else if(y == layerSize - 1)
|
else if (y == layerSize - 1)
|
||||||
{
|
{
|
||||||
possibilities.Add("straight_left_right");
|
possibilities.Add("straight_left_right");
|
||||||
possibilities.Add("t_up");
|
possibilities.Add("t_up");
|
||||||
}
|
}
|
||||||
else if(x == 0)
|
else if (x == 0)
|
||||||
{
|
{
|
||||||
possibilities.Add("straight_up_down");
|
possibilities.Add("straight_up_down");
|
||||||
possibilities.Add("t_right");
|
possibilities.Add("t_right");
|
||||||
}
|
}
|
||||||
else if(x == layerSize - 1)
|
else if (x == layerSize - 1)
|
||||||
{
|
{
|
||||||
possibilities.Add("straight_up_down");
|
possibilities.Add("straight_up_down");
|
||||||
possibilities.Add("t_left");
|
possibilities.Add("t_left");
|
||||||
}
|
}
|
||||||
|
|
||||||
string result = tile.Collapse(possibilities[rand.Next(0, possibilities.Count)]);
|
string result = tile.Collapse(possibilities[rand.Next(0, possibilities.Count)]);
|
||||||
|
|
||||||
if (result == "ERR")
|
if (result == "ERR")
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -165,6 +165,24 @@ public partial class Layer : Node3D
|
|||||||
return true;
|
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()
|
public bool GenerateLayer()
|
||||||
{
|
{
|
||||||
bool result = true;
|
bool result = true;
|
||||||
@@ -174,10 +192,11 @@ public partial class Layer : Node3D
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GenerateNecessaryTiles();
|
||||||
Vector2I position = GetSmallestPossibilities();
|
Vector2I position = GetSmallestPossibilities();
|
||||||
while (true)
|
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 == "ERR") return false;
|
||||||
if (keyword != "")
|
if (keyword != "")
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ public class WFC
|
|||||||
public static Random rand = new Random();
|
public static Random rand = new Random();
|
||||||
public enum Direction
|
public enum Direction
|
||||||
{
|
{
|
||||||
Up,
|
Backward,
|
||||||
Down,
|
Forward,
|
||||||
Left,
|
Left,
|
||||||
Right,
|
Right,
|
||||||
None
|
None,
|
||||||
|
Up,
|
||||||
|
Down
|
||||||
}
|
}
|
||||||
|
|
||||||
public static readonly Vector2I[] offsets =
|
public static readonly Vector2I[] offsets =
|
||||||
@@ -26,34 +28,34 @@ public class WFC
|
|||||||
|
|
||||||
public static readonly Direction[] dirs =
|
public static readonly Direction[] dirs =
|
||||||
{
|
{
|
||||||
Direction.Up,
|
Direction.Backward,
|
||||||
Direction.Down,
|
Direction.Forward,
|
||||||
Direction.Left,
|
Direction.Left,
|
||||||
Direction.Right
|
Direction.Right
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Dictionary<string, HashSet<Direction>> tileConnections = new Dictionary<string, HashSet<Direction>>
|
public static Dictionary<string, HashSet<Direction>> tileConnections = new Dictionary<string, HashSet<Direction>>
|
||||||
{
|
{
|
||||||
["t_right"] = new() { Direction.Up, Direction.Down, Direction.Right },
|
["t_right"] = new() { Direction.Backward, Direction.Forward, Direction.Right , Direction.Up},
|
||||||
["t_left"] = new() { Direction.Up, Direction.Down, Direction.Left },
|
["t_left"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Up },
|
||||||
["t_up"] = new() { Direction.Left, Direction.Right, Direction.Up },
|
["t_up"] = new() { Direction.Left, Direction.Right, Direction.Backward, Direction.Up },
|
||||||
["t_down"] = new() { Direction.Left, Direction.Right, Direction.Down },
|
["t_down"] = new() { Direction.Left, Direction.Right, Direction.Forward, Direction.Up },
|
||||||
|
|
||||||
["end_up"] = new() { Direction.Up },
|
["end_up"] = new() { Direction.Backward, Direction.Up },
|
||||||
["end_down"] = new() { Direction.Down },
|
["end_down"] = new() { Direction.Forward, Direction.Up },
|
||||||
["end_left"] = new() { Direction.Left },
|
["end_left"] = new() { Direction.Left, Direction.Up },
|
||||||
["end_right"] = new() { Direction.Right },
|
["end_right"] = new() { Direction.Right, Direction.Up },
|
||||||
|
|
||||||
["straight_left_right"] = new() { Direction.Left, Direction.Right },
|
["straight_left_right"] = new() { Direction.Left, Direction.Right, Direction.Up },
|
||||||
["straight_up_down"] = new() { Direction.Up, Direction.Down },
|
["straight_up_down"] = new() { Direction.Backward, Direction.Forward, Direction.Up },
|
||||||
|
|
||||||
["corner_up_left"] = new() { Direction.Up, Direction.Left },
|
["corner_up_left"] = new() { Direction.Backward, Direction.Left, Direction.Up },
|
||||||
["corner_up_right"] = new() { Direction.Up, Direction.Right },
|
["corner_up_right"] = new() { Direction.Backward, Direction.Right, Direction.Up },
|
||||||
["corner_down_left"] = new() { Direction.Down, Direction.Left },
|
["corner_down_left"] = new() { Direction.Forward, Direction.Left, Direction.Up },
|
||||||
["corner_down_right"] = new() { Direction.Down, Direction.Right },
|
["corner_down_right"] = new() { Direction.Forward, Direction.Right, Direction.Up },
|
||||||
|
|
||||||
["junction"] = new() { Direction.Up, Direction.Down, Direction.Left, Direction.Right },
|
["junction"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up},
|
||||||
["gate"] = new() { Direction.Up, Direction.Down, Direction.Left, Direction.Right }
|
["gate"] = new() { Direction.Backward, Direction.Forward, Direction.Left, Direction.Right, Direction.Up, Direction.Down}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Dictionary<string, float> weights = new()
|
public static Dictionary<string, float> weights = new()
|
||||||
@@ -77,17 +79,19 @@ public class WFC
|
|||||||
["end_left"] = 0.2f,
|
["end_left"] = 0.2f,
|
||||||
["end_right"] = 0.3f,
|
["end_right"] = 0.3f,
|
||||||
|
|
||||||
["gate"] = 0.1f
|
["gate"] = 0.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
public static Direction Opposite(Direction dir)
|
public static Direction Opposite(Direction dir)
|
||||||
{
|
{
|
||||||
return dir switch
|
return dir switch
|
||||||
{
|
{
|
||||||
Direction.Up => Direction.Down,
|
Direction.Backward => Direction.Forward,
|
||||||
Direction.Down => Direction.Up,
|
Direction.Forward => Direction.Backward,
|
||||||
Direction.Left => Direction.Right,
|
Direction.Left => Direction.Right,
|
||||||
Direction.Right => Direction.Left,
|
Direction.Right => Direction.Left,
|
||||||
|
Direction.Up => Direction.Down,
|
||||||
|
Direction.Down => Direction.Up,
|
||||||
_ => dir
|
_ => dir
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ public partial class World : Node3D
|
|||||||
if (Input.IsActionJustPressed("spawn_robot") && robots.Count < maxRobotCount)
|
if (Input.IsActionJustPressed("spawn_robot") && robots.Count < maxRobotCount)
|
||||||
{
|
{
|
||||||
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
|
Robot robot = ResourceLoader.LoadRobotPrefab().Instantiate<Robot>();
|
||||||
|
robot.Name = $"Robot #{robots.Count + 1}";
|
||||||
robot.Position = map[0].tiles[rand.Next(layerSize), rand.Next(layerSize)].Position;
|
robot.Position = map[0].tiles[rand.Next(layerSize), rand.Next(layerSize)].Position;
|
||||||
AddChild(robot);
|
AddChild(robot);
|
||||||
robots.Add(robot);
|
robots.Add(robot);
|
||||||
|
|||||||
Reference in New Issue
Block a user