diff options
| author | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-16 13:38:40 -0300 |
|---|---|---|
| committer | Matheus <matheus.guedes.mg.m@gmail.com> | 2025-08-16 13:38:40 -0300 |
| commit | 588a80a339a64f15b2e3bada550beb14e16abe3e (patch) | |
| tree | d5ae45279170e594ff1f3c589c070006b1bc7e90 /scripts | |
| parent | 579a2fe0f837236eec5d9f9347baa8f6a49f6458 (diff) | |
Parar de verificar input a cada frame.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/Character.cs | 29 |
1 files changed, 16 insertions, 13 deletions
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); } } } |
