diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-25 17:40:35 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-25 17:40:35 -0300 |
| commit | 7419e7237c3c5b3f1184babfcd826b7f788b599a (patch) | |
| tree | 62b37af72c4325e2342e9ab976c6cc1c30e45ed2 | |
| parent | 35660f002898cd2382567696890d3fbc4d21e763 (diff) | |
Organização.
| -rw-r--r-- | scenes/Game.tscn | 4 | ||||
| -rw-r--r-- | scripts/Game.cs | 9 | ||||
| -rw-r--r-- | scripts/map/DungeonGenerator.cs | 5 | ||||
| -rw-r--r-- | scripts/map/Map.cs | 18 | ||||
| -rw-r--r-- | scripts/map/MapData.cs | 5 |
5 files changed, 28 insertions, 13 deletions
diff --git a/scenes/Game.tscn b/scenes/Game.tscn index 58690de..983b2a8 100644 --- a/scenes/Game.tscn +++ b/scenes/Game.tscn @@ -24,7 +24,9 @@ iterations = 8 [node name="FieldOfView" type="Node" parent="Map"] script = ExtResource("5_s0nni") -[node name="Actors" type="Node2D" parent="."] +[node name="Tiles" type="Node2D" parent="Map"] + +[node name="Actors" type="Node2D" parent="Map"] [node name="Camera2D" type="Camera2D" parent="."] offset = Vector2(8, 8) diff --git a/scripts/Game.cs b/scripts/Game.cs index 29a0666..511b305 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -4,8 +4,6 @@ using System; public partial class Game : Node { private static readonly ActorDefinition playerDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Player.tres"); private static readonly ActorDefinition skeletonDefinition = GD.Load<ActorDefinition>("res://assets/definitions/actor/Skeleton.tres"); - private Player player; - private Node2D actorsNode; private Map Map; private InputHandler inputHandler; @@ -15,16 +13,13 @@ public partial class Game : Node { Map = GetNode<Map>("Map"); inputHandler = GetNode<InputHandler>("InputHandler"); - actorsNode = GetNode<Node2D>("Actors"); - player = new Player(Vector2I.Zero, null, playerDefinition); + Player player = new Player(Vector2I.Zero, null, playerDefinition); Camera2D camera = GetNode<Camera2D>("Camera2D"); RemoveChild(camera); player.AddChild(camera); - actorsNode.AddChild(player); - Map.Generate(player); Map.UpdateFOV(player.GridPosition); @@ -33,6 +28,8 @@ public partial class Game : Node { public override void _PhysicsProcess(double delta) { base._PhysicsProcess(delta); + Player player = Map.Map_Data.Player; + Action action = inputHandler.GetAction(player); if (action != null) { diff --git a/scripts/map/DungeonGenerator.cs b/scripts/map/DungeonGenerator.cs index 0d94724..68bde06 100644 --- a/scripts/map/DungeonGenerator.cs +++ b/scripts/map/DungeonGenerator.cs @@ -50,7 +50,10 @@ public partial class DungeonGenerator : Node public MapData GenerateDungeon(Player player) { - MapData data = new MapData(width, height); + MapData data = new MapData(width, height, player); + + data.InsertActor(player); + player.Map_Data = data; MapDivision root = new MapDivision(0, 0, width, height); diff --git a/scripts/map/Map.cs b/scripts/map/Map.cs index 41bd7f8..52ff588 100644 --- a/scripts/map/Map.cs +++ b/scripts/map/Map.cs @@ -8,21 +8,32 @@ public partial class Map : Node2D [Export] private int fovRadius = 12; - DungeonGenerator generator; + private DungeonGenerator generator; FieldOfView fieldOfView; + private Node2D tilesNode; + private Node2D actorsNode; + public override void _Ready() { base._Ready(); generator = GetNode<DungeonGenerator>("Generator"); fieldOfView = GetNode<FieldOfView>("FieldOfView"); + tilesNode = GetNode<Node2D>("Tiles"); + actorsNode = GetNode<Node2D>("Actors"); } private void PlaceTiles() { foreach (Tile tile in Map_Data.Tiles) { - AddChild(tile); + tilesNode.AddChild(tile); + } + } + + private void PlaceActors() { + foreach (Actor actor in Map_Data.Actors) { + actorsNode.AddChild(actor); } } @@ -30,11 +41,10 @@ public partial class Map : Node2D { Map_Data = generator.GenerateDungeon(player); - Map_Data.InsertActor(player); - player.Map_Data = Map_Data; PlaceTiles(); + PlaceActors(); } public void UpdateFOV(Vector2I pos) { diff --git a/scripts/map/MapData.cs b/scripts/map/MapData.cs index 1aba35d..ea18b4b 100644 --- a/scripts/map/MapData.cs +++ b/scripts/map/MapData.cs @@ -12,12 +12,15 @@ public partial class MapData : RefCounted public Godot.Collections.Array<Tile> Tiles { get; private set; } = []; + public Player Player { get; set; } public Godot.Collections.Array<Actor> Actors { get; private set; } = []; - public MapData(int width, int height) { + public MapData(int width, int height, Player player) { Width = width; Height = height; + Player = player; + SetupTiles(); } |
