diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-16 00:12:15 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-16 00:12:15 -0300 |
| commit | 579a2fe0f837236eec5d9f9347baa8f6a49f6458 (patch) | |
| tree | b91dc6db5dccb537600aba743bd565c43c59f2da /scripts/Character.cs | |
| parent | e159be9bbbf005785bd2d60af8b5c3df608f28b2 (diff) | |
Personagem que anda
Diffstat (limited to 'scripts/Character.cs')
| -rw-r--r-- | scripts/Character.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/scripts/Character.cs b/scripts/Character.cs new file mode 100644 index 0000000..d1865f1 --- /dev/null +++ b/scripts/Character.cs @@ -0,0 +1,42 @@ +using Godot; +using System; + +public partial class Character : Sprite2D { + [Export] + public TileMapLayer map; + public override void _Process(double delta) { + base._Process(delta); + + Vector2I offset = Vector2I.Zero; + + if (Input.IsActionJustPressed("walk-up")) { + offset += Vector2I.Up; + } + if (Input.IsActionJustPressed("walk-down")) { + offset += Vector2I.Down; + } + if (Input.IsActionJustPressed("walk-left")) { + offset += Vector2I.Left; + } + if (Input.IsActionJustPressed("walk-right")) { + offset += Vector2I.Right; + } + + if (offset != Vector2I.Zero) { + Walk(offset); + } + } + + private void Walk(Vector2I offset) { + Vector2I gridCoords = map.LocalToMap(Position); + gridCoords += offset; + + TileData tile = map.GetCellTileData(gridCoords); + + + if (tile.HasCustomData("isWalkable") && (bool) tile.GetCustomData("isWalkable")) { + GD.Print(gridCoords); + Position = map.MapToLocal(gridCoords); + } + } +} |
