Skip to content

Commit 1818d6f

Browse files
committed
feat: add flashing red border when mistake is made
To aid the player with visual feedback, the main level display now flashes red three times to inform them of mistakes.
1 parent 4efbd6e commit 1818d6f

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

scenes/play.tscn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ margin_bottom = 1020.0
5555
size_flags_vertical = 3
5656
script = ExtResource( 3 )
5757

58+
[node name="Label" type="Label" parent="PlayingScreen/DisplayBorder"]
59+
margin_left = 20.0
60+
margin_top = 448.0
61+
margin_right = 1840.0
62+
margin_bottom = 486.0
63+
text = "ready..."
64+
align = 1
65+
5866
[node name="Timer" type="Timer" parent="."]
5967
one_shot = true
6068
autostart = true

scripts/border.gd

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
extends MarginContainer
22

3-
var GREEN = Color(0.2, 1, 0.2)
4-
var WIDTH = 5
3+
const GREEN = Color(0.2, 1, 0.2)
4+
const RED = Color(1, 0, 0)
5+
const WIDTH = 5
6+
var color = GREEN
7+
var timer = Timer.new()
8+
const FLASHES = 3
9+
var color_changes = 0
510

611
func _ready():
7-
pass
12+
# Input should be reenabled right after the last red flash
13+
timer.wait_time = 1.0 / (FLASHES * 2 - 1)
14+
timer.connect("timeout", self, "_on_Timer_timeout")
15+
add_child(timer)
16+
17+
func flash():
18+
_on_Timer_timeout()
19+
timer.start()
20+
21+
func _on_Timer_timeout():
22+
if color_changes == FLASHES * 2 - 1:
23+
timer.stop()
24+
color_changes = 0
25+
color = GREEN
26+
else:
27+
color = RED if color_changes % 2 == 0 else GREEN
28+
color_changes += 1
29+
update()
830

931
func _draw():
10-
draw_rect(Rect2(Vector2(), rect_size), GREEN, false, WIDTH)
32+
draw_rect(Rect2(Vector2(), rect_size), color, false, WIDTH)

scripts/play.gd

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@ var start_time = -1
44

55
func _ready():
66
$HUDBorder/HUD/Level.text = scene.get_param("level")
7-
# Show ready text
8-
var label = Label.new()
9-
label.text = "ready..."
10-
label.align = Label.ALIGN_CENTER
11-
$DisplayBorder.add_child(label)
127

138
func _process(delta):
149
# Show elapsed time in milliseconds
@@ -18,7 +13,7 @@ func _process(delta):
1813
func _on_Timer_timeout():
1914
start_time = OS.get_ticks_msec()
2015
# Delete ready text
21-
$DisplayBorder.get_child(0).queue_free()
16+
$DisplayBorder/Label.queue_free()
2217
# Load level
2318
var array = ArrayModel.new(10)
2419
var level = getLevel(scene.get_param("level")).new(array)

views/array_view.gd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ func _process(delta):
2525
rects[i].rect_size.y = rect_size.y * level.array.get(i) / level.array.size
2626

2727
func _on_Level_mistake():
28-
pass
28+
get_parent().flash()

0 commit comments

Comments
 (0)