From fac981d07822592af2b2a971c08a6f73b3197825 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Wed, 5 May 2021 19:42:35 +0200 Subject: [PATCH] show objectives --- mini-game/MiniGame.gd | 19 +++++++++---------- mini-game/scenes/decor/scoreUI.gd | 16 +++++++++++++--- mini-game/scenes/decor/scoreUI.tscn | 27 ++++++++++++++++++++++++--- 3 files changed, 46 insertions(+), 16 deletions(-) diff --git a/mini-game/MiniGame.gd b/mini-game/MiniGame.gd index cbbc826..6083ebf 100644 --- a/mini-game/MiniGame.gd +++ b/mini-game/MiniGame.gd @@ -35,7 +35,7 @@ func setup(mode: String, goal: int, difficulty: String, next_lose: String, next_ game_version = version print("setup minigame: " + mode + " " + next_lose + " " + next_win) set_mode(mode) - scoreUI.init(mode) + scoreUI.init(mode, goal) next_timeline_lose = next_lose next_timeline_win = next_win @@ -102,18 +102,17 @@ func _on_player_die() -> void: func _on_player_hit() -> void: pass +func update_score(): + current_goal += 1 + scoreUI.update_score(current_goal) + if current_goal >= game_goal: + on_win() + func _on_player_score() -> void: if game_mode == "score": - current_goal += 1 - scoreUI.update_score(current_goal) - if current_goal >= game_goal: - on_win() - + update_score() func _on_Timer_timeout() -> void: if game_mode == "time": - current_goal += 1 - scoreUI.update_score(game_goal - current_goal) - if current_goal >= game_goal: - on_win() + update_score() diff --git a/mini-game/scenes/decor/scoreUI.gd b/mini-game/scenes/decor/scoreUI.gd index b67e445..dc36ca0 100644 --- a/mini-game/scenes/decor/scoreUI.gd +++ b/mini-game/scenes/decor/scoreUI.gd @@ -1,11 +1,14 @@ extends Control -onready var label := $MarginContainer/Label +onready var objective_label := $MarginContainer/VBoxContainer/ObjectiveLabel +onready var score_label := $MarginContainer/VBoxContainer/ScoreLabel var game_mode +var game_objective : int + func update_score(score: int): - label.text = String(score) + score_label.text = String(score) + "/" + String(game_objective) func start(initial_score: int): @@ -13,6 +16,13 @@ func start(initial_score: int): show() -func init(mode: String): +func init(mode: String, objective: int): + game_objective = objective game_mode = mode + if game_mode == "score": + objective_label.text = "Obtenez le score indiqué" + elif game_mode == "time": + objective_label.text = "Survivez le temps indiqué" + else: + objective_label.text = "Erreur" hide() diff --git a/mini-game/scenes/decor/scoreUI.tscn b/mini-game/scenes/decor/scoreUI.tscn index 6aa81d7..22c6cd6 100644 --- a/mini-game/scenes/decor/scoreUI.tscn +++ b/mini-game/scenes/decor/scoreUI.tscn @@ -1,8 +1,14 @@ -[gd_scene load_steps=4 format=2] +[gd_scene load_steps=5 format=2] [ext_resource path="res://mini-game/ressources/font/joystix/ot/joystix monospace.otf" type="DynamicFontData" id=1] [ext_resource path="res://mini-game/scenes/decor/scoreUI.gd" type="Script" id=2] +[sub_resource type="DynamicFont" id=2] +size = 70 +outline_size = 2 +outline_color = Color( 0, 0, 0, 1 ) +font_data = ExtResource( 1 ) + [sub_resource type="DynamicFont" id=1] size = 50 outline_size = 2 @@ -28,11 +34,26 @@ __meta__ = { "_edit_use_anchors_": false } -[node name="Label" type="Label" parent="MarginContainer"] +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] margin_left = 10.0 margin_top = 10.0 margin_right = 1910.0 -margin_bottom = 71.0 +margin_bottom = 160.0 + +[node name="ObjectiveLabel" type="Label" parent="MarginContainer/VBoxContainer"] +margin_right = 1900.0 +margin_bottom = 85.0 +custom_fonts/font = SubResource( 2 ) +text = "Objective" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="ScoreLabel" type="Label" parent="MarginContainer/VBoxContainer"] +margin_top = 89.0 +margin_right = 1900.0 +margin_bottom = 150.0 custom_fonts/font = SubResource( 1 ) text = "99999" align = 1