summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/DungeonLevel.cs10
-rw-r--r--scripts/Game.cs10
-rw-r--r--scripts/actors/Actor.cs10
-rw-r--r--scripts/actors/ActorDefinition.cs14
-rw-r--r--scripts/actors/ActorDefinition.cs.uid1
-rw-r--r--scripts/actors/actions/MovementAction.cs4
6 files changed, 39 insertions, 10 deletions
diff --git a/scripts/DungeonLevel.cs b/scripts/DungeonLevel.cs
index a303254..6fccc20 100644
--- a/scripts/DungeonLevel.cs
+++ b/scripts/DungeonLevel.cs
@@ -4,7 +4,7 @@ using System;
public partial class DungeonLevel : Node2D
{
public Player player;
- public TileMapLayer buildingLayer;
+ private TileMapLayer buildingLayer;
private Node2D actors;
@@ -16,4 +16,12 @@ public partial class DungeonLevel : Node2D
actors = GetNode<Node2D>("Actors");
player = actors.GetNode<Player>("Player");
}
+
+ public bool IsTileWalkable(Vector2I pos) {
+ TileData tile = buildingLayer.GetCellTileData(pos);
+
+ if (tile == null) return false;
+
+ return (bool)tile.GetCustomData("isWalkable");
+ }
}
diff --git a/scripts/Game.cs b/scripts/Game.cs
index 8de7af6..ddea395 100644
--- a/scripts/Game.cs
+++ b/scripts/Game.cs
@@ -3,19 +3,17 @@ using System;
public partial class Game : Node {
private Player player;
- public TileMapLayer Dungeon { get; private set; }
- private DungeonLevel map;
+ public DungeonLevel Map { get; private set; }
private InputHandler inputHandler;
public override void _Ready() {
base._Ready();
- map = GetNode<DungeonLevel>("Map");
+ Map = GetNode<DungeonLevel>("Map");
inputHandler = GetNode<InputHandler>("InputHandler");
- Dungeon = map.buildingLayer;
-
- player = map.player;
+
+ player = Map.player;
}
public override void _PhysicsProcess(double delta) {
diff --git a/scripts/actors/Actor.cs b/scripts/actors/Actor.cs
index 8e33b02..f35939a 100644
--- a/scripts/actors/Actor.cs
+++ b/scripts/actors/Actor.cs
@@ -2,6 +2,8 @@ using Godot;
[GlobalClass]
public abstract partial class Actor : Sprite2D {
+ [Export]
+ private ActorDefinition definition;
private Vector2I gridPosition = Vector2I.Zero;
public Vector2I GridPosition {
set {
@@ -11,6 +13,14 @@ public abstract partial class Actor : Sprite2D {
get => gridPosition;
}
+ public bool BlocksMovement {
+ get => definition.blocksMovement;
+ }
+
+ public string ActorName {
+ get => definition.name;
+ }
+
public override void _Ready()
{
base._Ready();
diff --git a/scripts/actors/ActorDefinition.cs b/scripts/actors/ActorDefinition.cs
new file mode 100644
index 0000000..58a749c
--- /dev/null
+++ b/scripts/actors/ActorDefinition.cs
@@ -0,0 +1,14 @@
+using Godot;
+using System;
+
+[GlobalClass]
+public partial class ActorDefinition : Resource
+{
+ [ExportCategory("Visuals")]
+ [Export]
+ public string name = "unnamed";
+
+ [ExportCategory("Mechanics")]
+ [Export]
+ public bool blocksMovement = true;
+}
diff --git a/scripts/actors/ActorDefinition.cs.uid b/scripts/actors/ActorDefinition.cs.uid
new file mode 100644
index 0000000..ddcfe02
--- /dev/null
+++ b/scripts/actors/ActorDefinition.cs.uid
@@ -0,0 +1 @@
+uid://crxw1e37xlrrt
diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs
index f29e2e8..8d864bd 100644
--- a/scripts/actors/actions/MovementAction.cs
+++ b/scripts/actors/actions/MovementAction.cs
@@ -13,9 +13,7 @@ public partial class MovementAction : Action
{
Vector2I finalDestination = actor.GridPosition + Offset;
- TileData tile = game.Dungeon.GetCellTileData(finalDestination);
-
- if (tile == null || !(bool) tile.GetCustomData("isWalkable")) return;
+ if (!game.Map.IsTileWalkable(finalDestination)) return;
actor.Walk(Offset);
}