2024-05-12 22:41:49 -04:00
|
|
|
extends Node2D
|
|
|
|
|
|
|
|
signal comet_shot (size : int)
|
|
|
|
signal screen_cleared
|
|
|
|
|
|
|
|
const COMET = preload("res://scenes/comet.tscn")
|
2024-05-13 17:14:48 -04:00
|
|
|
|
2024-05-12 22:41:49 -04:00
|
|
|
var comet_count := 1
|
|
|
|
|
|
|
|
var viewport_size := Vector2.ZERO
|
|
|
|
var random_position := Vector2.ZERO
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
viewport_size = get_viewport_rect().size
|
|
|
|
for comet in range(comet_count):
|
|
|
|
random_position.x = randf_range(viewport_size.x - 100, viewport_size.x)
|
|
|
|
random_position.y = randf_range(viewport_size.y - 100, viewport_size.y)
|
2024-05-13 08:15:21 -04:00
|
|
|
spawn_comet(2, random_position)
|
2024-05-12 22:41:49 -04:00
|
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
|
|
viewport_size = get_viewport_rect().size
|
|
|
|
if $Comets.get_child_count() <= 0:
|
|
|
|
screen_cleared.emit()
|
2024-05-13 08:15:21 -04:00
|
|
|
queue_free()
|
2024-05-12 22:41:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
func spawn_comet(size : int, pos : Vector2) -> void:
|
|
|
|
var comet := COMET.instantiate()
|
|
|
|
comet.position = pos
|
|
|
|
comet.current_size = size
|
|
|
|
comet.exploded.connect(comet_cleanup)
|
|
|
|
$Comets.add_child(comet)
|
|
|
|
|
|
|
|
func comet_cleanup(new_size : int, current_position : Vector2) -> void:
|
|
|
|
comet_shot.emit(new_size + 1)
|
|
|
|
if new_size >= 0:
|
|
|
|
for n in range(2):
|
|
|
|
spawn_comet(new_size, current_position)
|
|
|
|
|
|
|
|
|