From 579a2fe0f837236eec5d9f9347baa8f6a49f6458 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 16 Aug 2025 00:12:15 -0300 Subject: Personagem que anda --- scenes/character.tscn | 7 +++++++ scenes/test_map.tscn | 21 +++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 scenes/character.tscn create mode 100644 scenes/test_map.tscn (limited to 'scenes') diff --git a/scenes/character.tscn b/scenes/character.tscn new file mode 100644 index 0000000..c99e194 --- /dev/null +++ b/scenes/character.tscn @@ -0,0 +1,7 @@ +[gd_scene load_steps=2 format=3 uid="uid://bl01llfbscv6r"] + +[ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/character.png" id="1_agfs1"] + +[node name="Character" type="Sprite2D"] +texture_filter = 1 +texture = ExtResource("1_agfs1") diff --git a/scenes/test_map.tscn b/scenes/test_map.tscn new file mode 100644 index 0000000..427fd21 --- /dev/null +++ b/scenes/test_map.tscn @@ -0,0 +1,21 @@ +[gd_scene load_steps=4 format=4 uid="uid://u5h6iqyi8wd0"] + +[ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_57l66"] +[ext_resource type="PackedScene" uid="uid://bl01llfbscv6r" path="res://scenes/character.tscn" id="2_fn2sa"] +[ext_resource type="Script" uid="uid://c840l08453pu2" path="res://scripts/Character.cs" id="3_57l66"] + +[node name="Node2D" type="Node2D"] + +[node name="Map" type="TileMapLayer" parent="."] +texture_filter = 1 +tile_map_data = PackedByteArray("AAAHAAcAAAAAAAAAAAAIAAcAAAAAAAAAAAAJAAcAAAAAAAAAAAAKAAcAAAAAAAAAAAALAAcAAAAAAAAAAAAMAAcAAAAAAAAAAAANAAcAAAAAAAAAAAAOAAcAAAAAAAAAAAAOAAgAAAAAAAAAAAANAAgAAAAAAAAAAAAMAAgAAAAAAAAAAAALAAgAAAAAAAAAAAAKAAgAAAAAAAAAAAAJAAgAAAAAAAAAAAAIAAgAAAAAAAAAAAAHAAgAA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AAUAAAABAAAAAAAQAAkAAAAAAAAAAAARAAkAAAAAAAAAAAARAAgAAAAAAAAAAAASAAgAAAAAAAAAAAATAAgAAAAAAAAAAAAUAAkAAAAAAAAAAAATAAkAAAAAAAAAAAARAAcAAAAAAAAAAAAQAAcAAAAAAAAAAAAQAAYAAAAAAAAAAAAQAAUAAAAAAAAAAAARAAUAAAAAAAAAAAARAAQAAAAAAAAAAAASAAQAAAAAAAAAAAATAAQAAAAAAAAAAAAUAAQAAAAAAAAAAAAUAAUAAAAAAAAAAAAVAAUAAAAAAAAAAAAVAAYAAAAAAAAAAAAVAAcAAAAAAAAAAAAVAAgAAAAAAAAAAAAVAAkAAAAAAAAAAAASAAcAAAAAAAAAAAASAAYAAAAAAAAAAAASAAUAAAAAAAAAAAATAAUAAAAAAAAAAAAUAAYAAAAAAAAAAAAUAAcAAAAAAAAAAAAUAAgAAAAAAAAAAAATAAcAAAAAAAAAAAATAAYAAAAAAAAAAAAQAAQAAAAAAAAAAAAQAAgAAAAAAAAAAAARAAYAAAAAAAAAAAASAAkAAAAAAAAAAAAWAAkAAAAAAAAAAAAWAAgAAAAAAAAAAAAWAAcAAAAAAAAAAAAWAAYAAAAAAAAAAAAWAAUAAAAAAAAAAAAWAAQAAAAAAAAAAAAVAAQAAAAAAAAAAAA=") +tile_set = ExtResource("1_57l66") + +[node name="Character" parent="." node_paths=PackedStringArray("map") instance=ExtResource("2_fn2sa")] +position = Vector2(152, 136) +script = ExtResource("3_57l66") +map = NodePath("../Map") + +[node name="Camera2D" type="Camera2D" parent="."] +anchor_mode = 0 +zoom = Vector2(2, 2) -- cgit v1.2.3 From 588a80a339a64f15b2e3bada550beb14e16abe3e Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 16 Aug 2025 13:38:40 -0300 Subject: Parar de verificar input a cada frame. --- scenes/character.tscn | 4 +++- scenes/test_map.tscn | 12 +++++------- scripts/Character.cs | 29 ++++++++++++++++------------- 3 files changed, 24 insertions(+), 21 deletions(-) (limited to 'scenes') diff --git a/scenes/character.tscn b/scenes/character.tscn index c99e194..825f5bf 100644 --- a/scenes/character.tscn +++ b/scenes/character.tscn @@ -1,7 +1,9 @@ -[gd_scene load_steps=2 format=3 uid="uid://bl01llfbscv6r"] +[gd_scene load_steps=3 format=3 uid="uid://bl01llfbscv6r"] [ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/character.png" id="1_agfs1"] +[ext_resource type="Script" uid="uid://c840l08453pu2" path="res://scripts/Character.cs" id="2_rkhd4"] [node name="Character" type="Sprite2D"] texture_filter = 1 texture = ExtResource("1_agfs1") +script = ExtResource("2_rkhd4") diff --git a/scenes/test_map.tscn b/scenes/test_map.tscn index 427fd21..14a3aa4 100644 --- a/scenes/test_map.tscn +++ b/scenes/test_map.tscn @@ -1,8 +1,7 @@ -[gd_scene load_steps=4 format=4 uid="uid://u5h6iqyi8wd0"] +[gd_scene load_steps=3 format=4 uid="uid://u5h6iqyi8wd0"] [ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_57l66"] [ext_resource type="PackedScene" uid="uid://bl01llfbscv6r" path="res://scenes/character.tscn" id="2_fn2sa"] -[ext_resource type="Script" uid="uid://c840l08453pu2" path="res://scripts/Character.cs" id="3_57l66"] [node name="Node2D" type="Node2D"] @@ -11,11 +10,10 @@ texture_filter = 1 tile_map_data = PackedByteArray("AAAHAAcAAAAAAAAAAAAIAAcAAAAAAAAAAAAJAAcAAAAAAAAAAAAKAAcAAAAAAAAAAAALAAcAAAAAAAAAAAAMAAcAAAAAAAAAAAANAAcAAAAAAAAAAAAOAAcAAAAAAAAAAAAOAAgAAAAAAAAAAAANAAgAAAAAAAAAAAAMAAgAAAAAAAAAAAALAAgAAAAAAAAAAAAKAAgAAAAAAAAAAAAJAAgAAAAAAAAAAAAIAAgAAAAAAAAAAAAHAAgAAAAAAAAAAAAHAAkAAAAAAAAAAAAIAAkAAAAAAAAAAAAKAAkAAAAAAAAAAAALAAkA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gAAAAAAAAAAAATAAgAAAAAAAAAAAAUAAkAAAAAAAAAAAATAAkAAAAAAAAAAAARAAcAAAAAAAAAAAAQAAcAAAAAAAAAAAAQAAYAAAAAAAAAAAAQAAUAAAAAAAAAAAARAAUAAAAAAAAAAAARAAQAAAAAAAAAAAASAAQAAAAAAAAAAAATAAQAAAAAAAAAAAAUAAQAAAAAAAAAAAAUAAUAAAAAAAAAAAAVAAUAAAAAAAAAAAAVAAYAAAAAAAAAAAAVAAcAAAAAAAAAAAAVAAgAAAAAAAAAAAAVAAkAAAAAAAAAAAASAAcAAAAAAAAAAAASAAYAAAAAAAAAAAASAAUAAAAAAAAAAAATAAUAAAAAAAAAAAAUAAYAAAAAAAAAAAAUAAcAAAAAAAAAAAAUAAgAAAAAAAAAAAATAAcAAAAAAAAAAAATAAYAAAAAAAAAAAAQAAQAAAAAAAAAAAAQAAgAAAAAAAAAAAARAAYAAAAAAAAAAAASAAkAAAAAAAAAAAAWAAkAAAAAAAAAAAAWAAgAAAAAAAAAAAAWAAcAAAAAAAAAAAAWAAYAAAAAAAAAAAAWAAUAAAAAAAAAAAAWAAQAAAAAAAAAAAAVAAQAAAAAAAAAAAA=") tile_set = ExtResource("1_57l66") -[node name="Character" parent="." node_paths=PackedStringArray("map") instance=ExtResource("2_fn2sa")] -position = Vector2(152, 136) -script = ExtResource("3_57l66") -map = NodePath("../Map") - [node name="Camera2D" type="Camera2D" parent="."] anchor_mode = 0 zoom = Vector2(2, 2) + +[node name="Character" parent="." node_paths=PackedStringArray("map") instance=ExtResource("2_fn2sa")] +position = Vector2(135, 135) +map = NodePath("../Map") diff --git a/scripts/Character.cs b/scripts/Character.cs index d1865f1..1e11fcc 100644 --- a/scripts/Character.cs +++ b/scripts/Character.cs @@ -4,21 +4,25 @@ using System; public partial class Character : Sprite2D { [Export] public TileMapLayer map; - public override void _Process(double delta) { - base._Process(delta); + + public override void _Input(InputEvent @event) + { + base._Input(@event); + + if (!@event.IsPressed()) return; Vector2I offset = Vector2I.Zero; - if (Input.IsActionJustPressed("walk-up")) { + if (@event.IsActionPressed("walk-up")) { offset += Vector2I.Up; } - if (Input.IsActionJustPressed("walk-down")) { + if (@event.IsActionPressed("walk-down")) { offset += Vector2I.Down; } - if (Input.IsActionJustPressed("walk-left")) { + if (@event.IsActionPressed("walk-left")) { offset += Vector2I.Left; } - if (Input.IsActionJustPressed("walk-right")) { + if (@event.IsActionPressed("walk-right")) { offset += Vector2I.Right; } @@ -28,15 +32,14 @@ public partial class Character : Sprite2D { } private void Walk(Vector2I offset) { - Vector2I gridCoords = map.LocalToMap(Position); - gridCoords += offset; - - TileData tile = map.GetCellTileData(gridCoords); - + Vector2I toMovePos = map.LocalToMap(Position); + toMovePos += offset; + TileData tile = map.GetCellTileData(toMovePos); + if (tile.HasCustomData("isWalkable") && (bool) tile.GetCustomData("isWalkable")) { - GD.Print(gridCoords); - Position = map.MapToLocal(gridCoords); + GD.Print(toMovePos); + Position = map.MapToLocal(toMovePos); } } } -- cgit v1.2.3 From c411c496394c7a782854e03f2be8fab4cc1e2a81 Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 16 Aug 2025 14:22:04 -0300 Subject: Herança e preparativos para o sistema de turnos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- assets/sprites/skeleton.png | Bin 0 -> 215 bytes assets/sprites/skeleton.png.import | 34 ++++++++++++++++++++++++++++++++++ assets/sprites/skeleton.pxo | Bin 0 -> 838 bytes project.godot | 4 ++++ scenes/skeleton.tscn | 8 ++++++++ scenes/test_map.tscn | 11 ++++++++--- scripts/Actor.cs | 18 ++++++++++++++++++ scripts/Actor.cs.uid | 1 + scripts/Character.cs | 16 +--------------- scripts/Enemy.cs | 6 ++++++ scripts/Enemy.cs.uid | 1 + 11 files changed, 81 insertions(+), 18 deletions(-) create mode 100644 assets/sprites/skeleton.png create mode 100644 assets/sprites/skeleton.png.import create mode 100644 assets/sprites/skeleton.pxo create mode 100644 scenes/skeleton.tscn create mode 100644 scripts/Actor.cs create mode 100644 scripts/Actor.cs.uid create mode 100644 scripts/Enemy.cs create mode 100644 scripts/Enemy.cs.uid (limited to 'scenes') diff --git a/assets/sprites/skeleton.png b/assets/sprites/skeleton.png new file mode 100644 index 0000000..224afc6 Binary files /dev/null and b/assets/sprites/skeleton.png differ diff --git a/assets/sprites/skeleton.png.import b/assets/sprites/skeleton.png.import new file mode 100644 index 0000000..4b41cb3 --- /dev/null +++ b/assets/sprites/skeleton.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://dh5sgjdwkps88" +path="res://.godot/imported/skeleton.png-3c82138048422abf990547c960b9a428.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://assets/sprites/skeleton.png" +dest_files=["res://.godot/imported/skeleton.png-3c82138048422abf990547c960b9a428.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/assets/sprites/skeleton.pxo b/assets/sprites/skeleton.pxo new file mode 100644 index 0000000..d2cfbf3 Binary files /dev/null and b/assets/sprites/skeleton.pxo differ diff --git a/project.godot b/project.godot index fb9e219..bace009 100644 --- a/project.godot +++ b/project.godot @@ -41,3 +41,7 @@ walk-right={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } + +[rendering] + +textures/canvas_textures/default_texture_filter=0 diff --git a/scenes/skeleton.tscn b/scenes/skeleton.tscn new file mode 100644 index 0000000..8471909 --- /dev/null +++ b/scenes/skeleton.tscn @@ -0,0 +1,8 @@ +[gd_scene load_steps=3 format=3 uid="uid://bsn4a4tfensy8"] + +[ext_resource type="Texture2D" uid="uid://dh5sgjdwkps88" path="res://assets/sprites/skeleton.png" id="1_pbvs3"] +[ext_resource type="Script" uid="uid://bef1fo3vgvxej" path="res://scripts/Enemy.cs" id="2_txkty"] + +[node name="Skeleton" type="Sprite2D"] +texture = ExtResource("1_pbvs3") +script = ExtResource("2_txkty") diff --git a/scenes/test_map.tscn b/scenes/test_map.tscn index 14a3aa4..446e6d7 100644 --- a/scenes/test_map.tscn +++ b/scenes/test_map.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=3 format=4 uid="uid://u5h6iqyi8wd0"] +[gd_scene load_steps=4 format=4 uid="uid://u5h6iqyi8wd0"] [ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_57l66"] [ext_resource type="PackedScene" uid="uid://bl01llfbscv6r" path="res://scenes/character.tscn" id="2_fn2sa"] +[ext_resource type="PackedScene" uid="uid://bsn4a4tfensy8" path="res://scenes/skeleton.tscn" id="3_57l66"] [node name="Node2D" type="Node2D"] @@ -14,6 +15,10 @@ tile_set = ExtResource("1_57l66") anchor_mode = 0 zoom = Vector2(2, 2) -[node name="Character" parent="." node_paths=PackedStringArray("map") instance=ExtResource("2_fn2sa")] +[node name="Character" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("2_fn2sa")] position = Vector2(135, 135) -map = NodePath("../Map") +Map = NodePath("../Map") + +[node name="Skeleon" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("3_57l66")] +position = Vector2(184, 136) +Map = NodePath("../Map") diff --git a/scripts/Actor.cs b/scripts/Actor.cs new file mode 100644 index 0000000..fc69edf --- /dev/null +++ b/scripts/Actor.cs @@ -0,0 +1,18 @@ +using Godot; + +public partial class Actor : Node2D { + [Export] + public TileMapLayer Map { get; set; } + + protected void Walk(Vector2I offset) { + Vector2I toMovePos = Map.LocalToMap(Position); + toMovePos += offset; + + TileData tile = Map.GetCellTileData(toMovePos); + + if (tile.HasCustomData("isWalkable") && (bool) tile.GetCustomData("isWalkable")) { + GD.Print(toMovePos); + Position = Map.MapToLocal(toMovePos); + } + } +} \ No newline at end of file diff --git a/scripts/Actor.cs.uid b/scripts/Actor.cs.uid new file mode 100644 index 0000000..cf29b40 --- /dev/null +++ b/scripts/Actor.cs.uid @@ -0,0 +1 @@ +uid://c0cm4woy8lawl diff --git a/scripts/Character.cs b/scripts/Character.cs index 1e11fcc..e3707f5 100644 --- a/scripts/Character.cs +++ b/scripts/Character.cs @@ -1,9 +1,7 @@ using Godot; using System; -public partial class Character : Sprite2D { - [Export] - public TileMapLayer map; +public partial class Character : Actor { public override void _Input(InputEvent @event) { @@ -30,16 +28,4 @@ public partial class Character : Sprite2D { Walk(offset); } } - - private void Walk(Vector2I offset) { - Vector2I toMovePos = map.LocalToMap(Position); - toMovePos += offset; - - TileData tile = map.GetCellTileData(toMovePos); - - if (tile.HasCustomData("isWalkable") && (bool) tile.GetCustomData("isWalkable")) { - GD.Print(toMovePos); - Position = map.MapToLocal(toMovePos); - } - } } diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs new file mode 100644 index 0000000..6f48bd1 --- /dev/null +++ b/scripts/Enemy.cs @@ -0,0 +1,6 @@ +using Godot; +using System; + +public partial class Enemy : Actor { + +} diff --git a/scripts/Enemy.cs.uid b/scripts/Enemy.cs.uid new file mode 100644 index 0000000..93255b7 --- /dev/null +++ b/scripts/Enemy.cs.uid @@ -0,0 +1 @@ +uid://bef1fo3vgvxej -- cgit v1.2.3 From b05cfd5577884d1a398dbb226e2082af5fe8f8fa Mon Sep 17 00:00:00 2001 From: Matheus Date: Sat, 16 Aug 2025 15:56:28 -0300 Subject: Sistema de turnos básico MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project.godot | 5 ++++ scenes/character.tscn | 5 +++- scenes/skeleton.tscn | 2 +- scenes/test_map.tscn | 21 ++++++++++------ scenes/turn_manager.tscn | 6 +++++ scripts/Actor.cs | 19 +++++++++++++- scripts/Character.cs | 50 ++++++++++++++++++++++++++----------- scripts/DungeonLevel.cs | 18 +++++++++++++ scripts/DungeonLevel.cs.uid | 1 + scripts/Enemy.cs | 6 ++++- scripts/TurnManager.cs | 61 +++++++++++++++++++++++++++++++++++++++++++++ scripts/TurnManager.cs.uid | 1 + 12 files changed, 168 insertions(+), 27 deletions(-) create mode 100644 scenes/turn_manager.tscn create mode 100644 scripts/DungeonLevel.cs create mode 100644 scripts/DungeonLevel.cs.uid create mode 100644 scripts/TurnManager.cs create mode 100644 scripts/TurnManager.cs.uid (limited to 'scenes') diff --git a/project.godot b/project.godot index bace009..0e7d507 100644 --- a/project.godot +++ b/project.godot @@ -41,6 +41,11 @@ walk-right={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +skip-turn={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":46,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) +] +} [rendering] diff --git a/scenes/character.tscn b/scenes/character.tscn index 825f5bf..4b23758 100644 --- a/scenes/character.tscn +++ b/scenes/character.tscn @@ -3,7 +3,10 @@ [ext_resource type="Texture2D" uid="uid://dwky8qc2y602k" path="res://assets/sprites/character.png" id="1_agfs1"] [ext_resource type="Script" uid="uid://c840l08453pu2" path="res://scripts/Character.cs" id="2_rkhd4"] -[node name="Character" type="Sprite2D"] +[node name="Character" type="Sprite2D" groups=["TimeSlave"]] texture_filter = 1 texture = ExtResource("1_agfs1") script = ExtResource("2_rkhd4") + +[node name="Camera2D" type="Camera2D" parent="."] +zoom = Vector2(4, 4) diff --git a/scenes/skeleton.tscn b/scenes/skeleton.tscn index 8471909..1dc7727 100644 --- a/scenes/skeleton.tscn +++ b/scenes/skeleton.tscn @@ -3,6 +3,6 @@ [ext_resource type="Texture2D" uid="uid://dh5sgjdwkps88" path="res://assets/sprites/skeleton.png" id="1_pbvs3"] [ext_resource type="Script" uid="uid://bef1fo3vgvxej" path="res://scripts/Enemy.cs" id="2_txkty"] -[node name="Skeleton" type="Sprite2D"] +[node name="Skeleton" type="Sprite2D" groups=["TimeSlave"]] texture = ExtResource("1_pbvs3") script = ExtResource("2_txkty") diff --git a/scenes/test_map.tscn b/scenes/test_map.tscn index 446e6d7..a5c4039 100644 --- a/scenes/test_map.tscn +++ b/scenes/test_map.tscn @@ -1,24 +1,29 @@ -[gd_scene load_steps=4 format=4 uid="uid://u5h6iqyi8wd0"] +[gd_scene load_steps=6 format=4 uid="uid://u5h6iqyi8wd0"] [ext_resource type="TileSet" uid="uid://biilh0ufacguh" path="res://assets/test_tileset.tres" id="1_57l66"] +[ext_resource type="Script" uid="uid://dwubb28wt4bhe" path="res://scripts/DungeonLevel.cs" id="1_p21b5"] [ext_resource type="PackedScene" uid="uid://bl01llfbscv6r" path="res://scenes/character.tscn" id="2_fn2sa"] [ext_resource type="PackedScene" uid="uid://bsn4a4tfensy8" path="res://scenes/skeleton.tscn" id="3_57l66"] +[ext_resource type="PackedScene" uid="uid://ie3vpgatjvkw" path="res://scenes/turn_manager.tscn" id="4_p21b5"] -[node name="Node2D" type="Node2D"] +[node name="DungeonLevel" type="Node2D"] +script = ExtResource("1_p21b5") [node name="Map" type="TileMapLayer" parent="."] texture_filter = 1 tile_map_data = PackedByteArray("AAAHAAcAAAAAAAAAAAAIAAcAAAAAAAAAAAAJAAcAAAAAAAAAAAAKAAcAAAAAAAAAAAALAAcAAAAAAAAAAAAMAAcAAAAAAAAAAA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XAAMAAAABAAAAAAAWAAMAAAABAAAAAAAVAAMAAAABAAAAAAAUAAMAAAABAAAAAAATAAMAAAABAAAAAAASAAMAAAABAAAAAAARAAMAAAABAAAAAAAQAAMAAAABAAAAAAAPAAMAAAABAAAAAAAPAAQAAAABAAAAAAAPAAUAAAABAAAAAAAQAAkAAAAAAAAAAAARAAkAAAAAAAAAAAARAAgAAAAAAAAAAAASAAgAAAAAAAAAAAATAAgAAAAAAAAAAAAUAAkAAAAAAAAAAAATAAkAAAAAAAAAAAARAAcAAAAAAAAAAAAQAAcAAAAAAAAAAAAQAAYAAAAAAAAAAAAQAAUAAAAAAAAAAAARAAUAAAAAAAAAAAARAAQAAAAAAAAAAAASAAQAAAAAAAAAAAATAAQAAAAAAAAAAAAUAAQAAAAAAAAAAAAUAAUAAAAAAAAAAAAVAAUAAAAAAAAAAAAVAAYAAAAAAAAAAAAVAAcAAAAAAAAAAAAVAAgAAAAAAAAAAAAVAAkAAAAAAAAAAAASAAcAAAAAAAAAAAASAAYAAAAAAAAAAAASAAUAAAAAAAAAAAATAAUAAAAAAAAAAAAUAAYAAAAAAAAAAAAUAAcAAAAAAAAAAAAUAAgAAAAAAAAAAAATAAcAAAAAAAAAAAATAAYAAAAAAAAAAAAQAAQAAAAAAAAAAAAQAAgAAAAAAAAAAAARAAYAAAAAAAAAAAASAAkAAAAAAAAAAAAWAAkAAAAAAAAAAAAWAAgAAAAAAAAAAAAWAAcAAAAAAAAAAAAWAAYAAAAAAAAAAAAWAAUAAAAAAAAAAAAWAAQAAAAAAAAAAAAVAAQAAAAAAAAAAAA=") tile_set = ExtResource("1_57l66") -[node name="Camera2D" type="Camera2D" parent="."] -anchor_mode = 0 -zoom = Vector2(2, 2) +[node name="Skeleton" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("3_57l66")] +position = Vector2(120, 121) +Map = NodePath("../Map") [node name="Character" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("2_fn2sa")] position = Vector2(135, 135) Map = NodePath("../Map") -[node name="Skeleon" parent="." node_paths=PackedStringArray("Map") instance=ExtResource("3_57l66")] -position = Vector2(184, 136) -Map = NodePath("../Map") +[node name="TurnManager" parent="." instance=ExtResource("4_p21b5")] + +[connection signal="actionPerformed" from="Skeleton" to="TurnManager" method="OnActionEnd"] +[connection signal="actionPerformed" from="Character" to="TurnManager" method="OnActionEnd"] +[connection signal="turnEnd" from="TurnManager" to="." method="OnTurnEnd"] diff --git a/scenes/turn_manager.tscn b/scenes/turn_manager.tscn new file mode 100644 index 0000000..4a1cf5c --- /dev/null +++ b/scenes/turn_manager.tscn @@ -0,0 +1,6 @@ +[gd_scene load_steps=2 format=3 uid="uid://ie3vpgatjvkw"] + +[ext_resource type="Script" uid="uid://ynjn2pmluvf6" path="res://scripts/TurnManager.cs" id="1_3c2a3"] + +[node name="TurnManager" type="Node"] +script = ExtResource("1_3c2a3") diff --git a/scripts/Actor.cs b/scripts/Actor.cs index fc69edf..b360545 100644 --- a/scripts/Actor.cs +++ b/scripts/Actor.cs @@ -1,8 +1,16 @@ using Godot; -public partial class Actor : Node2D { +public abstract partial class Actor : Node2D { + static int baseWalkCost = 10; [Export] public TileMapLayer Map { get; set; } + [Signal] + public delegate void actionPerformedEventHandler(); + + [Export] + public int Energy { get; set; } = 0; + [Export] + public int Speed { get; protected set; } = 10; protected void Walk(Vector2I offset) { Vector2I toMovePos = Map.LocalToMap(Position); @@ -14,5 +22,14 @@ public partial class Actor : Node2D { GD.Print(toMovePos); Position = Map.MapToLocal(toMovePos); } + + Energy -= baseWalkCost; + EndAction(); } + + protected virtual void EndAction() { + EmitSignal(SignalName.actionPerformed); + } + + public abstract void performAction(); } \ No newline at end of file diff --git a/scripts/Character.cs b/scripts/Character.cs index e3707f5..172ffe4 100644 --- a/scripts/Character.cs +++ b/scripts/Character.cs @@ -2,6 +2,7 @@ using Godot; using System; public partial class Character : Actor { + private bool canAct = false; public override void _Input(InputEvent @event) { @@ -9,23 +10,42 @@ public partial class Character : Actor { if (!@event.IsPressed()) return; - Vector2I offset = Vector2I.Zero; + if (canAct) { + - if (@event.IsActionPressed("walk-up")) { - offset += Vector2I.Up; - } - if (@event.IsActionPressed("walk-down")) { - offset += Vector2I.Down; - } - if (@event.IsActionPressed("walk-left")) { - offset += Vector2I.Left; - } - if (@event.IsActionPressed("walk-right")) { - offset += Vector2I.Right; - } + if (@event.IsActionPressed("walk-up")) { + Walk(Vector2I.Up); + } + if (@event.IsActionPressed("walk-down")) { + Walk(Vector2I.Down); + } + if (@event.IsActionPressed("walk-left")) { + Walk(Vector2I.Left); + } + if (@event.IsActionPressed("walk-right")) { + GD.Print("Hello!"); + Walk(Vector2I.Right); + } - if (offset != Vector2I.Zero) { - Walk(offset); + if (@event.IsActionPressed("skip-turn")) { + SkipTurn(); + } } } + + private void SkipTurn() { + GD.Print("Skipped the turn."); + Energy = 0; + EndAction(); + } + + protected override void EndAction() { + canAct = false; + base.EndAction(); + } + + public override void performAction() { + GD.Print("I can act"); + canAct = true; + } } diff --git a/scripts/DungeonLevel.cs b/scripts/DungeonLevel.cs new file mode 100644 index 0000000..c3536ac --- /dev/null +++ b/scripts/DungeonLevel.cs @@ -0,0 +1,18 @@ +using Godot; +using System; + +public partial class DungeonLevel : Node2D { + TurnManager turnManager; + + public override void _Ready() { + base._Ready(); + + turnManager = GetNode("TurnManager"); + + turnManager.Tick(); + } + + public void OnTurnEnd() { + turnManager.Tick(); + } +} diff --git a/scripts/DungeonLevel.cs.uid b/scripts/DungeonLevel.cs.uid new file mode 100644 index 0000000..5c3c2a2 --- /dev/null +++ b/scripts/DungeonLevel.cs.uid @@ -0,0 +1 @@ +uid://dwubb28wt4bhe diff --git a/scripts/Enemy.cs b/scripts/Enemy.cs index 6f48bd1..52eb27f 100644 --- a/scripts/Enemy.cs +++ b/scripts/Enemy.cs @@ -2,5 +2,9 @@ using Godot; using System; public partial class Enemy : Actor { - + public override void performAction() { + Walk(Vector2I.Right); + + GD.Print("Energy after walking: " + Energy); + } } diff --git a/scripts/TurnManager.cs b/scripts/TurnManager.cs new file mode 100644 index 0000000..ffb2659 --- /dev/null +++ b/scripts/TurnManager.cs @@ -0,0 +1,61 @@ +using Godot; +using System; +using System.Collections.Generic; +using System.Reflection.Metadata.Ecma335; + +public partial class TurnManager : Node { + [Signal] + public delegate void turnBeginEventHandler(); + [Signal] + public delegate void turnEndEventHandler(); + + private Godot.Collections.Array actors = []; + private int index = 0; + + public int TurnCount { get; private set; } = 1; + + public void Tick() { + EmitSignal(SignalName.turnBegin); + + GD.Print("Turn: " + TurnCount); + + actors.Clear(); + actors = GetTree().GetNodesInGroup("TimeSlave"); + + GD.Print("Actor count: " + actors.Count); + + index = -1; + NextActor(); + } + + private void NextActor() { + index++; + GD.Print("Index: " + index); + if (index >= actors.Count) { + EndTurn(); + return; + } + Actor currentActor = (Actor) actors[index]; + currentActor.Energy += currentActor.Speed; + ActorPerformAction(); + } + + private void ActorPerformAction() { + Actor currentActor = (Actor) actors[index]; + if (currentActor.Energy > 0) { + currentActor.performAction(); + } else { + NextActor(); + } + } + + public void OnActionEnd() { + ActorPerformAction(); + } + + private void EndTurn() { + GD.Print("Turn End"); + TurnCount++; + EmitSignal(SignalName.turnEnd); + } +} diff --git a/scripts/TurnManager.cs.uid b/scripts/TurnManager.cs.uid new file mode 100644 index 0000000..a306f3e --- /dev/null +++ b/scripts/TurnManager.cs.uid @@ -0,0 +1 @@ +uid://ynjn2pmluvf6 -- cgit v1.2.3