aboutsummaryrefslogtreecommitdiffstats
path: root/Scripts
diff options
context:
space:
mode:
authorLibravatar IcECreAm777 <hgk.1998@googlemail.com>2023-07-09 16:24:34 +0200
committerLibravatar IcECreAm777 <hgk.1998@googlemail.com>2023-07-09 16:24:34 +0200
commit1782e704c10c4ddf2955f72dd32ca4d068aec3e0 (patch)
tree169ac3bbb00b91044de0542701cf397c94e0f2ca /Scripts
parentbcccb662566481ea5956e40086e894aa8543f665 (diff)
download2023-1782e704c10c4ddf2955f72dd32ca4d068aec3e0.tar.gz
2023-1782e704c10c4ddf2955f72dd32ca4d068aec3e0.tar.bz2
2023-1782e704c10c4ddf2955f72dd32ca4d068aec3e0.zip
medal system
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/UI_Control.gd20
-rw-r--r--Scripts/game.gd2
-rw-r--r--Scripts/scene_control.gd17
3 files changed, 35 insertions, 4 deletions
diff --git a/Scripts/UI_Control.gd b/Scripts/UI_Control.gd
index b7ce2a5..a45503a 100644
--- a/Scripts/UI_Control.gd
+++ b/Scripts/UI_Control.gd
@@ -5,6 +5,10 @@ extends Control
@onready var time_label = $InGameUI/CurrentTime
+@onready var gold_sprite: AnimatedSprite2D = $PostGameUI/Gold
+@onready var silver_sprite: AnimatedSprite2D = $PostGameUI/Silver
+@onready var bronze_sprite: AnimatedSprite2D = $PostGameUI/Bronze
+
func update_timer_label(new_time: float):
if(new_time < 0):
@@ -12,14 +16,28 @@ func update_timer_label(new_time: float):
return
time_label.text = str(new_time).pad_decimals(3)
-func switch_to_post_game_UI():
+func switch_to_post_game_UI(medal: int):
in_game_ui.visible = false
post_game_ui.visible = true
$PostGameUI/FinalTime.text = time_label.text
+
+ if medal == 0:
+ gold_sprite.visible = true
+ gold_sprite.play("default")
+ elif medal == 1:
+ silver_sprite.visible = true
+ silver_sprite.play("default")
+ elif medal == 2:
+ bronze_sprite.visible = true
+ bronze_sprite.play("default")
func switch_to_in_game_UI():
in_game_ui.visible = true
post_game_ui.visible = false
+
+ gold_sprite.visible = false
+ silver_sprite.visible = false
+ bronze_sprite.visible = false
func _on_start_button_pressed():
var root = owner.owner
diff --git a/Scripts/game.gd b/Scripts/game.gd
index f1520dd..95ca24a 100644
--- a/Scripts/game.gd
+++ b/Scripts/game.gd
@@ -9,7 +9,7 @@ var scenes = [
preload("res://Levels/Tut01.tscn"),
preload("res://Levels/Tut02.tscn"),
preload("res://Levels/Tut03.tscn"),
- preload("res://Levels/Level_test_2.tscn")
+ preload("res://Levels/Level1.tscn")
]
# Called when the node enters the scene tree for the first time.
diff --git a/Scripts/scene_control.gd b/Scripts/scene_control.gd
index 73d9273..c4d42ec 100644
--- a/Scripts/scene_control.gd
+++ b/Scripts/scene_control.gd
@@ -2,6 +2,10 @@ extends Node
class_name SceneControl
+@export var gold_medal_time = 5.0
+@export var silver_medal_time = 7.0
+@export var bronze_medal_time = 10
+
@onready var path: Path2D = $DrawNode/TrackPath
@onready var path_follow: PathFollow2D = $DrawNode/TrackPath/TrackFollower
@onready var car = $Car
@@ -24,7 +28,7 @@ func _ready():
$UI/Control/PostGameUI/NextLevelButton.pressed.connect(next_level)
var start_button = $Start/Start as TextureButton
- start_button.pressed.connect(start_drawing)
+ start_button.button_down.connect(start_drawing)
reset_level()
@@ -75,10 +79,19 @@ func evaluate_driving():
return false
return true
+func evaluate_time():
+ if current_time < gold_medal_time:
+ return 0
+ if current_time < silver_medal_time:
+ return 1
+ if current_time < bronze_medal_time:
+ return 2
+ return 3
+
func _on_finish_line_body_entered(node: Node2D):
if evaluate_driving():
- ui.switch_to_post_game_UI()
+ ui.switch_to_post_game_UI(evaluate_time())
set_driving(false)
return