diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/DungeonLevel.cs | 9 | ||||
| -rw-r--r-- | scripts/Enemy.cs | 4 | ||||
| -rw-r--r-- | scripts/Game.cs | 11 | ||||
| -rw-r--r-- | scripts/actors/Actor.cs | 11 | ||||
| -rw-r--r-- | scripts/actors/ActorDefinition.cs | 2 | ||||
| -rw-r--r-- | scripts/actors/Player.cs | 4 |
6 files changed, 31 insertions, 10 deletions
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<Actor> Actors { get; private set; } = []; - private Node2D actorsNode; public override void _Ready() @@ -17,7 +14,11 @@ public partial class DungeonLevel : Node2D buildingLayer = GetNode<TileMapLayer>("Dungeon"); actorsNode = GetNode<Node2D>("Actors"); - player = actorsNode.GetNode<Player>("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<ActorDefinition>("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<DungeonLevel>("Map"); inputHandler = GetNode<InputHandler>("InputHandler"); - - player = Map.player; + + player = new Player(new Vector2I(0, 0), Map, playerDefinition); + Camera2D camera = GetNode<Camera2D>("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) + { + } } |
