blob: fbdb0975a2e11f6b12f9091d053070afa1bfef8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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
|