Now About Social Code
summaryrefslogtreecommitdiff
path: root/scripts/dungeon_manager.gd
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/dungeon_manager.gd')
-rw-r--r--scripts/dungeon_manager.gd36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/dungeon_manager.gd b/scripts/dungeon_manager.gd
new file mode 100644
index 0000000..270a5a0
--- /dev/null
+++ b/scripts/dungeon_manager.gd
@@ -0,0 +1,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(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()