36 lines
1.3 KiB
GDScript
36 lines
1.3 KiB
GDScript
# GDScript
|
|
extends Node
|
|
|
|
const ENEMY_COUNT_INIT_DELAY := 3.0
|
|
const PLAYER_GROUP := "player"
|
|
const DEFAULT_SPAWN_MANAGER_PATH := NodePath("../SpawnManager")
|
|
|
|
@onready var _player: Player = get_tree().get_first_node_in_group(PLAYER_GROUP) as Player
|
|
@onready var _spawn_manager: Node = get_node_or_null(DEFAULT_SPAWN_MANAGER_PATH)
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
if _player == null:
|
|
push_warning("GameManager: Kein Player gefunden (Export-Referenz setzen oder Gruppe 'player' verwenden).")
|
|
if _spawn_manager == null:
|
|
push_warning("GameManager: Kein SpawnManager gefunden (Export-Referenz setzen oder NodePath %s)." % str(DEFAULT_SPAWN_MANAGER_PATH))
|
|
await _schedule_enemy_count_sync()
|
|
|
|
|
|
func game_over() -> void:
|
|
var gold := _player.gold if _player else 0
|
|
print("Game Over! You have collected {gold} gold in this run. Try to collect more in the next run...".format({"gold": gold}))
|
|
|
|
|
|
# TODO: Show Game Over screen with gold
|
|
|
|
func _schedule_enemy_count_sync() -> void:
|
|
await get_tree().create_timer(ENEMY_COUNT_INIT_DELAY).timeout
|
|
if _spawn_manager and _spawn_manager.has_method("enemy_count_changed"):
|
|
_spawn_manager.call("enemy_count_changed")
|
|
|
|
func increase_player_gold(amount: int) -> void:
|
|
_player.gold += amount
|
|
print("Player gets " + str(amount) + " gold and has now " + str(_player.gold) + " in sum!")
|