45 lines
1.2 KiB
GDScript
45 lines
1.2 KiB
GDScript
extends Node
|
|
|
|
@export var Tower = preload("res://Tower.tscn");
|
|
|
|
@onready var screen_size = Vector2(ProjectSettings.get("display/window/size/viewport_width"), ProjectSettings.get("display/window/size/viewport_height"))
|
|
|
|
@export var tower_density = 250
|
|
|
|
signal spawn
|
|
|
|
var last_built = 300
|
|
|
|
var towers = []
|
|
|
|
func build_tower():
|
|
var tower = Tower.instantiate()
|
|
tower.connect("exit", Callable(self, "_on_Tower_exit"))
|
|
|
|
var pos = Vector2(last_built, (randf() * (screen_size.y * 0.7)) + screen_size.y * 0.15) # The player's movement vector.
|
|
|
|
tower.position = pos
|
|
towers.append(tower)
|
|
|
|
emit_signal("spawn", tower.get_global_transform().get_origin().x)
|
|
add_child(tower)
|
|
last_built += tower_density
|
|
|
|
func build_all_towers():
|
|
get_tree().call_group("tower", "queue_free")
|
|
last_built = 300
|
|
while last_built < screen_size.x * 3:
|
|
build_tower()
|
|
|
|
func _ready():
|
|
var ui = get_node("UI")
|
|
var player = get_node("Player")
|
|
player.connect("start", Callable(self, "build_all_towers"))
|
|
player.connect("start", Callable(ui, "_on_Player_start"))
|
|
player.connect("hit", Callable(ui, "_on_Player_hit"))
|
|
player.connect("passed", Callable(ui, "_on_Player_passed"))
|
|
connect("spawn", Callable(player, "_on_Tower_spawn"))
|
|
randomize()
|
|
|
|
func _on_Tower_exit():
|
|
build_tower()
|