Spawn doors on walls

This commit is contained in:
Marco 2025-04-23 14:27:30 +02:00
commit eab572ff2e
2 changed files with 41 additions and 65 deletions

View file

@ -51,7 +51,6 @@ MaxBranchLength = 2
MaxKeys = 2 MaxKeys = 2
MaxSecrets = 1 MaxSecrets = 1
MaxTreasures = 1 MaxTreasures = 1
Seed = 1
[node name="CameraController" type="Camera2D" parent="."] [node name="CameraController" type="Camera2D" parent="."]
process_mode = 1 process_mode = 1

View file

@ -154,19 +154,19 @@ public partial class RogueliteRoom : Node2D
var connected = connection is not null; var connected = connection is not null;
var door = this.CreateChildOf<Door>(marker, marker.Direction switch
{
DoorDirections.North => DoorPrefab,
DoorDirections.South => DoorPrefab,
DoorDirections.East => VerticalDoorPrefab,
DoorDirections.West => VerticalDoorPrefab,
_ => throw new ArgumentOutOfRangeException()
}, marker.GlobalPosition);
door.State = DoorState.Closed;
if (connected) if (connected)
{ {
var door = this.CreateChildOf<Door>(marker, marker.Direction switch
{
DoorDirections.North => DoorPrefab,
DoorDirections.South => DoorPrefab,
DoorDirections.East => VerticalDoorPrefab,
DoorDirections.West => VerticalDoorPrefab,
_ => throw new ArgumentOutOfRangeException()
}, marker.GlobalPosition);
door.State = DoorState.Closed;
_doors.Add(door); _doors.Add(door);
if (doorEdge == connection.From) if (doorEdge == connection.From)
@ -179,41 +179,17 @@ public partial class RogueliteRoom : Node2D
} }
else else
{ {
GD.Print($"Door {door} connection was full: {connection.From} {connection.FromDoor} to {connection.To} {connection.ToDoor}"); GD.Print(
$"Door {door} connection was full: {connection.From} {connection.FromDoor} to {connection.To} {connection.ToDoor}");
} }
// if (connection.FromDoor is null && connection.ToDoor != door)
// {
// connection.FromDoor = door;
// }
// else if (connection.ToDoor is null && connection.FromDoor != door)
// {
// connection.ToDoor = door;
// }
// else
// {
// GD.Print($"Door {door} connection was full: {connection.From} {connection.FromDoor} to {connection.To} {connection.ToDoor}");
// }
_connections.Add(connection); _connections.Add(connection);
// var label = new Label();
// label.Text = $"Door Edge: {doorEdge}, {connection}";
// label.ZIndex = 10;
//
// door.AddChild(label);
} }
else else
{ {
var wall = this.CreateChild<Node2D>(WallPrefab, marker.GlobalPosition); // var wall = this.CreateChild<Node2D>(WallPrefab, marker.GlobalPosition);
// var label = new Label();
// label.Text = $"Door Edge: {doorEdge}, Neighbor: {neighborPos}";
// label.ZIndex = 10;
//
// marker.AddChild(label);
} }
} }
} }
@ -297,8 +273,9 @@ public partial class RogueliteRoom : Node2D
{ {
DoorDirections.North => new Vector2((BaseRoomSize.X / 2) + (BaseRoomSize.X * wallIndex), 32), DoorDirections.North => new Vector2((BaseRoomSize.X / 2) + (BaseRoomSize.X * wallIndex), 32),
DoorDirections.South => new Vector2((BaseRoomSize.X / 2) + (BaseRoomSize.X * wallIndex), DoorDirections.South => new Vector2((BaseRoomSize.X / 2) + (BaseRoomSize.X * wallIndex),
((BaseRoomSize.Y) * RoomResource.Size.Y) +2 ), ((BaseRoomSize.Y) * RoomResource.Size.Y) + 2),
DoorDirections.East => new Vector2((BaseRoomSize.X * RoomResource.Size.X) - 12, (BaseRoomSize.Y / 2) + (BaseRoomSize.Y * wallIndex) - 8), DoorDirections.East => new Vector2((BaseRoomSize.X * RoomResource.Size.X) - 12,
(BaseRoomSize.Y / 2) + (BaseRoomSize.Y * wallIndex) - 8),
DoorDirections.West => new Vector2(12, (BaseRoomSize.Y / 2) + (BaseRoomSize.Y * wallIndex) - 8), DoorDirections.West => new Vector2(12, (BaseRoomSize.Y / 2) + (BaseRoomSize.Y * wallIndex) - 8),
_ => Vector2.Zero _ => Vector2.Zero
}; };
@ -322,9 +299,10 @@ public partial class RogueliteRoom : Node2D
Vector2 doorPosition = doorMarker.Direction switch Vector2 doorPosition = doorMarker.Direction switch
{ {
DoorDirections.North => new Vector2((baseGridSize.X / 2) + (baseGridSize.X * doorMarker.WallIndex), 32), DoorDirections.North => new Vector2((baseGridSize.X / 2) + (baseGridSize.X * doorMarker.WallIndex),
32),
DoorDirections.South => new Vector2((baseGridSize.X / 2) + (baseGridSize.X * doorMarker.WallIndex), DoorDirections.South => new Vector2((baseGridSize.X / 2) + (baseGridSize.X * doorMarker.WallIndex),
((baseGridSize.Y) * RoomResource.Size.Y) +2 ), ((baseGridSize.Y) * RoomResource.Size.Y) + 2),
DoorDirections.East => doorMarker.Position, DoorDirections.East => doorMarker.Position,
DoorDirections.West => doorMarker.Position, DoorDirections.West => doorMarker.Position,
_ => doorMarker.Position _ => doorMarker.Position
@ -337,6 +315,5 @@ public partial class RogueliteRoom : Node2D
GD.Print($"Node was something else: {node}"); GD.Print($"Node was something else: {node}");
} }
} }
} }
} }