diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-17 20:18:47 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-17 20:18:47 -0300 |
| commit | bf74afcdd07e59b1a48dbfacdce9d52fad765865 (patch) | |
| tree | 53ac9b8d61f7afa553ddafa0f22e2cf6014e55be | |
| parent | 6fb1eb6a6fe0f3f4c2f4e9d7fc476566168eba5d (diff) | |
Inimigos sólidos.
| -rw-r--r-- | scenes/DungeonLevel.tscn | 5 | ||||
| -rw-r--r-- | scripts/DungeonLevel.cs | 17 | ||||
| -rw-r--r-- | scripts/Utils/Grid.cs | 2 | ||||
| -rw-r--r-- | scripts/actors/actions/MovementAction.cs | 2 |
4 files changed, 20 insertions, 6 deletions
diff --git a/scenes/DungeonLevel.tscn b/scenes/DungeonLevel.tscn index 43e70e2..6810ba7 100644 --- a/scenes/DungeonLevel.tscn +++ b/scenes/DungeonLevel.tscn @@ -5,8 +5,9 @@ [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"] +[node name="Map" type="Node2D" node_paths=PackedStringArray("actors")] script = ExtResource("1_u6mlv") +actors = [NodePath("Actors/Player"), NodePath("Actors/Skeleton")] [node name="Dungeon" type="TileMapLayer" parent="."] texture_filter = 1 @@ -18,5 +19,5 @@ 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")] +[node name="Skeleton" parent="Actors" instance=ExtResource("4_8elbs")] position = Vector2(160, 128) diff --git a/scripts/DungeonLevel.cs b/scripts/DungeonLevel.cs index 6fccc20..d3a5aee 100644 --- a/scripts/DungeonLevel.cs +++ b/scripts/DungeonLevel.cs @@ -5,16 +5,18 @@ public partial class DungeonLevel : Node2D { public Player player; private TileMapLayer buildingLayer; + [Export] + private Godot.Collections.Array<Actor> actors = []; - private Node2D actors; + private Node2D actorsNode; public override void _Ready() { base._Ready(); buildingLayer = GetNode<TileMapLayer>("Dungeon"); - actors = GetNode<Node2D>("Actors"); - player = actors.GetNode<Player>("Player"); + actorsNode = GetNode<Node2D>("Actors"); + player = actorsNode.GetNode<Player>("Player"); } public bool IsTileWalkable(Vector2I pos) { @@ -24,4 +26,13 @@ public partial class DungeonLevel : Node2D return (bool)tile.GetCustomData("isWalkable"); } + + public Actor GetBlockingActorAtPosition(Vector2I pos) { + foreach (Actor actor in actors) { + if (actor.GridPosition == pos && actor.BlocksMovement) { + return actor; + } + } + return null; + } } diff --git a/scripts/Utils/Grid.cs b/scripts/Utils/Grid.cs index bf5d98f..cde01f6 100644 --- a/scripts/Utils/Grid.cs +++ b/scripts/Utils/Grid.cs @@ -1,7 +1,7 @@ using Godot; using System; -public partial class Grid : GodotObject { +public abstract partial class Grid : GodotObject { public static readonly Vector2I tileSize = new(16, 16); public static Vector2I WorldToGrid(Vector2 coord) { diff --git a/scripts/actors/actions/MovementAction.cs b/scripts/actors/actions/MovementAction.cs index 8d864bd..6fa3491 100644 --- a/scripts/actors/actions/MovementAction.cs +++ b/scripts/actors/actions/MovementAction.cs @@ -15,6 +15,8 @@ public partial class MovementAction : Action if (!game.Map.IsTileWalkable(finalDestination)) return; + if (game.Map.GetBlockingActorAtPosition(finalDestination) != null) return; + actor.Walk(Offset); } } |
