blob: d1865f1205d2a8eb6041f481def80a1ddbc4c2c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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);
}
}
}
|