extends Control @export var world_path : NodePath = NodePath() @onready var game_running_widgets : Control = $'GameRunningWidgets' @onready var game_startup_widgets : Control = $'GameStartupWidgets' @onready var game_finished_widgets : Control = $'GameFinishedWidgets' @onready var player1_score_label : Label = $'GameRunningWidgets/Player1Widgets/ScoreLabel' @onready var player2_score_label : Label = $'GameRunningWidgets/Player2Widgets/ScoreLabel' @onready var player2_widgets : Control = $'GameRunningWidgets/Player2Widgets' @onready var time_left_label : Label = $'GameRunningWidgets/TimeWidgets/TimeLeftLabel' var world : World = null # Called when the node enters the scene tree for the first time. func _ready(): world = get_node(world_path) if world.players.size() == 1: player2_widgets.visible = false func _process(_delta): if world.game_state == World.GameState.Startup: game_startup_widgets.visible = true game_running_widgets.visible = false game_finished_widgets.visible = false elif world.game_state == World.GameState.Running: game_startup_widgets.visible = false game_running_widgets.visible = true game_finished_widgets.visible = false var minutes = floor(world.time_left / 60.) var seconds = fmod(floor(world.time_left), 60) var milliseconds = floor((world.time_left - floor(world.time_left)) * 10) time_left_label.text = str(minutes) + ":" + str(seconds) + ":" + str(milliseconds) elif world.game_state == World.GameState.Finished: game_startup_widgets.visible = false game_running_widgets.visible = false game_finished_widgets.visible = true player1_score_label.text = str(world.players[0].score) if player2_widgets.visible: player2_score_label.text = str(world.players[1].score) func _input(event): if event.is_action_pressed("ui_accept"): if world.game_state == World.GameState.Startup: world.game_state = World.GameState.Running if event.is_action_pressed("ui_cancel"): if world.game_state == World.GameState.Finished: world.game_state = World.GameState.Startup