2020-01-14 22:20:17 +01:00
|
|
|
extends Node
|
|
|
|
|
2024-04-16 12:44:28 +02:00
|
|
|
@onready var screen_size = Vector2(ProjectSettings.get("display/window/size/viewport_width"), ProjectSettings.get("display/window/size/viewport_height"))
|
2020-01-14 22:20:17 +01:00
|
|
|
|
2024-04-18 15:53:19 +02:00
|
|
|
# Tower variables
|
|
|
|
@export var Tower = preload("res://Tower.tscn"); # Tower scene
|
|
|
|
@export var tower_density = 250 # How often a tower should be added
|
|
|
|
var last_built = 300 # Helper variable to adhear the tower density
|
2020-04-09 18:30:56 +02:00
|
|
|
var towers = []
|
2020-01-15 15:44:46 +01:00
|
|
|
|
2024-04-18 15:53:19 +02:00
|
|
|
signal spawn # A tower is spawned in
|
|
|
|
|
|
|
|
# Build a single tower
|
2020-01-15 15:44:46 +01:00
|
|
|
func build_tower():
|
2024-04-16 12:44:28 +02:00
|
|
|
var tower = Tower.instantiate()
|
|
|
|
tower.connect("exit", Callable(self, "_on_Tower_exit"))
|
2020-01-29 21:51:40 +01:00
|
|
|
|
|
|
|
var pos = Vector2(last_built, (randf() * (screen_size.y * 0.7)) + screen_size.y * 0.15) # The player's movement vector.
|
|
|
|
|
2020-01-15 15:44:46 +01:00
|
|
|
tower.position = pos
|
2020-04-09 18:30:56 +02:00
|
|
|
towers.append(tower)
|
2020-01-15 15:44:46 +01:00
|
|
|
|
2020-04-08 12:40:43 +02:00
|
|
|
emit_signal("spawn", tower.get_global_transform().get_origin().x)
|
2020-01-15 15:44:46 +01:00
|
|
|
add_child(tower)
|
|
|
|
last_built += tower_density
|
|
|
|
|
2024-04-18 15:53:19 +02:00
|
|
|
# Build all towers
|
2020-04-09 18:30:56 +02:00
|
|
|
func build_all_towers():
|
2020-04-09 19:24:24 +02:00
|
|
|
get_tree().call_group("tower", "queue_free")
|
2020-04-09 18:30:56 +02:00
|
|
|
last_built = 300
|
|
|
|
while last_built < screen_size.x * 3:
|
|
|
|
build_tower()
|
|
|
|
|
2020-01-14 22:20:17 +01:00
|
|
|
func _ready():
|
2024-04-18 15:53:19 +02:00
|
|
|
# Connect signals
|
2020-04-08 12:40:43 +02:00
|
|
|
var ui = get_node("UI")
|
|
|
|
var player = get_node("Player")
|
2024-04-16 12:44:28 +02:00
|
|
|
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"))
|
2020-01-15 15:44:46 +01:00
|
|
|
randomize()
|
|
|
|
|
|
|
|
func _on_Tower_exit():
|
|
|
|
build_tower()
|