summaryrefslogtreecommitdiff
path: root/scripts/DungeonLevel.cs
blob: 68751c55500c8ee4e85b68524a1fba1e9c24a77d (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
using Godot;
using System;

public partial class DungeonLevel : Node2D
{
	private TileMapLayer buildingLayer;
	public Godot.Collections.Array<Actor> Actors { get; private set; } = [];

	private Node2D actorsNode;

	public override void _Ready()
	{
		base._Ready();

		buildingLayer = GetNode<TileMapLayer>("Dungeon");
		actorsNode = GetNode<Node2D>("Actors");
	}

	public void InsertActor(Actor actor) {
		Actors.Add(actor);
		actorsNode.AddChild(actor);
	}

	public bool IsTileWalkable(Vector2I pos) {
		TileData tile = buildingLayer.GetCellTileData(pos);

		if (tile == null) return false;

		return (bool)tile.GetCustomData("isWalkable");
	}

	public Actor GetBlockingActorAtPosition(Vector2I pos) {
		foreach (Actor actor in Actors) {
			if (actor.GridPosition == pos && actor.BlocksMovement) {
				return actor;
			}
		}
		return null;
	}
}