summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--scenes/Game.tscn4
-rw-r--r--scripts/Game.cs9
-rw-r--r--scripts/map/DungeonGenerator.cs5
-rw-r--r--scripts/map/Map.cs18
-rw-r--r--scripts/map/MapData.cs5
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();
}