Browse Source

:tada: Make the mobs appear one after another

With a delay a 15 sec for now.
DricomDragon 2 years ago
parent
commit
de94dc5ea5

+ 40 - 8
godot/component/entity/spawner/MobSpawner.gd

@@ -5,7 +5,14 @@ extends Path2D
 
 signal reset
 
-export (Array, PackedScene) var mobs
+export (Array, PackedScene) var mob_list
+
+var _mob_storage: Array
+var _running_mob: Array
+
+
+func _ready():
+	assert(!mob_list.empty())
 
 
 func spawn():
@@ -21,23 +28,48 @@ func spawn():
 	add_child(newMob)
 
 
-func _on_MobTimer_timeout():
+func _on_SpawnTimer_timeout():
 	spawn()
-	$MobTimer.start()
+	$SpawnTimer.start()
+
+
+func _on_NewMobTimer_timeout():
+	_add_mob()
+	if _has_remaining_mob_in_storage():
+		$NewMobTimer.start()
 
 
 func _on_HUD_start_game():
-	emit_signal("reset")
+	_reset()
 
 
 func _on_Main_game_started():
-	$MobTimer.start()
+	_add_mob()
+	$SpawnTimer.start()
+	$NewMobTimer.start()
 
 
 func _on_Main_game_over():
-	$MobTimer.stop()
+	$SpawnTimer.stop()
+	$NewMobTimer.stop()
 
 
 func _pick_a_mob() -> PackedScene:
-	mobs.shuffle()
-	return mobs.front()
+	assert(!_running_mob.empty())
+	_running_mob.shuffle()
+	return _running_mob.front()
+
+
+func _add_mob():
+	assert(!_mob_storage.empty())
+	_running_mob.append(_mob_storage.pop_front())
+
+
+func _has_remaining_mob_in_storage() -> bool:
+	return !_mob_storage.empty()
+
+
+func _reset():
+	_mob_storage = mob_list.duplicate()
+	_running_mob.clear()
+	emit_signal("reset")

+ 12 - 3
godot/component/entity/spawner/MobSpawner.tscn

@@ -12,12 +12,21 @@ _data = {
 [node name="MobSpawner" type="Path2D"]
 curve = SubResource( 1 )
 script = ExtResource( 1 )
-mobs = [ ExtResource( 3 ), ExtResource( 4 ) ]
+mob_list = [ ExtResource( 4 ), ExtResource( 3 ) ]
 
-[node name="MobTimer" type="Timer" parent="."]
+[node name="SpawnTimer" type="Timer" parent="."]
 process_mode = 0
 wait_time = 0.53
 
+[node name="NewMobTimer" type="Timer" parent="."]
+process_mode = 0
+wait_time = 15.0
+one_shot = true
+__meta__ = {
+"_editor_description_": "Time before arrival of a new mob"
+}
+
 [node name="MobSpawnLocation" type="PathFollow2D" parent="."]
 
-[connection signal="timeout" from="MobTimer" to="." method="_on_MobTimer_timeout"]
+[connection signal="timeout" from="SpawnTimer" to="." method="_on_SpawnTimer_timeout"]
+[connection signal="timeout" from="NewMobTimer" to="." method="_on_NewMobTimer_timeout"]