From 6c1a3d54bdc0c9139f41acb58320ee22af805e4e Mon Sep 17 00:00:00 2001 From: Kilokem Date: Thu, 31 Jul 2025 21:02:49 +0200 Subject: [PATCH] Wave generation --- Game/Maps/map_1.gd | 34 +++++++++++++++++++++++++++------- Game/Maps/map_1.tscn | 2 +- Game/Towers/archer_tower.tscn | 1 + 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Game/Maps/map_1.gd b/Game/Maps/map_1.gd index 5c4d459..ab7c18b 100644 --- a/Game/Maps/map_1.gd +++ b/Game/Maps/map_1.gd @@ -12,23 +12,43 @@ const enemies = [FORKMAN, COBOLD, ORK] func _ready() -> void: get_node("CanvasLayer/SidePanel").Update_Lifes(20) get_node("CanvasLayer/SidePanel").Update_Coins(2000) - + +#the meaning of the columns inside my wave generation matris: +# Number of enemies need to be spawned, chance of spawn an enemy, chance of forkman, chance of gobline, chance of ork +var waves = [ + [10, 0.2, 0.8, 0.2, 0.0], #wave 1 + [20, 0.4, 0.5, 0.5, 0.0], #wave 2 + [30, 0.5, 0.4, 0.4, 0.1], #wave 3 + [40, 0.8, 0.3, 0.2, 0.5], #wave 4 + [50, 0.9, 0.1, 0.2, 0.7], #wave 5 +] func _on_timer_timeout() -> void: spawnMonster() func spawnMonster(): - var path = PathFollow2D.new() - var monster = enemies.pick_random().instantiate() - path.add_child(monster) - - path_2d.add_child(path) + for w in waves: + if w[0] > 0: + if randf() < w[1]: #chance of generating any kind of enemy + w[0] -= 1 + var chosen = randf() + var sum = 0.0 + for i in range(2,5): + sum += w[i] + if chosen < sum: + var monster = enemies[i-2].instantiate() + var path = PathFollow2D.new() + path.add_child(monster) + path_2d.add_child(path) + break + break func decrease_life(damage) -> void: get_node("CanvasLayer/SidePanel").Update_Lifes(-damage) if get_node("CanvasLayer/SidePanel").get_Lifes() <= 0: game_over() - + + func game_over()-> void: get_node("Timer").stop() var enemy = get_node("Path2D").get_children() diff --git a/Game/Maps/map_1.tscn b/Game/Maps/map_1.tscn index ea1e276..3d1552e 100644 --- a/Game/Maps/map_1.tscn +++ b/Game/Maps/map_1.tscn @@ -1549,7 +1549,7 @@ texture = ExtResource("65_ef8wx") curve = SubResource("Curve2D_6abe5") [node name="Timer" type="Timer" parent="."] -wait_time = 1.5 +wait_time = 0.5 autostart = true [node name="TrapArea" type="Area2D" parent="."] diff --git a/Game/Towers/archer_tower.tscn b/Game/Towers/archer_tower.tscn index ed0b061..02c42f2 100644 --- a/Game/Towers/archer_tower.tscn +++ b/Game/Towers/archer_tower.tscn @@ -83,6 +83,7 @@ collision_mask = 2 shape = SubResource("CircleShape2D_be2t6") [node name="Timer" type="Timer" parent="."] +wait_time = 0.5 autostart = true [node name="Area2D" type="Area2D" parent="."]