mirror of
https://codeberg.org/Melon-Bread/Comets.gd.git
synced 2025-07-06 22:54:36 -04:00
Created an invader spawner that gives points when shot
This commit is contained in:
@ -38,6 +38,10 @@ func game_over() -> void:
|
||||
if score > high_score:
|
||||
save_score()
|
||||
|
||||
func _on_invader_spawner_shot() -> void:
|
||||
# This is not the most modular way to do this.
|
||||
score += 500
|
||||
|
||||
func increase_score(comet_size : int) -> void:
|
||||
# We add one since comet_size starts count at 0
|
||||
comet_size += 1
|
||||
@ -59,5 +63,3 @@ func load_score() -> int:
|
||||
return file.get_var(score)
|
||||
else:
|
||||
return 0
|
||||
|
||||
|
||||
|
26
scripts/invader_spawner.gd
Normal file
26
scripts/invader_spawner.gd
Normal file
@ -0,0 +1,26 @@
|
||||
extends Node2D
|
||||
|
||||
signal shot
|
||||
|
||||
const INVADER = preload("res://scenes/invader.tscn")
|
||||
|
||||
var can_spawn = false
|
||||
|
||||
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()
|
Reference in New Issue
Block a user