summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/definitions/actor/Player.tres9
-rw-r--r--assets/definitions/actor/Skeleton.tres9
-rw-r--r--scenes/DungeonLevel.tscn8
-rw-r--r--scenes/Player.tscn4
-rw-r--r--scenes/Skeleton.tscn11
-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
11 files changed, 77 insertions, 13 deletions
diff --git a/assets/definitions/actor/Player.tres b/assets/definitions/actor/Player.tres
new file mode 100644
index 0000000..4b9b172
--- /dev/null
+++ b/assets/definitions/actor/Player.tres
@@ -0,0 +1,9 @@
+[gd_resource type="Resource" script_class="ActorDefinition" load_steps=2 format=3 uid="uid://cn6xnpwxjudbp"]
+
+[ext_resource type="Script" uid="uid://crxw1e37xlrrt" path="res://scripts/actors/ActorDefinition.cs" id="1_2k33r"]
+
+[resource]
+script = ExtResource("1_2k33r")
+name = "Jogador"
+blocksMovement = true
+metadata/_custom_type_script = "uid://crxw1e37xlrrt"
diff --git a/assets/definitions/actor/Skeleton.tres b/assets/definitions/actor/Skeleton.tres
new file mode 100644
index 0000000..687bcee
--- /dev/null
+++ b/assets/definitions/actor/Skeleton.tres
@@ -0,0 +1,9 @@
+[gd_resource type="Resource" script_class="ActorDefinition" load_steps=2 format=3 uid="uid://bphsl6o2nsb8x"]
+
+[ext_resource type="Script" uid="uid://crxw1e37xlrrt" path="res://scripts/actors/ActorDefinition.cs" id="1_m5x88"]
+
+[resource]
+script = ExtResource("1_m5x88")
+name = "Eis que leto"
+blocksMovement = true
+metadata/_custom_type_script = "uid://crxw1e37xlrrt"
diff --git a/scenes/DungeonLevel.tscn b/scenes/DungeonLevel.tscn
index f9d98fd..43e70e2 100644
--- a/scenes/DungeonLevel.tscn
+++ b/scenes/DungeonLevel.tscn
@@ -1,8 +1,9 @@
-[gd_scene load_steps=4 format=4 uid="uid://dnh8xgk1w76i2"]
+[gd_scene load_steps=5 format=4 uid="uid://dnh8xgk1w76i2"]
[ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_bxfih"]
[ext_resource type="Script" uid="uid://cy7qumrpks2kx" path="res://scripts/DungeonLevel.cs" id="1_u6mlv"]
-[ext_resource type="PackedScene" uid="uid://7sfxgul40ths" path="res://scenes/Player.tscn" id="2_u6mlv"]
+[ext_resource type="PackedScene" uid="uid://c3wbuxeetj24a" path="res://scenes/Player.tscn" id="2_u6mlv"]
+[ext_resource type="PackedScene" uid="uid://cnkx22hgs0b3p" path="res://scenes/Skeleton.tscn" id="4_8elbs"]
[node name="Map" type="Node2D"]
script = ExtResource("1_u6mlv")
@@ -16,3 +17,6 @@ tile_set = ExtResource("1_bxfih")
[node name="Player" parent="Actors" instance=ExtResource("2_u6mlv")]
position = Vector2(144, 144)
+
+[node name="Skeleton" parent="." instance=ExtResource("4_8elbs")]
+position = Vector2(160, 128)
diff --git a/scenes/Player.tscn b/scenes/Player.tscn
index bd40178..d95d726 100644
--- a/scenes/Player.tscn
+++ b/scenes/Player.tscn
@@ -1,12 +1,14 @@
-[gd_scene load_steps=3 format=3 uid="uid://7sfxgul40ths"]
+[gd_scene load_steps=4 format=3 uid="uid://c3wbuxeetj24a"]
[ext_resource type="Script" uid="uid://c840l08453pu2" path="res://scripts/actors/Player.cs" id="1_p0vlq"]
[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/character.png" id="1_v6fml"]
+[ext_resource type="Resource" uid="uid://cn6xnpwxjudbp" path="res://assets/definitions/actor/Player.tres" id="3_3li8b"]
[node name="Player" type="Sprite2D"]
texture = ExtResource("1_v6fml")
centered = false
script = ExtResource("1_p0vlq")
+definition = ExtResource("3_3li8b")
[node name="Camera2D" type="Camera2D" parent="."]
offset = Vector2(8, 8)
diff --git a/scenes/Skeleton.tscn b/scenes/Skeleton.tscn
new file mode 100644
index 0000000..ad78474
--- /dev/null
+++ b/scenes/Skeleton.tscn
@@ -0,0 +1,11 @@
+[gd_scene load_steps=4 format=3 uid="uid://cnkx22hgs0b3p"]
+
+[ext_resource type="Texture2D" uid="uid://dh5sgjdwkps88" path="res://assets/sprites/skeleton.png" id="1_s4oxe"]
+[ext_resource type="Script" uid="uid://bef1fo3vgvxej" path="res://scripts/Enemy.cs" id="2_at7gs"]
+[ext_resource type="Resource" uid="uid://bphsl6o2nsb8x" path="res://assets/definitions/actor/Skeleton.tres" id="3_at7gs"]
+
+[node name="Skeleton" type="Sprite2D"]
+texture = ExtResource("1_s4oxe")
+centered = false
+script = ExtResource("2_at7gs")
+definition = ExtResource("3_at7gs")
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);
}