add round label to car

This commit is contained in:
interfisch 2024-11-09 14:27:34 +01:00
parent 30b3bece93
commit 3a06f1c02b
9 changed files with 88 additions and 48 deletions

View file

@ -1,14 +1,52 @@
[gd_scene load_steps=6 format=3 uid="uid://0g7qqh7naniv"]
[gd_scene load_steps=10 format=3 uid="uid://0g7qqh7naniv"]
[ext_resource type="Script" path="res://scripts/car_node.gd" id="1_0tin3"]
[ext_resource type="Script" path="res://scripts/car.gd" id="1_i5tet"]
[ext_resource type="Texture2D" uid="uid://mqdujngircok" path="res://sprites/car_features.png" id="3_ts6mm"]
[ext_resource type="Texture2D" uid="uid://e5aeyl47wi8p" path="res://sprites/car_body.png" id="4_lps13"]
[ext_resource type="Script" path="res://scripts/label_round.gd" id="5_vheit"]
[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_bj1hp"]
radius = 8.0
height = 34.0
[sub_resource type="Animation" id="Animation_wl2vo"]
resource_name = "show_rounds"
length = 3.0
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("label_round:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0.133333, 0.533333, 1.5, 2.5),
"transitions": PackedFloat32Array(1, 1, 1, 1),
"update": 0,
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 0)]
}
[sub_resource type="Animation" id="Animation_3soig"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("label_round:self_modulate")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 0,
"values": [Color(1, 1, 1, 1)]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_55lyd"]
_data = {
"RESET": SubResource("Animation_3soig"),
"show_rounds": SubResource("Animation_wl2vo")
}
[node name="Car" type="Node2D"]
script = ExtResource("1_0tin3")
@ -51,5 +89,22 @@ collide_with_areas = true
wait_time = 0.1
one_shot = true
[node name="label_round" type="Label" parent="CharacterBody_Car"]
z_index = 10
offset_left = -52.0
offset_top = -12.0
offset_right = -12.0
offset_bottom = 12.0
pivot_offset = Vector2(20, 12)
text = "3/3"
horizontal_alignment = 1
vertical_alignment = 1
script = ExtResource("5_vheit")
[node name="AnimationPlayer" type="AnimationPlayer" parent="CharacterBody_Car"]
libraries = {
"": SubResource("AnimationLibrary_55lyd")
}
[connection signal="timeout" from="CharacterBody_Car/resetTimer" to="CharacterBody_Car" method="_on_reset_timer_timeout"]
[connection signal="timeout" from="CharacterBody_Car/collisionEnableTimer" to="CharacterBody_Car" method="_on_collision_enable_timer_timeout"]

View file

@ -28,7 +28,7 @@ tracks/1/keys = {
"times": PackedFloat32Array(0, 0.966667),
"transitions": PackedFloat32Array(1, 1),
"update": 0,
"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 0.568627)]
"values": [Color(1, 1, 1, 0), Color(0.446777, 0.446777, 0.446777, 0.568627)]
}
tracks/2/type = "value"
tracks/2/imported = false
@ -162,10 +162,10 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -166.0
offset_top = -252.0
offset_right = -108.0
offset_bottom = -175.0
offset_left = -483.861
offset_top = -287.132
offset_right = -425.861
offset_bottom = -210.132
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("2_80mhm")

View file

@ -216,6 +216,10 @@ func calculate_steering(delta:float):
velocity = - new_heading * min(velocity.length(),max_speed_reverse)
rotation = new_heading.angle()
func getRound():
var i=getNextCPindex()/checkpoints.size()
print("Round="+str(i)+" cpindex="+str(getNextCPindex())+" size="+str(checkpoints.size()))
return i
func check_markers():
if ray_cast_car.is_colliding():
@ -225,8 +229,9 @@ func check_markers():
#if ray_cast_car.get_collision_mask_value(COLLISIONMASK_CHECKPOINT):
var rcc_collidername=ray_cast_car.get_collider().name
if rcc_collidername=="area_finish":
$label_round.showRounds(getRound())
#print("Player "+str(playerid)+" drove through Finish")
if getNextCPindex()==-1 and finalTime==-1: #all checkpoints have times and did not finish
if getNextCPindex()==-1 and finalTime==-1: #all checkpoints have times and did not finish = Finished
print("Player "+str(playerid)+" Finished")
print("Final Time: "+str(Gamestate.getTimeElapsed()))
running=false

View file

@ -19,6 +19,7 @@ func getRounds():
return rounds
func setRounds(r):
print("Rounds set to "+str(r))
rounds=r
func getSelectedMap():

18
scripts/label_round.gd Normal file
View file

@ -0,0 +1,18 @@
extends Label
@onready var animation_player: AnimationPlayer = $"../AnimationPlayer"
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
self_modulate=Color(1,1,1,0) #start transparent
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func showRounds(round):
var rounds=Gamestate.getRounds()
text=str(round)+"/"+str(rounds)
animation_player.play("show_rounds")

View file

@ -4,13 +4,8 @@ extends OptionButton
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
select(3-1) #preselect rounds
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
Gamestate.setRounds(3)

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.9 KiB

View file

@ -1,34 +0,0 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://c2wq5xkfmca1r"
path="res://.godot/imported/car.png-b2ca7bee34d0a72d15f9ed0bc2f7996f.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://sprites/car.png"
dest_files=["res://.godot/imported/car.png-b2ca7bee34d0a72d15f9ed0bc2f7996f.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1