flappy-bird/Camera2D.gd

46 lines
1.2 KiB
GDScript3
Raw Normal View History

2020-01-14 22:20:17 +01:00
extends Node
2024-04-16 12:44:28 +02:00
@export var Tower = preload("res://Tower.tscn");
2020-01-15 15:44:46 +01:00
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-16 12:44:28 +02:00
@export var tower_density = 250
2020-04-08 12:40:43 +02:00
signal spawn
2020-04-09 18:30:56 +02:00
var last_built = 300
var towers = []
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
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():
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()