From d6fc2026917d55fa12713e3d00004ec461cc5971 Mon Sep 17 00:00:00 2001 From: Matheus Date: Thu, 30 Oct 2025 17:31:00 -0300 Subject: vĂ¡rios andares MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/Map/Map.cs | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) (limited to 'scripts/Map/Map.cs') 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. /// 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"); tilesNode = GetNode("Tiles"); entitiesNode = GetNode("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").MakeCurrent(); + fieldOfView.ResetFOV(); + UpdateFOV(player.GridPosition); } /// /// Cria um andar da masmorra utilizando o gerador de mapa. /// /// O gerador de mapas precisa do jogador. - 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); } /// @@ -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); + } } -- cgit v1.2.3