Wave generation

This commit is contained in:
2025-07-31 21:02:49 +02:00
parent 9e72211a49
commit 6c1a3d54bd
3 changed files with 29 additions and 8 deletions

View File

@ -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()

View File

@ -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="."]

View File

@ -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="."]