mirror of
https://codeberg.org/Melon-Bread/Comets.gd.git
synced 2024-11-24 21:18:21 -05:00
39 lines
1.0 KiB
GDScript3
39 lines
1.0 KiB
GDScript3
|
extends Node2D
|
||
|
|
||
|
signal comet_shot (size : int)
|
||
|
signal screen_cleared
|
||
|
|
||
|
const COMET = preload("res://scenes/comet.tscn")
|
||
|
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)
|
||
|
spawn_comet(0, random_position)
|
||
|
|
||
|
func _process(_delta: float) -> void:
|
||
|
viewport_size = get_viewport_rect().size
|
||
|
if $Comets.get_child_count() <= 0:
|
||
|
screen_cleared.emit()
|
||
|
|
||
|
|
||
|
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)
|
||
|
|
||
|
|