diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-10-30 17:31:00 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-10-30 17:31:06 -0300 |
| commit | d6fc2026917d55fa12713e3d00004ec461cc5971 (patch) | |
| tree | 54fc79f9f8a217b2477721e21875e74c1736564e /scripts/Map/Map.cs | |
| parent | e40bc38dcc17ebeb40722bedb94a6459e47b9aeb (diff) | |
vários andares
Diffstat (limited to 'scripts/Map/Map.cs')
| -rw-r--r-- | scripts/Map/Map.cs | 50 |
1 files changed, 47 insertions, 3 deletions
diff --git a/scripts/Map/Map.cs b/scripts/Map/Map.cs index 04ccabd..2913c1f 100644 --- a/scripts/Map/Map.cs +++ b/scripts/Map/Map.cs @@ -2,6 +2,7 @@ using System.Net.Http.Headers; using Godot; using TheLegendOfGustav.Entities; using TheLegendOfGustav.Entities.Actors; +using TheLegendOfGustav.Utils; namespace TheLegendOfGustav.Map; @@ -30,7 +31,11 @@ public partial class Map : Node2D /// Dados do mapa. /// </summary> public MapData MapData { get; private set; } - + + [Signal] + public delegate void DungeonFloorChangedEventHandler(int floor); + + private SignalBus.PlayerDescentEventHandler joinSignal; public override void _Ready() { base._Ready(); @@ -39,20 +44,46 @@ public partial class Map : Node2D fieldOfView = GetNode<FieldOfView>("FieldOfView"); tilesNode = GetNode<Node2D>("Tiles"); entitiesNode = GetNode<Node2D>("Entities"); + + joinSignal = () => NextFloor(); + SignalBus.Instance.PlayerDescent += joinSignal; + } + + void NextFloor() + { + Player player = MapData.Player; + entitiesNode.RemoveChild(player); + + foreach (var entity in entitiesNode.GetChildren()) + { + entity.QueueFree(); + } + + foreach (var tile in tilesNode.GetChildren()) + { + tile.QueueFree(); + } + + Generate(player, MapData.CurrentFloor + 1); + player.GetNode<Camera2D>("Camera2D").MakeCurrent(); + fieldOfView.ResetFOV(); + UpdateFOV(player.GridPosition); } /// <summary> /// Cria um andar da masmorra utilizando o gerador de mapa. /// </summary> /// <param name="player">O gerador de mapas precisa do jogador.</param> - public void Generate(Player player) + public void Generate(Player player, int currentFloor = 1) { - MapData = generator.GenerateDungeon(player); + MapData = generator.GenerateDungeon(player, currentFloor); MapData.EntityPlaced += OnEntityPlaced; PlaceTiles(); PlaceEntities(); + + EmitSignal(SignalName.DungeonFloorChanged, currentFloor); } /// <summary> @@ -111,6 +142,19 @@ public partial class Map : Node2D PlaceEntities(); MapData.EntityPlaced += OnEntityPlaced; + EmitSignal(SignalName.DungeonFloorChanged, MapData.CurrentFloor); return true; } + + public override void _Notification(int what) + { + if (what == NotificationPredelete) + { + if (joinSignal != null) + { + SignalBus.Instance.PlayerDescent -= joinSignal; + } + } + base._Notification(what); + } } |
