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(1, 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()