Skip to content

Commit c247f67

Browse files
committed
feat: add simple end screen
Added a simple but usable end screen that takes the player back to level selection.
1 parent 1818d6f commit c247f67

File tree

4 files changed

+55
-16
lines changed

4 files changed

+55
-16
lines changed

scenes/end.tscn

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,37 @@
1-
[gd_scene format=2]
1+
[gd_scene load_steps=3 format=2]
2+
3+
[ext_resource path="res://scripts/end.gd" type="Script" id=1]
4+
[ext_resource path="res://assets/theme.theme" type="Theme" id=2]
25

36
[node name="Viewport" type="MarginContainer"]
7+
anchor_top = 0.5
48
anchor_right = 1.0
5-
anchor_bottom = 1.0
9+
anchor_bottom = 0.5
10+
margin_top = -62.0
11+
margin_bottom = 62.0
12+
theme = ExtResource( 2 )
613
__meta__ = {
714
"_edit_use_anchors_": false
815
}
16+
17+
[node name="EndScreen" type="VBoxContainer" parent="."]
18+
margin_left = 20.0
19+
margin_top = 20.0
20+
margin_right = 1900.0
21+
margin_bottom = 104.0
22+
script = ExtResource( 1 )
23+
24+
[node name="Score" type="Label" parent="EndScreen"]
25+
margin_right = 1880.0
26+
margin_bottom = 38.0
27+
size_flags_vertical = 1
28+
text = "SCORE"
29+
align = 1
30+
valign = 2
31+
32+
[node name="Button" type="Button" parent="EndScreen"]
33+
margin_top = 46.0
34+
margin_right = 1880.0
35+
margin_bottom = 84.0
36+
text = "restart"
37+
[connection signal="pressed" from="EndScreen/Button" to="EndScreen" method="_on_Button_pressed"]

scenes/play.tscn

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[node name="Viewport" type="MarginContainer"]
88
anchor_right = 1.0
99
anchor_bottom = 1.0
10+
theme = ExtResource( 2 )
1011
custom_constants/margin_right = 30
1112
custom_constants/margin_top = 30
1213
custom_constants/margin_left = 30
@@ -15,47 +16,46 @@ __meta__ = {
1516
"_edit_use_anchors_": false
1617
}
1718

18-
[node name="PlayingScreen" type="VBoxContainer" parent="."]
19+
[node name="GameDisplay" type="VBoxContainer" parent="."]
1920
margin_left = 30.0
2021
margin_top = 30.0
2122
margin_right = 1890.0
2223
margin_bottom = 1050.0
23-
theme = ExtResource( 2 )
2424
script = ExtResource( 1 )
2525

26-
[node name="HUDBorder" type="MarginContainer" parent="PlayingScreen"]
26+
[node name="HUDBorder" type="MarginContainer" parent="GameDisplay"]
2727
margin_right = 1860.0
2828
margin_bottom = 78.0
2929
script = ExtResource( 3 )
3030

31-
[node name="HUD" type="HBoxContainer" parent="PlayingScreen/HUDBorder"]
31+
[node name="HUD" type="HBoxContainer" parent="GameDisplay/HUDBorder"]
3232
margin_left = 20.0
3333
margin_top = 20.0
3434
margin_right = 1840.0
3535
margin_bottom = 58.0
3636

37-
[node name="Level" type="Label" parent="PlayingScreen/HUDBorder/HUD"]
37+
[node name="Level" type="Label" parent="GameDisplay/HUDBorder/HUD"]
3838
margin_right = 906.0
3939
margin_bottom = 38.0
4040
size_flags_horizontal = 3
4141
text = "LEVEL"
4242

43-
[node name="Score" type="Label" parent="PlayingScreen/HUDBorder/HUD"]
43+
[node name="Score" type="Label" parent="GameDisplay/HUDBorder/HUD"]
4444
margin_left = 914.0
4545
margin_right = 1820.0
4646
margin_bottom = 38.0
4747
size_flags_horizontal = 3
48-
text = "SCORE"
48+
text = "0.000"
4949
align = 2
5050

51-
[node name="DisplayBorder" type="MarginContainer" parent="PlayingScreen"]
51+
[node name="DisplayBorder" type="MarginContainer" parent="GameDisplay"]
5252
margin_top = 86.0
5353
margin_right = 1860.0
5454
margin_bottom = 1020.0
5555
size_flags_vertical = 3
5656
script = ExtResource( 3 )
5757

58-
[node name="Label" type="Label" parent="PlayingScreen/DisplayBorder"]
58+
[node name="Label" type="Label" parent="GameDisplay/DisplayBorder"]
5959
margin_left = 20.0
6060
margin_top = 448.0
6161
margin_right = 1840.0
@@ -66,4 +66,4 @@ align = 1
6666
[node name="Timer" type="Timer" parent="."]
6767
one_shot = true
6868
autostart = true
69-
[connection signal="timeout" from="Timer" to="PlayingScreen" method="_on_Timer_timeout"]
69+
[connection signal="timeout" from="Timer" to="GameDisplay" method="_on_Timer_timeout"]

scripts/end.gd

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extends VBoxContainer
2+
3+
func _ready():
4+
$Score.text = str(scene.get_param("score"))
5+
$Button.grab_focus()
6+
7+
func _on_Button_pressed():
8+
scene.change_scene("res://scenes/levels.tscn")

scripts/play.gd

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ func _ready():
66
$HUDBorder/HUD/Level.text = scene.get_param("level")
77

88
func _process(delta):
9-
# Show elapsed time in milliseconds
10-
var elapsed_time = stepify((OS.get_ticks_msec() - start_time) / 1000.0, 0.001)
11-
$HUDBorder/HUD/Score.text = "0.000" if start_time == -1 else "%.3f" % elapsed_time
9+
if start_time >= 0:
10+
$HUDBorder/HUD/Score.text = "%.3f" % get_score()
1211

1312
func _on_Timer_timeout():
1413
start_time = OS.get_ticks_msec()
@@ -25,5 +24,8 @@ func getLevel(level):
2524
"BUBBLE SORT":
2625
return BubbleSort
2726

27+
func get_score():
28+
return stepify((OS.get_ticks_msec() - start_time) / 1000.0, 0.001)
29+
2830
func _on_Level_done():
29-
scene.change_scene("res://scenes/end.tscn")
31+
scene.change_scene("res://scenes/end.tscn", {"score": get_score()})

0 commit comments

Comments
 (0)