Commit e5c9e7ca authored by Nathan Lovato's avatar Nathan Lovato

Add game restart on key press or on touch at the high score screen

parent 025a51ed
......@@ -7,6 +7,8 @@ onready var foreground :Node2D = $Foreground
onready var gnu := $Gnu
onready var score_board := $UI/ScoreBoard
var waiting_to_restart :bool = false
func _ready() -> void:
pillar_spawner.connect("pillar_checkpoint_reached", self, "increase_score")
......@@ -14,6 +16,9 @@ func _ready() -> void:
func _unhandled_input(event) -> void:
if waiting_to_restart:
if event.is_action_pressed("ui_accept") or event.is_action_pressed("tap"):
get_tree().reload_current_scene()
if event.is_action_pressed("reset"):
get_tree().reload_current_scene()
......@@ -30,3 +35,4 @@ func _on_Gnu_died() -> void:
score_label.fade_out()
yield(get_tree().create_timer(0.6), "timeout")
score_board.start(score_label.score)
waiting_to_restart = true
......@@ -6,6 +6,7 @@
[node name="ScoreBoard" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
mouse_filter = 2
script = ExtResource( 1 )
[node name="Column" type="VBoxContainer" parent="."]
......@@ -15,6 +16,7 @@ margin_left = 120.0
margin_top = 400.0
margin_right = -120.0
margin_bottom = -340.0
mouse_filter = 2
[node name="Title" type="Label" parent="Column"]
margin_right = 840.0
......@@ -28,5 +30,6 @@ uppercase = true
margin_top = 116.0
margin_right = 840.0
margin_bottom = 1180.0
mouse_filter = 2
size_flags_vertical = 3
......@@ -23,18 +23,19 @@ func register(score:int):
sorted_scores.sort_custom(self, 'sort_scores')
sorted_scores.pop_back()
_scores = sorted_scores
save()
static func sort_scores(a:Dictionary, b:Dictionary) -> bool:
return a['score'] >= b['score']
func save(scores:Array=[]) -> void:
if scores.size() != 10:
func save() -> void:
if _scores.size() != 10:
return
var file := ConfigFile.new()
for i in range(scores.size()):
file.set_value(SCORE_SECTION, str(i), scores[i])
for i in range(_scores.size()):
file.set_value(SCORE_SECTION, str(i), _scores[i])
file.save(SCORES_PATH)
......
......@@ -43,6 +43,7 @@ anchor_right = 1.0
anchor_bottom = 0.5
margin_top = -44.0
margin_bottom = 44.0
mouse_filter = 2
alignment = 1
script = ExtResource( 1 )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment