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

[GlobalClass]
public abstract partial class Actor : Sprite2D
{
	private ActorDefinition definition;
	private Vector2I gridPosition = Vector2I.Zero;
	public MapData Map_Data { get; set; }

	public Actor(Vector2I initialPosition, MapData map, ActorDefinition definition) {
		GridPosition = initialPosition;
		Map_Data = map;
		this.definition = definition;
		Texture = definition.texture;
		Centered = false;
	}

	public Vector2I GridPosition {
		set {
			gridPosition = value;
			Position = Grid.GridToWorld(value);
		}
		get => gridPosition;
	}

	public bool BlocksMovement {
		get => definition.blocksMovement;
	}

	public string ActorName {
		get => definition.name;
	}

	public override void _Ready()
	{
		base._Ready();
		GridPosition = Grid.WorldToGrid(Position);
	}

	public void Walk(Vector2I offset) {
		GridPosition += offset;
	}
}