Add RPM and speed numbers to gauges

soundtrack
Ensar Sarajčić 2021-11-14 23:07:54 +01:00
parent 783a21325f
commit be935e9f41
3 changed files with 66 additions and 7 deletions

View File

@ -2,7 +2,9 @@ extends MarginContainer
onready var rpm_needle = $HBoxContainer/RPMGauge/RPMNeedle
onready var rpm_label = $HBoxContainer/RPMGauge/Panel/RPMLabel
onready var speed_needle = $HBoxContainer/SpeedGauge/SpeedNeedle
onready var speed_label = $HBoxContainer/SpeedGauge/Panel/SpeedLabel
onready var gear_label = $HBoxContainer/GearLabel
var min_rotation = -85
@ -11,11 +13,13 @@ var max_rotation = 75
func _get_rotation(percent: float) -> float:
return min_rotation + (max_rotation - min_rotation) * percent
func update_speed(speed_percent: float) -> void:
func update_speed(speed: int, speed_percent: float) -> void:
speed_needle.rect_rotation = _get_rotation(speed_percent)
speed_label.text = str(speed)
func update_rpm(rpm_percent: float) -> void:
func update_rpm(rpm: int, rpm_percent: float) -> void:
rpm_needle.rect_rotation = _get_rotation(rpm_percent)
rpm_label.text = str(rpm)
func update_gear(gear: int) -> void:
if gear == -1:

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=7 format=2]
[gd_scene load_steps=9 format=2]
[ext_resource path="res://assets/gauge.png" type="Texture" id=1]
[ext_resource path="res://assets/needle.png" type="Texture" id=2]
@ -7,6 +7,13 @@
[sub_resource type="CanvasItemMaterial" id=3]
[sub_resource type="StyleBoxFlat" id=4]
bg_color = Color( 0.576471, 0.576471, 0.576471, 0.392157 )
[sub_resource type="DynamicFont" id=5]
size = 14
font_data = ExtResource( 4 )
[sub_resource type="DynamicFont" id=1]
size = 48
font_data = ExtResource( 4 )
@ -53,6 +60,30 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Panel" type="Panel" parent="HBoxContainer/RPMGauge"]
anchor_left = 0.3
anchor_top = 0.6
anchor_right = 0.7
anchor_bottom = 0.8
custom_styles/panel = SubResource( 4 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="RPMLabel" type="Label" parent="HBoxContainer/RPMGauge/Panel"]
anchor_left = 0.1
anchor_top = 0.1
anchor_right = 0.9
anchor_bottom = 0.6
size_flags_vertical = 1
custom_colors/font_color = Color( 0.282353, 0.0196078, 0.0196078, 1 )
custom_fonts/font = SubResource( 5 )
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SpeedGauge" type="TextureRect" parent="HBoxContainer"]
margin_left = 148.0
margin_right = 276.0
@ -72,6 +103,30 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Panel" type="Panel" parent="HBoxContainer/SpeedGauge"]
anchor_left = 0.3
anchor_top = 0.6
anchor_right = 0.7
anchor_bottom = 0.8
custom_styles/panel = SubResource( 4 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SpeedLabel" type="Label" parent="HBoxContainer/SpeedGauge/Panel"]
anchor_left = 0.1
anchor_top = 0.1
anchor_right = 0.9
anchor_bottom = 0.6
size_flags_vertical = 1
custom_colors/font_color = Color( 0.282353, 0.0196078, 0.0196078, 1 )
custom_fonts/font = SubResource( 5 )
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="GearLabel" type="Label" parent="HBoxContainer"]
margin_left = 296.0
margin_top = 37.0

View File

@ -1,7 +1,7 @@
extends VehicleBody
signal speed_updated(speed_percent)
signal rpm_updated(rpm_percent)
signal speed_updated(speed_kph, speed_percent)
signal rpm_updated(rpm, rpm_percent)
signal gear_updated(gear)
export (float) var MAX_STEER_ANGLE = 25
@ -139,8 +139,8 @@ func _physics_process(delta: float):
rlwheel.brake = handbrake * MAX_BRAKE_FORCE / 2
var speed = wheel_rpm * 2.0 * PI * rrwheel.wheel_radius / 60.0 * 3600.0 / 1000.0
emit_signal("speed_updated", speed / EXPECTED_MAX_SPEED)
emit_signal("rpm_updated", rpm_factor)
emit_signal("speed_updated", speed, speed / EXPECTED_MAX_SPEED)
emit_signal("rpm_updated", rpm, rpm_factor)
var steering_input = Input.get_action_strength("steer_left") - Input.get_action_strength("steer_right")
if abs(steering_input) < 0.05: