From 3a06f1c02b3977ce4b6e3dd399dda072a6e2663b Mon Sep 17 00:00:00 2001 From: Fisch Date: Sat, 9 Nov 2024 14:27:34 +0100 Subject: [PATCH] add round label to car --- scenes/car.tscn | 57 +++++++++++++++++++++++++++++++++++- scenes/game.tscn | 10 +++---- scripts/car.gd | 7 ++++- scripts/gamestate.gd | 1 + scripts/label_round.gd | 18 ++++++++++++ scripts/rounds_selection.gd | 9 ++---- sprites/car.bmp | Bin 6198 -> 0 bytes sprites/car.png | Bin 7043 -> 0 bytes sprites/car.png.import | 34 --------------------- 9 files changed, 88 insertions(+), 48 deletions(-) create mode 100644 scripts/label_round.gd delete mode 100644 sprites/car.bmp delete mode 100644 sprites/car.png delete mode 100644 sprites/car.png.import diff --git a/scenes/car.tscn b/scenes/car.tscn index f9a13dc..c82a532 100644 --- a/scenes/car.tscn +++ b/scenes/car.tscn @@ -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"] diff --git a/scenes/game.tscn b/scenes/game.tscn index cdc1824..4fc0409 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -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") diff --git a/scripts/car.gd b/scripts/car.gd index 45b8335..1357342 100644 --- a/scripts/car.gd +++ b/scripts/car.gd @@ -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 diff --git a/scripts/gamestate.gd b/scripts/gamestate.gd index 240ef77..b4429cb 100644 --- a/scripts/gamestate.gd +++ b/scripts/gamestate.gd @@ -19,6 +19,7 @@ func getRounds(): return rounds func setRounds(r): + print("Rounds set to "+str(r)) rounds=r func getSelectedMap(): diff --git a/scripts/label_round.gd b/scripts/label_round.gd new file mode 100644 index 0000000..5be90dc --- /dev/null +++ b/scripts/label_round.gd @@ -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") diff --git a/scripts/rounds_selection.gd b/scripts/rounds_selection.gd index 6236de1..cfe95f4 100644 --- a/scripts/rounds_selection.gd +++ b/scripts/rounds_selection.gd @@ -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) + diff --git a/sprites/car.bmp b/sprites/car.bmp deleted file mode 100644 index a9930defcce6de140c7bf756240c77dec4744a18..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6198 zcmdUzF;W9D3`N5&C@DEXYKERO(QpaQ!wu-T00ozT58C{}h zeSA9J9{$!5-}ks4aNXg$Icyu-4?l?gt(ZXpwtSv3=i!U1#- zkF}kIpBOaopZq8<`lg<%E|xnR&*eusXNS=8B7ichE|w?!#SZiEt9$hWp#1s>isP&2 zs*C07|LXke-irP^{^AIFe)I_z4}hK-)x~l>KkM>i3bRoStoX0yyYY(#s^_YU_+|s-nIt*>A+UT--VxcgeH0N3a*(yRdDH7pbAet LmAwfJfgyeX$El3A diff --git a/sprites/car.png b/sprites/car.png deleted file mode 100644 index ca142a1cf8936d8205ab4f8c799bd9e72d174a63..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7043 zcmeHLc|4SB`yZW?ts;aLWsFK<%$UWPiLBYOWhhCf#>_KgFpJrdU0M*OkSvv?Y@G;6 zyCoH&l4DIr(aE6@(&l|;sPuc!@4UbB`TXAhn$PE%dG7oEUf=7wzxQ?B&;85+S7+Nr z^2_BR5Xd5XJ8L)a*Brc{veMx9>CCVg2t+nI*xi%oMiN5V92S)x06=*`Yyb*~=u`+q z)KQe`f8@{g3Nh2A2e(IAMC`_!Xj5fMKTgFIyzd_1Jw47js=0LWx?IQhqUnzzRpBEG zus^FOr+9O(zpGvD@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^9F{PxapeD2BLU3e}C593(KoM8mY|UAcXb4Hu1o3y^e`6y0 zvV_e48_zfBR~8EnPsrlT#^8wNR|N9ab}3@OJdRhaKD``wlDqkzer>} z4uvA&kN})Y2GDQ}9&ZdcCR0#w3>oQzGC~{TG1!>}{>si}QF%fV2e6=lIRLIRSX`2I zhOV2s2d;PVpk^?^B?CE`N*FMejT@4x5)r2gULAL;u;t{-y! zBL)5u_(yjAkn0~Q@Q=Vhvg`j%F8Ob-+yE0i_X)ul>P|Yp7=3Vl{U&GYV$0o8{{mR?8^{0v diff --git a/sprites/car.png.import b/sprites/car.png.import deleted file mode 100644 index e2c8a72..0000000 --- a/sprites/car.png.import +++ /dev/null @@ -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