bugged-racing/player/gui.gd

34 lines
936 B
GDScript
Raw Permalink Normal View History

2021-11-13 22:55:18 +00:00
extends MarginContainer
2021-11-18 23:36:05 +00:00
var min_rotation = -85
var max_rotation = 75
2021-11-13 22:55:18 +00:00
onready var rpm_needle = $HBoxContainer/RPMGauge/RPMNeedle
2021-11-14 22:07:54 +00:00
onready var rpm_label = $HBoxContainer/RPMGauge/Panel/RPMLabel
2021-11-13 22:55:18 +00:00
onready var speed_needle = $HBoxContainer/SpeedGauge/SpeedNeedle
2021-11-14 22:07:54 +00:00
onready var speed_label = $HBoxContainer/SpeedGauge/Panel/SpeedLabel
2021-11-13 22:55:18 +00:00
onready var gear_label = $HBoxContainer/GearLabel
func _get_rotation(percent: float) -> float:
return min_rotation + (max_rotation - min_rotation) * percent
2021-11-18 23:36:05 +00:00
2021-11-14 22:07:54 +00:00
func update_speed(speed: int, speed_percent: float) -> void:
2021-11-13 22:55:18 +00:00
speed_needle.rect_rotation = _get_rotation(speed_percent)
2021-11-14 22:07:54 +00:00
speed_label.text = str(speed)
2021-11-13 22:55:18 +00:00
2021-11-18 23:36:05 +00:00
2021-11-14 22:07:54 +00:00
func update_rpm(rpm: int, rpm_percent: float) -> void:
2021-11-13 22:55:18 +00:00
rpm_needle.rect_rotation = _get_rotation(rpm_percent)
2021-11-14 22:07:54 +00:00
rpm_label.text = str(rpm)
2021-11-13 22:55:18 +00:00
2021-11-18 23:36:05 +00:00
2021-11-13 22:55:18 +00:00
func update_gear(gear: int) -> void:
if gear == -1:
gear_label.text = "R"
elif gear == 0:
gear_label.text = "N"
else:
gear_label.text = str(gear)