Locked Doors

This commit is contained in:
Marco 2025-04-24 16:40:51 +02:00
commit e25da0fe16
20 changed files with 318 additions and 61 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using Cirno.Scripts.Components.FSM.Enemy;
using Cirno.Scripts.Enums;
using Cirno.Scripts.Interactables;
using Cirno.Scripts.Resources;
using Cirno.Scripts.Resources.Roguelite;
using Godot;
@ -14,6 +15,8 @@ namespace Cirno.Scripts.Controllers;
public partial class RogueliteRoom : Node2D
{
[Export] public RogueliteRoomResource RoomResource { get; set; }
public RogueliteMapTheme MapTheme { get; set; }
public Vector2I GridPosition { get; set; } // Set by dungeon manager
@ -39,11 +42,6 @@ public partial class RogueliteRoom : Node2D
};
}
[Export] public PackedScene DoorPrefab { get; private set; }
[Export] public PackedScene VerticalDoorPrefab { get; private set; }
[Export] public PackedScene WallPrefab { get; private set; }
private static readonly Godot.Collections.Dictionary<string, Vector2I> DirectionMap = new()
{
{ "North", new Vector2I(0, -1) },
@ -157,14 +155,16 @@ public partial class RogueliteRoom : Node2D
var door = this.CreateChildOf<Door>(marker, marker.Direction switch
{
DoorDirections.North => DoorPrefab,
DoorDirections.South => DoorPrefab,
DoorDirections.East => VerticalDoorPrefab,
DoorDirections.West => VerticalDoorPrefab,
DoorDirections.North => MapTheme.HorizontalDoorPrefab,
DoorDirections.South => MapTheme.HorizontalDoorPrefab,
DoorDirections.East => MapTheme.VerticalDoorPrefab,
DoorDirections.West => MapTheme.VerticalDoorPrefab,
_ => throw new ArgumentOutOfRangeException()
}, marker.GlobalPosition);
door.State = DoorState.Closed;
door.Close();
// door.State = DoorState.Closed;
if (connected)
{
_doors.Add(door);
@ -172,6 +172,21 @@ public partial class RogueliteRoom : Node2D
if (doorEdge == connection.From)
{
connection.FromDoor = door;
// Spawn lock if locked
if (connection.IsLocked)
{
var doorLock = door.CreateChild<RogueliteDoorLock>(MapTheme.DoorLockPrefab);
doorLock.Connection = connection;
doorLock.ZIndex += 2;
//doorLock.Targets.Add(door);
//doorLock.Targets.Add(connection.ToDoor);
doorLock.ActivationType = ActivationType.Open;
}
}
else if (doorEdge == connection.To)
{
@ -184,6 +199,9 @@ public partial class RogueliteRoom : Node2D
}
_connections.Add(connection);
}
else
{
@ -229,8 +247,14 @@ public partial class RogueliteRoom : Node2D
{
foreach (var connection in _connections)
{
connection.FromDoor?.Open();
connection.ToDoor?.Open();
if(!connection.IsLocked)
{
connection.FromDoor?.Open();
}
if(!connection.IsLocked)
{
connection.ToDoor?.Open();
}
}
}
@ -238,8 +262,14 @@ public partial class RogueliteRoom : Node2D
{
foreach (var connection in _connections)
{
connection.FromDoor?.Close();
connection.ToDoor?.Close();
if(!connection.IsLocked)
{
connection.FromDoor?.Close();
}
if(!connection.IsLocked)
{
connection.ToDoor?.Close();
}
}
}