Jam10/Scripts/InGameUI.gd

56 lines
1.6 KiB
GDScript

extends CanvasLayer
const Constants = preload("res://Scripts/Constants.gd")
const FLASH_BOOST_DUR : float = 1.0
const FLASH_BOOST_CYCLE : float = 0.1
var scene : GameScene
var player : DownhillAutoscrollerPlayer
var boost_label : RichTextLabel
var flash_boost : bool
var flash_time_elapsed : float
var speedometer : RichTextLabel
var timer : RichTextLabel
# Called when the node enters the scene tree for the first time.
func _ready():
scene = get_node("/root/Scene")
player = get_node("/root/Scene/Player")
speedometer = get_node("Speedometer")
timer = get_node("Timer")
boost_label = get_node("BoostLabel")
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
speedometer.text = str(floor(scene.player_speed_mph)) + " MPH"
var dec_value : int = floor((scene.time_elapsed_in_race - floor(scene.time_elapsed_in_race))
* 100)
timer.text = str(floor(scene.time_elapsed_in_race)) + ":" + str(dec_value)
if player.get_current_action() == Constants.UnitCurrentAction.SPINNING:
flash_boost = false
flash_time_elapsed = 0
boost_label.remove_color_override("default_color")
boost_label.visible = true
boost_label.text = "+" + str(floor(player.boost * 1.36)) + " MPH"
else:
if flash_boost:
boost_label.add_color_override("default_color", Color.green)
flash_time_elapsed += delta
if flash_time_elapsed > FLASH_BOOST_DUR:
flash_boost = false
else:
if int(floor(flash_time_elapsed / FLASH_BOOST_CYCLE)) % 2 == 0:
boost_label.visible = true
else:
boost_label.visible = false
else:
boost_label.visible = false