From c9057bbd88f14a4e0e572c16452c1ab9baebfe2a Mon Sep 17 00:00:00 2001 From: Matheus Date: Sun, 17 Aug 2025 22:30:35 -0300 Subject: Atores agora são criados por código. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/DungeonLevel.cs | 9 +++++---- scripts/Enemy.cs | 4 +++- scripts/Game.cs | 11 +++++++++-- scripts/actors/Actor.cs | 11 +++++++++-- scripts/actors/ActorDefinition.cs | 2 ++ scripts/actors/Player.cs | 4 +++- 6 files changed, 31 insertions(+), 10 deletions(-) (limited to 'scripts') diff --git a/scripts/DungeonLevel.cs b/scripts/DungeonLevel.cs index cdafdca..68751c5 100644 --- a/scripts/DungeonLevel.cs +++ b/scripts/DungeonLevel.cs @@ -3,12 +3,9 @@ using System; public partial class DungeonLevel : Node2D { - public Player player; private TileMapLayer buildingLayer; - [Export] public Godot.Collections.Array Actors { get; private set; } = []; - private Node2D actorsNode; public override void _Ready() @@ -17,7 +14,11 @@ public partial class DungeonLevel : Node2D buildingLayer = GetNode("Dungeon"); actorsNode = GetNode("Actors"); - player = actorsNode.GetNode("Player"); + } + + public void InsertActor(Actor actor) { + Actors.Add(actor); + actorsNode.AddChild(actor); } public bool IsTileWalkable(Vector2I pos) { diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs index 29a85b7..921cd86 100644 --- a/scripts/Enemy.cs +++ b/scripts/Enemy.cs @@ -3,5 +3,7 @@ using System; public partial class Enemy : Actor { - + public Enemy(Vector2I initialPosition, DungeonLevel map, ActorDefinition definition) : base(initialPosition, map, definition) + { + } } diff --git a/scripts/Game.cs b/scripts/Game.cs index 067f4a4..f5c5240 100644 --- a/scripts/Game.cs +++ b/scripts/Game.cs @@ -2,6 +2,7 @@ using Godot; using System; public partial class Game : Node { + private static readonly ActorDefinition playerDefinition = GD.Load("res://assets/definitions/actor/Player.tres"); private Player player; public DungeonLevel Map { get; private set; } private InputHandler inputHandler; @@ -12,8 +13,14 @@ public partial class Game : Node { Map = GetNode("Map"); inputHandler = GetNode("InputHandler"); - - player = Map.player; + + player = new Player(new Vector2I(0, 0), Map, playerDefinition); + Camera2D camera = GetNode("Camera2D"); + RemoveChild(camera); + + player.AddChild(camera); + + Map.InsertActor(player); } public override void _PhysicsProcess(double delta) { diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs index f429ead..7e9ab04 100644 --- a/scripts/actors/Actor.cs +++ b/scripts/actors/Actor.cs @@ -3,11 +3,18 @@ using Godot; [GlobalClass] public abstract partial class Actor : Sprite2D { - [Export] private ActorDefinition definition; private Vector2I gridPosition = Vector2I.Zero; - [Export] public DungeonLevel Map { get; private set; } + + public Actor(Vector2I initialPosition, DungeonLevel map, ActorDefinition definition) { + GridPosition = initialPosition; + Map = map; + this.definition = definition; + Texture = definition.texture; + Centered = false; + } + public Vector2I GridPosition { set { gridPosition = value; diff --git a/scripts/actors/ActorDefinition.cs b/scripts/actors/ActorDefinition.cs index 58a749c..5678921 100644 --- a/scripts/actors/ActorDefinition.cs +++ b/scripts/actors/ActorDefinition.cs @@ -7,6 +7,8 @@ public partial class ActorDefinition : Resource [ExportCategory("Visuals")] [Export] public string name = "unnamed"; + [Export] + public Texture2D texture; [ExportCategory("Mechanics")] [Export] diff --git a/scripts/actors/Player.cs b/scripts/actors/Player.cs index c8abe12..590020d 100644 --- a/scripts/actors/Player.cs +++ b/scripts/actors/Player.cs @@ -4,5 +4,7 @@ using System; [GlobalClass] public partial class Player : Actor { - + public Player(Vector2I initialPosition, DungeonLevel map, ActorDefinition definition) : base(initialPosition, map, definition) + { + } } -- cgit v1.2.3