Comets.gd/scripts/invader_spawner.gd

27 lines
499 B
GDScript3
Raw Normal View History

extends Node2D
signal shot
const INVADER = preload("res://scenes/invader.tscn")
var can_spawn = false
2024-05-16 14:42:02 -04:00
func _process(_delta: float) -> void:
if can_spawn:
spawn_invader()
$SpawnTimer.wait_time = randi_range(20, 40)
func _on_spawn_timer_timeout() -> void:
can_spawn = true
func spawn_invader() -> void:
var invader := INVADER.instantiate()
invader.shot.connect(player_shot)
$Invaders.add_child(invader)
can_spawn = false
$SpawnTimer.start()
func player_shot() -> void:
shot.emit()