From 26972abbe2dd670d2afac067c548cfaf1da73b2d Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 9 Nov 2026 11:46:51 +0100 Subject: boos room --- DungeonSystem/scenes/ZoneEntrance.tscn | 20 ++ DungeonSystem/scenes/roomBase.tscn | 17 +- DungeonSystem/scripts/Door.cs | 90 +++---- DungeonSystem/scripts/DungeonGenerator.cs | 61 ++++- DungeonSystem/scripts/EncounterHud.cs | 77 ++++++ DungeonSystem/scripts/EncounterHud.cs.uid | 1 + DungeonSystem/scripts/Room.cs | 3 +- DungeonSystem/scripts/RoomEncounterConfig.cs | 11 + DungeonSystem/scripts/RoomEncounterConfig.cs.uid | 1 + DungeonSystem/scripts/RoomEncounterManager.cs | 322 ++++++++++++++++++++--- DungeonSystem/scripts/WaveConfig.cs | 11 + DungeonSystem/scripts/WaveConfig.cs.uid | 1 + DungeonSystem/scripts/ZoneEntrance.cs | 49 ++++ DungeonSystem/scripts/ZoneEntrance.cs.uid | 1 + 14 files changed, 573 insertions(+), 92 deletions(-) create mode 100644 DungeonSystem/scenes/ZoneEntrance.tscn create mode 100644 DungeonSystem/scripts/EncounterHud.cs create mode 100644 DungeonSystem/scripts/EncounterHud.cs.uid create mode 100644 DungeonSystem/scripts/RoomEncounterConfig.cs create mode 100644 DungeonSystem/scripts/RoomEncounterConfig.cs.uid create mode 100644 DungeonSystem/scripts/WaveConfig.cs create mode 100644 DungeonSystem/scripts/WaveConfig.cs.uid create mode 100644 DungeonSystem/scripts/ZoneEntrance.cs create mode 100644 DungeonSystem/scripts/ZoneEntrance.cs.uid (limited to 'DungeonSystem') diff --git a/DungeonSystem/scenes/ZoneEntrance.tscn b/DungeonSystem/scenes/ZoneEntrance.tscn new file mode 100644 index 0000000..260e558 --- /dev/null +++ b/DungeonSystem/scenes/ZoneEntrance.tscn @@ -0,0 +1,20 @@ +[gd_scene format=3] + +[ext_resource type="Script" path="res://DungeonSystem/scripts/ZoneEntrance.cs" id="1_script"] +[ext_resource type="Texture2D" path="res://icon.svg" id="2_icon"] + +[sub_resource type="CircleShape2D" id="CircleShape2D_trigger"] +radius = 16.0 + +[node name="ZoneEntrance" type="Node2D"] +script = ExtResource("1_script") + +[node name="Sprite2D" type="Sprite2D" parent="."] +texture = ExtResource("2_icon") +scale = Vector2(0.2, 0.2) + +[node name="Area2D" type="Area2D" parent="."] +collision_mask = 2 + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] +shape = SubResource("CircleShape2D_trigger") diff --git a/DungeonSystem/scenes/roomBase.tscn b/DungeonSystem/scenes/roomBase.tscn index f155572..9d560a5 100644 --- a/DungeonSystem/scenes/roomBase.tscn +++ b/DungeonSystem/scenes/roomBase.tscn @@ -159,7 +159,22 @@ tile_set = SubResource("TileSet_cb62v") position = Vector2(5, -2) navigation_polygon = SubResource("NavigationPolygon_0m7y3") -[node name="EnemySpawners" type="Node" parent="." unique_id=334603267] +[node name="EnemySpawners" type="Node2D" parent="." unique_id=334603267] + +[node name="SpawnA" type="Marker2D" parent="EnemySpawners" unique_id=155180021] +position = Vector2(-24, -24) + +[node name="SpawnB" type="Marker2D" parent="EnemySpawners" unique_id=310446298] +position = Vector2(24, -24) + +[node name="SpawnC" type="Marker2D" parent="EnemySpawners" unique_id=1598592441] +position = Vector2(-24, 24) + +[node name="SpawnD" type="Marker2D" parent="EnemySpawners" unique_id=210595017] +position = Vector2(24, 24) + +[node name="NextZoneEntranceMarker" type="Marker2D" parent="." unique_id=991240117] +position = Vector2(0, 0) [node name="Doors" type="Node2D" parent="." unique_id=34224735] diff --git a/DungeonSystem/scripts/Door.cs b/DungeonSystem/scripts/Door.cs index c30c462..e3ec5d6 100644 --- a/DungeonSystem/scripts/Door.cs +++ b/DungeonSystem/scripts/Door.cs @@ -5,61 +5,61 @@ namespace DungeonSystem; [GlobalClass] public partial class Door : Node2D { - [Signal] - public delegate void PlayerEnteredDoorwayEventHandler(Door door); + [Signal] + public delegate void PlayerEnteredDoorwayEventHandler(Door door); - public enum DoorState { Open, Locked } - public DoorState CurrentState { get; private set; } = DoorState.Open; + public enum DoorState { Open, Locked } + public DoorState CurrentState { get; private set; } = DoorState.Open; - private CollisionShape2D? _barrierCollision; - private Area2D? _triggerArea; - private AnimationPlayer? _animPlayer; + private CollisionShape2D? _barrierCollision; + private Area2D? _triggerArea; + private AnimationPlayer? _animPlayer; - public override void _Ready() - { - _barrierCollision = GetNodeOrNull("Barrier/CollisionShape2D") - ?? GetNodeOrNull("StaticBody2D/CollisionShape2D"); - _triggerArea = GetNodeOrNull("TriggerArea") - ?? GetNodeOrNull("Area2D"); - _animPlayer = GetNodeOrNull("AnimationPlayer"); + public override void _Ready() + { + _barrierCollision = GetNodeOrNull("Barrier/CollisionShape2D") + ?? GetNodeOrNull("StaticBody2D/CollisionShape2D"); + _triggerArea = GetNodeOrNull("TriggerArea") + ?? GetNodeOrNull("Area2D"); + _animPlayer = GetNodeOrNull("AnimationPlayer"); - if (_triggerArea != null) - { - _triggerArea.CollisionMask |= 1u << 1; - _triggerArea.Monitoring = true; - } + if (_triggerArea != null) + { + _triggerArea.CollisionMask |= 1u << 1; + _triggerArea.Monitoring = true; + } - if (_triggerArea != null) - _triggerArea.BodyEntered += OnBodyEntered; + if (_triggerArea != null) + _triggerArea.BodyEntered += OnBodyEntered; - UnlockDoor(); - } + UnlockDoor(); + } - public void LockDoor() - { - if (CurrentState == DoorState.Locked) return; + public void LockDoor() + { + if (CurrentState == DoorState.Locked) return; - CurrentState = DoorState.Locked; - _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, false); + CurrentState = DoorState.Locked; + _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, false); - if (_animPlayer != null && _animPlayer.HasAnimation("lock")) - _animPlayer.Play("lock"); - } + if (_animPlayer != null && _animPlayer.HasAnimation("lock")) + _animPlayer.Play("lock"); + } - public void UnlockDoor() - { - CurrentState = DoorState.Open; - _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, true); + public void UnlockDoor() + { + CurrentState = DoorState.Open; + _barrierCollision?.SetDeferred(CollisionShape2D.PropertyName.Disabled, true); - if (_animPlayer != null && _animPlayer.HasAnimation("unlock")) - _animPlayer.Play("unlock"); - } + if (_animPlayer != null && _animPlayer.HasAnimation("unlock")) + _animPlayer.Play("unlock"); + } - private void OnBodyEntered(Node2D body) - { - if (CurrentState == DoorState.Open && body.IsInGroup("player")) - { - EmitSignal(SignalName.PlayerEnteredDoorway, this); - } - } + private void OnBodyEntered(Node2D body) + { + if (CurrentState == DoorState.Open && body.IsInGroup("player")) + { + EmitSignal(SignalName.PlayerEnteredDoorway, this); + } + } } diff --git a/DungeonSystem/scripts/DungeonGenerator.cs b/DungeonSystem/scripts/DungeonGenerator.cs index 3a44dc4..91a39d3 100644 --- a/DungeonSystem/scripts/DungeonGenerator.cs +++ b/DungeonSystem/scripts/DungeonGenerator.cs @@ -13,6 +13,9 @@ public partial class DungeonGenerator : Node2D [Export] public PackedScene BossRoomScene { get; set; } = null!; [Export] public PackedScene DoorScene { get; set; } = null!; [Export] public PackedScene? EnemyScene { get; set; } = GD.Load("res://enemy.tscn"); + [Export] public PackedScene? BossEnemyScene { get; set; } = GD.Load("res://zones/zone1/boss/bossEnemy.tscn"); + [Export] public PackedScene? NextZoneEntranceScene { get; set; } = GD.Load("res://DungeonSystem/scenes/ZoneEntrance.tscn"); + [Export] public string NextZoneScenePath { get; set; } = "res://zones/zone2/world.tscn"; [Export] public int TargetRoomCount { get; set; } = 10; [Export] public int MaxAttempts { get; set; } = 100; @@ -36,6 +39,8 @@ public partial class DungeonGenerator : Node2D private float _corridorTileSize = 16.0f; private RoomEncounterManager? _encounterManager; + public RoomEncounterManager? EncounterManager => _encounterManager; + private readonly struct CorridorConnection { public readonly Vector2 From; @@ -72,29 +77,71 @@ public partial class DungeonGenerator : Node2D _placedRooms.Add(startRoom); _openDoors.AddRange(startRoom.GetOpenDoors()); - // 2. Main Generation Loop + // 2. Place boss room first so generation always includes one. + bool shouldPlaceBossRoom = BossRoomScene != null && TargetRoomCount > 1; + if (shouldPlaceBossRoom && !_TryPlaceBossRoom()) + { + GD.PrintErr("[DungeonGenerator] Failed to place required boss room. Dungeon generation aborted."); + return; + } + + // 3. Main Generation Loop int attempts = 0; while (_openDoors.Count > 0 && _placedRooms.Count < TargetRoomCount && attempts < MaxAttempts) { attempts++; Marker2D targetDoor = _openDoors[(int)(GD.Randi() % (uint)_openDoors.Count)]; - _TryAttachRoom(targetDoor); + _TryAttachRandomCombatRoom(targetDoor); } _BuildCorridors(); - // 3. Post-Process Doors + // 4. Post-Process Doors SpawnDoorsAndSealUnconnected(); - // 4. Setup encounter manager + // 5. Setup encounter manager _ConfigureEncounterManager(); } - private bool _TryAttachRoom(Marker2D targetDoor) + private bool _TryAttachRandomCombatRoom(Marker2D targetDoor) { if (CombatRoomScenes.Count == 0) return false; PackedScene candidateScene = CombatRoomScenes[(int)(GD.Randi() % (uint)CombatRoomScenes.Count)]; + return _TryAttachRoom(targetDoor, candidateScene, Room.RoomType.Combat); + } + + private bool _TryPlaceBossRoom() + { + if (BossRoomScene == null) + { + return false; + } + + int attempts = 0; + while (_openDoors.Count > 0 && attempts < MaxAttempts) + { + attempts++; + Marker2D targetDoor = _openDoors[(int)(GD.Randi() % (uint)_openDoors.Count)]; + if (_TryAttachRoom(targetDoor, BossRoomScene, Room.RoomType.Boss)) + { + Room placedBossRoom = _placedRooms[_placedRooms.Count - 1]; + if (placedBossRoom.Type != Room.RoomType.Boss) + { + placedBossRoom.Type = Room.RoomType.Boss; + } + + GD.Print($"[DungeonGenerator] Boss room placed: {placedBossRoom.Name}"); + return true; + } + } + + GD.PrintErr("[DungeonGenerator] Failed to place boss room."); + return false; + } + + private bool _TryAttachRoom(Marker2D targetDoor, PackedScene candidateScene, Room.RoomType roomType) + { if (candidateScene.Instantiate() is not Room candidate) return false; AddChild(candidate); @@ -147,6 +194,7 @@ public partial class DungeonGenerator : Node2D } _placedRooms.Add(candidate); + candidate.Type = roomType; targetDoor.SetMeta("connected", true); entryDoor.SetMeta("connected", true); @@ -406,6 +454,9 @@ public partial class DungeonGenerator : Node2D _placedRooms, _roomDoors, EnemyScene, + BossEnemyScene, + NextZoneEntranceScene, + NextZoneScenePath, MinEnemiesPerCombatRoom, MaxEnemiesPerCombatRoom, EnemySpawnPadding, diff --git a/DungeonSystem/scripts/EncounterHud.cs b/DungeonSystem/scripts/EncounterHud.cs new file mode 100644 index 0000000..74a8af0 --- /dev/null +++ b/DungeonSystem/scripts/EncounterHud.cs @@ -0,0 +1,77 @@ +using Godot; + +namespace DungeonSystem; + +public partial class EncounterHud : CanvasLayer +{ + [Export] public NodePath DungeonGeneratorPath { get; set; } = new NodePath("../DungeonGenerator"); + [Export] public NodePath StatusLabelPath { get; set; } = new NodePath("StatusLabel"); + + private Label? _statusLabel; + + public override void _Ready() + { + _statusLabel = GetNodeOrNull