mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-07-03 03:31:16 +00:00
Door link fix
This commit is contained in:
parent
8c20e6f342
commit
cae1f99949
5 changed files with 86 additions and 33 deletions
|
|
@ -34,6 +34,8 @@ SpawnMarkers = Dictionary[int, NodePath]({
|
||||||
process_mode = 1
|
process_mode = 1
|
||||||
script = ExtResource("4_jtlua")
|
script = ExtResource("4_jtlua")
|
||||||
Rooms = Array[Object]([ExtResource("5_gwtv6"), ExtResource("6_gwtv6"), ExtResource("7_wbqvu"), ExtResource("8_3fyis"), ExtResource("9_go1yg"), ExtResource("5_pfafs"), ExtResource("11_68lig"), ExtResource("12_83bvc"), ExtResource("13_y651a")])
|
Rooms = Array[Object]([ExtResource("5_gwtv6"), ExtResource("6_gwtv6"), ExtResource("7_wbqvu"), ExtResource("8_3fyis"), ExtResource("9_go1yg"), ExtResource("5_pfafs"), ExtResource("11_68lig"), ExtResource("12_83bvc"), ExtResource("13_y651a")])
|
||||||
|
DungeonLength = 12
|
||||||
|
Seed = 1
|
||||||
|
|
||||||
[node name="CameraController" type="Camera2D" parent="."]
|
[node name="CameraController" type="Camera2D" parent="."]
|
||||||
process_mode = 1
|
process_mode = 1
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,26 @@ public partial class RogueliteRoom : Node2D
|
||||||
{
|
{
|
||||||
SpawnEnemies();
|
SpawnEnemies();
|
||||||
//HandleDoors(connectionChecker);
|
//HandleDoors(connectionChecker);
|
||||||
|
AddDebugLabel();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HandleDoors(Func<Vector2I, bool> connectionChecker)
|
private void AddDebugLabel()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < RoomResource.Size.X; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < RoomResource.Size.Y; j++)
|
||||||
|
{
|
||||||
|
var label = new Label();
|
||||||
|
label.Text = $"{GridPosition + new Vector2I(i, j)}";
|
||||||
|
label.ZIndex = 11;
|
||||||
|
label.Position = (new Vector2(i, j) * new Vector2(320, 160)) + new Vector2(160, 80);
|
||||||
|
this.AddChild(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void HandleDoors(Func<Vector2I, Vector2I, RoomConnection> connectionChecker)
|
||||||
{
|
{
|
||||||
if (!HasNode("Doors")) return;
|
if (!HasNode("Doors")) return;
|
||||||
var doorsNode = GetNode("Doors");
|
var doorsNode = GetNode("Doors");
|
||||||
|
|
@ -47,8 +63,10 @@ public partial class RogueliteRoom : Node2D
|
||||||
// WallIndex determines the offset *along* the edge of the room
|
// WallIndex determines the offset *along* the edge of the room
|
||||||
Vector2I offset = marker.Direction switch
|
Vector2I offset = marker.Direction switch
|
||||||
{
|
{
|
||||||
RoomDirection.North or RoomDirection.South => new Vector2I(marker.WallIndex, 0),
|
RoomDirection.North => new Vector2I(marker.WallIndex, 0),
|
||||||
RoomDirection.East or RoomDirection.West => new Vector2I(0, marker.WallIndex),
|
RoomDirection.South => new Vector2I(marker.WallIndex, RoomResource.Size.Y - 1),
|
||||||
|
RoomDirection.East => new Vector2I(RoomResource.Size.X - 1, marker.WallIndex),
|
||||||
|
RoomDirection.West => new Vector2I(0, marker.WallIndex),
|
||||||
_ => Vector2I.Zero
|
_ => Vector2I.Zero
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -56,17 +74,31 @@ public partial class RogueliteRoom : Node2D
|
||||||
Vector2I doorEdge = GridPosition + offset;
|
Vector2I doorEdge = GridPosition + offset;
|
||||||
Vector2I neighborPos = doorEdge + baseDir;
|
Vector2I neighborPos = doorEdge + baseDir;
|
||||||
|
|
||||||
bool connected = connectionChecker.Invoke(neighborPos);
|
var connection = connectionChecker.Invoke(doorEdge, neighborPos);
|
||||||
|
|
||||||
|
var connected = connection is not null;
|
||||||
|
|
||||||
if (connected)
|
if (connected)
|
||||||
{
|
{
|
||||||
var door = this.CreateChild<Door>(DoorPrefab, marker.GlobalPosition);
|
var door = this.CreateChild<Door>(DoorPrefab, marker.GlobalPosition);
|
||||||
|
|
||||||
door.State = DoorState.Open;
|
door.State = DoorState.Closed;
|
||||||
|
|
||||||
|
// 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
// PackedScene prefab = hasConnection
|
// PackedScene prefab = hasConnection
|
||||||
|
|
|
||||||
|
|
@ -126,8 +126,6 @@ public partial class RogueliteRoomManager : Node2D
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
|
|
||||||
_mainPath.Add(nextPos);
|
_mainPath.Add(nextPos);
|
||||||
|
|
||||||
// Place cursor at bottom of room
|
// Place cursor at bottom of room
|
||||||
|
|
@ -174,10 +172,11 @@ public partial class RogueliteRoomManager : Node2D
|
||||||
foreach (var roomEntry in _roomGrid)
|
foreach (var roomEntry in _roomGrid)
|
||||||
{
|
{
|
||||||
var room = roomEntry.Value;
|
var room = roomEntry.Value;
|
||||||
room.HandleDoors(pos =>
|
room.HandleDoors((doorEdge, pos) =>
|
||||||
{
|
{
|
||||||
var neighborPos = room.GridPosition + pos;
|
//var neighborPos = room.GridPosition + pos;
|
||||||
return _roomGrid.ContainsKey(neighborPos);
|
return _connections.FirstOrDefault(x => (x.From == doorEdge && x.To == pos) || (x.From == pos && x.To == doorEdge));
|
||||||
|
//return _roomGrid.ContainsKey(neighborPos);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -414,19 +413,3 @@ public partial class RogueliteRoomManager : Node2D
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RoomConnection
|
|
||||||
{
|
|
||||||
public Vector2I From;
|
|
||||||
public Vector2I To;
|
|
||||||
public bool IsLocked;
|
|
||||||
public bool IsSecret;
|
|
||||||
|
|
||||||
public RoomConnection(Vector2I from, Vector2I to, bool isLocked = false, bool isSecret = false)
|
|
||||||
{
|
|
||||||
From = from;
|
|
||||||
To = to;
|
|
||||||
IsLocked = isLocked;
|
|
||||||
IsSecret = isSecret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
24
Scripts/Controllers/RoomConnection.cs
Normal file
24
Scripts/Controllers/RoomConnection.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
using Godot;
|
||||||
|
|
||||||
|
namespace Cirno.Scripts.Controllers;
|
||||||
|
|
||||||
|
public class RoomConnection
|
||||||
|
{
|
||||||
|
public Vector2I From;
|
||||||
|
public Vector2I To;
|
||||||
|
public bool IsLocked;
|
||||||
|
public bool IsSecret;
|
||||||
|
|
||||||
|
public RoomConnection(Vector2I from, Vector2I to, bool isLocked = false, bool isSecret = false)
|
||||||
|
{
|
||||||
|
From = from;
|
||||||
|
To = to;
|
||||||
|
IsLocked = isLocked;
|
||||||
|
IsSecret = isSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"From {From} to {To}, IsLocked: {IsLocked}, IsSecret: {IsSecret}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -92,7 +92,19 @@ public partial class Minimap : CanvasLayer
|
||||||
RenderingServer.CanvasItemAddRect(_canvasItemRid, new Rect2(drawPos, drawSize), color);
|
RenderingServer.CanvasItemAddRect(_canvasItemRid, new Rect2(drawPos, drawSize), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
DrawRoomConnections( Connections, min, offset);
|
DrawRoomConnections(Connections, min, offset);
|
||||||
|
|
||||||
|
//DrawDebugGrid();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawDebugGrid()
|
||||||
|
{
|
||||||
|
foreach (var room in SpawnedRooms)
|
||||||
|
{
|
||||||
|
var rect = new Rect2(room.GridPosition * RoomManager.TileSize * RoomManager.RoomSizeInTiles, RoomManager.TileSize * RoomManager.RoomSizeInTiles);
|
||||||
|
|
||||||
|
RenderingServer.CanvasItemAddRect(_canvasItemRid, rect, new Color(0, 120,0, 125));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DrawRoomConnections(List<RoomConnection> connections, Vector2I minGrid, Vector2 baseOffset)
|
private void DrawRoomConnections(List<RoomConnection> connections, Vector2I minGrid, Vector2 baseOffset)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue