mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-10 17:15:53 +00:00
room positioning and door generator
This commit is contained in:
parent
59f98ebf0e
commit
5bfffc22ad
19 changed files with 571 additions and 17 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Resources.Roguelite;
|
||||
using Godot;
|
||||
|
|
@ -9,11 +10,74 @@ namespace Cirno.Scripts.Controllers;
|
|||
public partial class RogueliteRoom : Node2D
|
||||
{
|
||||
[Export] public RogueliteRoomResource RoomResource { get; set; }
|
||||
|
||||
public Vector2I GridPosition { get; set; } // Set by dungeon manager
|
||||
|
||||
[Export] public PackedScene DoorPrefab { get; private set; }
|
||||
|
||||
private static readonly Dictionary<string, Vector2I> DirectionMap = new()
|
||||
{
|
||||
{ "North", new Vector2I(0, -1) },
|
||||
{ "South", new Vector2I(0, 1) },
|
||||
{ "East", new Vector2I(1, 0) },
|
||||
{ "West", new Vector2I(-1, 0) },
|
||||
};
|
||||
|
||||
private Array<EnemyResource> SpawnableEnemies => RoomResource.SpawnableEnemies;
|
||||
|
||||
public void Spawn()
|
||||
public RogueliteRoom Spawn(Func<Vector2I, bool> connectionChecker)
|
||||
{
|
||||
SpawnEnemies();
|
||||
HandleDoors(connectionChecker);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void HandleDoors(Func<Vector2I, bool> connectionChecker)
|
||||
{
|
||||
if (!HasNode("Doors")) return;
|
||||
var doorsNode = GetNode("Doors");
|
||||
|
||||
foreach (Node child in doorsNode.GetChildren())
|
||||
{
|
||||
if (child is not DoorMarker marker) continue;
|
||||
|
||||
var baseDir = marker.GetWorldDirection();
|
||||
|
||||
// WallIndex determines the offset *along* the edge of the room
|
||||
Vector2I offset = marker.Direction switch
|
||||
{
|
||||
RoomDirection.North or RoomDirection.South => new Vector2I(marker.WallIndex, 0),
|
||||
RoomDirection.East or RoomDirection.West => new Vector2I(0, marker.WallIndex),
|
||||
_ => Vector2I.Zero
|
||||
};
|
||||
|
||||
// Combine GridPosition + offset to locate where this door aligns
|
||||
Vector2I doorEdge = GridPosition + offset;
|
||||
Vector2I neighborPos = doorEdge + baseDir;
|
||||
|
||||
bool connected = connectionChecker.Invoke(neighborPos);
|
||||
|
||||
if (!connected) continue;
|
||||
|
||||
var door = this.CreateChild<Door>(DoorPrefab, marker.GlobalPosition);
|
||||
|
||||
door.State = DoorState.Open;
|
||||
|
||||
// PackedScene prefab = hasConnection
|
||||
// ? GD.Load<PackedScene>("res://Prefabs/Door.tscn")
|
||||
// : GD.Load<PackedScene>("res://Prefabs/Wall.tscn");
|
||||
//
|
||||
// var instance = prefab.Instantiate<Node2D>();
|
||||
// AddChild(instance);
|
||||
// instance.GlobalPosition = ((Node2D)child).GlobalPosition;
|
||||
// instance.Rotation = ((Node2D)child).GlobalRotation;
|
||||
}
|
||||
}
|
||||
|
||||
private void SpawnEnemies()
|
||||
{
|
||||
if (SpawnableEnemies is null || !SpawnableEnemies.Any()) return;
|
||||
|
||||
var enemySpawners = this.GetNode("EnemySpawners").GetChildren().Cast<Marker2D>();
|
||||
|
||||
foreach (var spawner in enemySpawners)
|
||||
|
|
@ -26,6 +90,5 @@ public partial class RogueliteRoom : Node2D
|
|||
var enemyScene = GD.Load<PackedScene>(e.PrefabPath);
|
||||
var spawnedEnemy = spawner.CreateChild<Node2D>(enemyScene);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue