summaryrefslogtreecommitdiff
path: root/components/meteor_spawner.gd
diff options
context:
space:
mode:
authorSophia Pearson <codergal89@gmail.com>2026-05-20 09:39:22 +0200
committerSophia Pearson <codergal89@gmail.com>2026-05-20 09:39:22 +0200
commit75c83f4d7a628077d9ec98bfbd674699bfa20529 (patch)
tree092244938ba3f2bf9e4355840e7f65176a6f5e3f /components/meteor_spawner.gd
downloadmoon-buggy-2d-develop.tar.xz
moon-buggy-2d-develop.zip
initial gdscript rewritedevelop
Diffstat (limited to 'components/meteor_spawner.gd')
-rw-r--r--components/meteor_spawner.gd36
1 files changed, 36 insertions, 0 deletions
diff --git a/components/meteor_spawner.gd b/components/meteor_spawner.gd
new file mode 100644
index 0000000..fbdb097
--- /dev/null
+++ b/components/meteor_spawner.gd
@@ -0,0 +1,36 @@
+class_name MeteorSpawner
+extends Path2D
+
+## Whether meteors spawned by this spawner ignore gravity or not.
+@export var ignore_gravity: bool = false
+
+@export_group("Spawning")
+
+## The duration of time, in seconds, that has to pass between consecutive spawn attempts.
+@export_range(0.0, 120, 0.1, "suffix:s") var cooldown: float = 5.0:
+ get:
+ return cooldown
+ set(value):
+ $CooldownTimer.wait_time = value
+ cooldown = value
+
+## The likelihood of actually spawning a meteor once the cooldown has elapsed.
+@export_range(0.0, 1.0) var probability: float = 0.5
+
+const _meteor_scene = preload("res://components/meteor.tscn")
+
+func _ready() -> void:
+ assert(curve.point_count == 2)
+ $SpawnPoint.progress_ratio = 0
+ $CooldownTimer.wait_time = cooldown
+ $CooldownTimer.start()
+
+func _try_to_spawn() -> void:
+ if(randf() > probability):
+ return
+
+ $SpawnPoint.progress_ratio = randf()
+ var meteor = _meteor_scene.instantiate()
+ add_child(meteor)
+
+ meteor.position = $SpawnPoint.position