Skip to content

Commit cf0b7ff

Browse files
committed
refactor: move end.tscn's function into play.tscn
There was no need for a separate end scene with nothing but a score and a button.
1 parent 54422fa commit cf0b7ff

File tree

6 files changed

+52
-71
lines changed

6 files changed

+52
-71
lines changed

levels/comparison_sort.gd

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const DISABLE_TIME = 1.0
1414

1515
var array: ArrayModel
1616
var active = true
17+
var _done = false
1718

1819
var _timer = Timer.new()
1920

@@ -24,10 +25,11 @@ func _init(array):
2425
_timer.connect("timeout", self, "_on_Timer_timeout")
2526
add_child(_timer)
2627
self.connect("mistake", self, "_on_ComparisonSort_mistake")
28+
self.connect("done", self, "_on_ComparisonSort_done")
2729

2830
func _input(event):
2931
"""Pass input events for checking and take appropriate action."""
30-
if not active or array.is_sorted():
32+
if _done or not active:
3133
return
3234
if event.is_pressed():
3335
return next(event.as_text())
@@ -37,13 +39,16 @@ func next(action):
3739
push_error("NotImplementedError")
3840

3941
func get_effect(i):
40-
if array.is_sorted():
42+
if _done:
4143
return EFFECTS.NONE
4244
return _get_effect(i)
4345

4446
func _get_effect(i):
4547
push_error("NotImplementedError")
4648

49+
func _on_ComparisonSort_done():
50+
_done = true
51+
4752
func _on_ComparisonSort_mistake():
4853
"""Disable the controls for one second."""
4954
active = false

scenes/end.tscn

Lines changed: 0 additions & 37 deletions
This file was deleted.

scenes/menu.tscn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ custom_constants/separation = 500
5858
margin_right = 50.0
5959
margin_bottom = 19.0
6060
size_flags_horizontal = 4
61-
text = "start"
61+
text = "START"
6262
flat = true
6363

6464
[node name="Credits" type="Button" parent="MainMenu/Buttons"]
6565
margin_left = 550.0
6666
margin_right = 620.0
6767
margin_bottom = 19.0
68-
text = "credits"
68+
text = "CREDITS"
6969

7070
[node name="Timer" type="Timer" parent="."]
7171
wait_time = 0.25

scenes/play.tscn

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,51 +19,51 @@ __meta__ = {
1919
[node name="GameDisplay" type="VBoxContainer" parent="."]
2020
margin_left = 30.0
2121
margin_top = 30.0
22-
margin_right = 1890.0
23-
margin_bottom = 1050.0
22+
margin_right = 1250.0
23+
margin_bottom = 690.0
2424
script = ExtResource( 1 )
2525

2626
[node name="HUDBorder" type="MarginContainer" parent="GameDisplay"]
27-
margin_right = 1860.0
28-
margin_bottom = 78.0
27+
margin_right = 1220.0
28+
margin_bottom = 59.0
2929
script = ExtResource( 3 )
3030

3131
[node name="HUD" type="HBoxContainer" parent="GameDisplay/HUDBorder"]
3232
margin_left = 20.0
3333
margin_top = 20.0
34-
margin_right = 1840.0
35-
margin_bottom = 58.0
34+
margin_right = 1200.0
35+
margin_bottom = 39.0
3636

3737
[node name="Level" type="Label" parent="GameDisplay/HUDBorder/HUD"]
38-
margin_right = 906.0
39-
margin_bottom = 38.0
38+
margin_right = 586.0
39+
margin_bottom = 19.0
4040
size_flags_horizontal = 3
4141
text = "LEVEL"
4242

4343
[node name="Score" type="Label" parent="GameDisplay/HUDBorder/HUD"]
44-
margin_left = 914.0
45-
margin_right = 1820.0
46-
margin_bottom = 38.0
44+
margin_left = 594.0
45+
margin_right = 1180.0
46+
margin_bottom = 19.0
4747
size_flags_horizontal = 3
4848
text = "0.000"
4949
align = 2
5050

5151
[node name="DisplayBorder" type="MarginContainer" parent="GameDisplay"]
52-
margin_top = 86.0
53-
margin_right = 1860.0
54-
margin_bottom = 1020.0
52+
margin_top = 67.0
53+
margin_right = 1220.0
54+
margin_bottom = 660.0
5555
size_flags_vertical = 3
5656
script = ExtResource( 3 )
5757

5858
[node name="Label" type="Label" parent="GameDisplay/DisplayBorder"]
5959
margin_left = 20.0
60-
margin_top = 448.0
61-
margin_right = 1840.0
62-
margin_bottom = 486.0
60+
margin_top = 287.0
61+
margin_right = 1200.0
62+
margin_bottom = 306.0
6363
text = "ready..."
6464
align = 1
6565

66-
[node name="Timer" type="Timer" parent="."]
66+
[node name="Timer" type="Timer" parent="GameDisplay"]
6767
one_shot = true
6868
autostart = true
69-
[connection signal="timeout" from="Timer" to="GameDisplay" method="_on_Timer_timeout"]
69+
[connection signal="timeout" from="GameDisplay/Timer" to="GameDisplay" method="_on_Timer_timeout"]

scripts/end.gd

Lines changed: 0 additions & 9 deletions
This file was deleted.

scripts/play.gd

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,27 @@ func get_score():
2020
return stepify((OS.get_ticks_msec() - _start_time) / 1000.0, 0.001)
2121

2222
func _on_Level_done():
23-
GlobalScene.change_scene("res://scenes/end.tscn",
24-
{"level": GlobalScene.get_param("level"), "score": get_score()})
23+
var restart = Button.new()
24+
restart.text = "RESTART LEVEL"
25+
restart.connect("pressed", self, "_on_Button_pressed", ["play"])
26+
var separator = Label.new()
27+
separator.text = " / "
28+
var back = Button.new()
29+
back.text = "BACK TO LEVEL SELECT"
30+
back.connect("pressed", self, "_on_Button_pressed", ["levels"])
31+
var result = Label.new()
32+
result.text = "%.3f" % get_score()
33+
result.size_flags_horizontal = Control.SIZE_EXPAND_FILL
34+
result.align = Label.ALIGN_RIGHT
35+
_start_time = -1
36+
$HUDBorder/HUD/Level.queue_free()
37+
$HUDBorder/HUD/Score.queue_free()
38+
$HUDBorder/HUD.add_child(restart)
39+
$HUDBorder/HUD.add_child(separator)
40+
$HUDBorder/HUD.add_child(back)
41+
$HUDBorder/HUD.add_child(result)
42+
restart.grab_focus()
43+
44+
func _on_Button_pressed(scene):
45+
GlobalScene.change_scene("res://scenes/" + scene + ".tscn",
46+
{"level": GlobalScene.get_param("level")})

0 commit comments

Comments
 (0)