Created a comet spwaner/manager for the game

This commit is contained in:
Rain Clark 2024-05-12 22:41:49 -04:00
parent 47ead79f1b
commit 2a7c2155c4
2 changed files with 46 additions and 0 deletions

View File

@ -0,0 +1,8 @@
[gd_scene load_steps=2 format=3 uid="uid://6c6g7e5v3ifr"]
[ext_resource type="Script" path="res://scripts/comet_spawner.gd" id="1_ngrtm"]
[node name="CometSpawner" type="Node2D"]
script = ExtResource("1_ngrtm")
[node name="Comets" type="Node" parent="."]

38
scripts/comet_spawner.gd Normal file
View File

@ -0,0 +1,38 @@
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)