DashBoomColorClash/scenes/GameUI.gd

61 lines
2.3 KiB
GDScript
Raw Normal View History

extends Control
@export var world_path : NodePath = NodePath()
2024-01-27 23:12:04 +01:00
@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'
2024-01-27 23:30:23 +01:00
@onready var player1_energy_progressbar : ProgressBar = $'GameRunningWidgets/Player1Widgets/EnergyProgressBar'
2024-01-27 23:12:04 +01:00
@onready var player2_score_label : Label = $'GameRunningWidgets/Player2Widgets/ScoreLabel'
2024-01-27 23:30:23 +01:00
@onready var player2_energy_progressbar : ProgressBar = $'GameRunningWidgets/Player2Widgets/EnergyProgressBar'
2024-01-27 23:12:04 +01:00
@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):
2024-01-27 23:12:04 +01:00
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)
2024-01-27 23:30:23 +01:00
player1_energy_progressbar.value = world.players[0].energy
if player2_widgets.visible:
player2_score_label.text = str(world.players[1].score)
2024-01-27 23:30:23 +01:00
player2_energy_progressbar.value = world.players[1].energy
2024-01-27 23:12:04 +01:00
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