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

public partial class DungeonLevel : Node2D
{
	public Player player;
	private TileMapLayer buildingLayer;
	[Export]
	private Godot.Collections.Array<Actor> actors = [];

	private Node2D actorsNode;

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

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

	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;
	}
}