Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/dungeon_manager.gd
blob: 513fcd612d2e1976231999457be85cb2acc9eb69 (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
extends Node3D

var grid: Array[Tile.Tile] = []
var grid_width: int
var grid_height: int

var enemy_inst = preload("res://prefabs/enemy.tscn")

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
	pass # Replace with function body.

func create_enemies() -> void:
	var num_enemies = randi_range(4, 10)
	
	for i in range(num_enemies):
		var enemy = enemy_inst.instantiate()
		enemy.target = $Player
		
		var found_pos = false
		while not found_pos:
			var pos = Vector2i(randi_range(0, grid_width-1), randi_range(0, grid_height-1))
			
			if grid[pos.y * grid_width + pos.x] == Tile.Tile.FLOOR:
				enemy.position = Vector3(pos.x, 0, pos.y)
				found_pos = true
				print("Placing at ", pos)
				
		add_child.call_deferred(enemy)

func _grid_generated(p_grid: Array[Tile.Tile], p_grid_width: int, p_grid_height: int) -> void:
	grid = p_grid
	grid_width = p_grid_width
	grid_height = p_grid_height
	
	create_enemies()