summaryrefslogtreecommitdiff
path: root/Stages/Spawn/spawn.gd
blob: 0189632fc5423fbda2de8f9576e9ec2a17081c70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
extends Node2D


@export var spawn_count := 10
@export var spawn_frequency := 2.0

var spawned_count := 0


func _ready() -> void:
	$SpawnTimer.wait_time = spawn_frequency / Game.speed
	Game.speed_changed.connect(func():
		$SpawnTimer.wait_time = spawn_frequency / Game.speed
		# calculate remaining time and set fraction accordingly
	)
	
	$AnimatedSprite.play("default")
	$AnimatedSprite.animation_finished.connect(func():
		#_on_spawn_timer_timeout()
		$SpawnTimer.start()
	)



func _on_spawn_timer_timeout() -> void:
	var unit: Unit = preload("res://Units/Default.tscn").instantiate()
	unit.position = $SpawnPosition.global_position
	get_tree().current_scene.add_child(unit)
	
	spawned_count += 1
	if spawned_count >= spawn_count:
		$SpawnTimer.stop()