summaryrefslogtreecommitdiff
path: root/scripts/Actor.cs
blob: d1969402e1ca6a1f5e0b71b1c07b7bcbfc90188c (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
using Godot;

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);
		toMovePos += offset;
		
		TileData tile = Map.GetCellTileData(toMovePos);

		if (tile != null) {
			if ((bool) tile.GetCustomData("isWalkable")) {
				Position = Map.MapToLocal(toMovePos);
			}
		}

		Energy -= baseWalkCost;
		EndAction();
	}

	protected virtual void EndAction() {
		EmitSignal(SignalName.actionPerformed);
	}

	public abstract void PerformAction();
}