INIT
This commit is contained in:
33
levels/level_1/spawner.gd
Normal file
33
levels/level_1/spawner.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
extends Node2D
|
||||
|
||||
@export
|
||||
var spawnee: PackedScene
|
||||
|
||||
@export
|
||||
var initial_spawn_amount: int = 4
|
||||
|
||||
@export
|
||||
var score_label: Label
|
||||
|
||||
var score: int = 0
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
score_label.text = str(score)
|
||||
for i in range(initial_spawn_amount):
|
||||
spawn()
|
||||
|
||||
|
||||
func spawn() -> void:
|
||||
var new_spawnee: Node2D = spawnee.instantiate()
|
||||
new_spawnee.position = Vector2(randi_range(40, 280), randi_range(40, 200))
|
||||
|
||||
|
||||
new_spawnee.killed.connect(on_killed)
|
||||
|
||||
add_child(new_spawnee)
|
||||
|
||||
|
||||
func on_killed():
|
||||
score += 1
|
||||
score_label.text = str(score)
|
||||
Reference in New Issue
Block a user