Skip to content

Commit 84d78ef

Browse files
committed
feat: nerf bubble sort and add dimming effects
The player no longer has to go through the sorted end in bubble sort, which is now dimmed. The sorted subarrays of insertion sort and selection sort are dimmed too.
1 parent 5cb9c76 commit 84d78ef

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

levels/bubble_sort.gd

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ them. Otherwise, hit RIGHT ARROW to continue.
1515
"""
1616

1717
var _index = 0
18+
var _end = array.size
1819
var _swapped = false
1920

2021
func _init(array).(array):
@@ -31,13 +32,16 @@ func next():
3132
array.swap(_index, _index + 1)
3233
_swapped = true
3334
_index += 1
34-
if _index == array.size - 1:
35+
if _index + 1 == _end:
3536
if not _swapped:
3637
emit_signal("done")
3738
_index = 0
39+
_end -= 1
3840
_swapped = false
3941

4042
func get_effect(i):
43+
if i >= _end:
44+
return EFFECTS.DIMMED
4145
if i == _index or i == _index + 1:
4246
return EFFECTS.HIGHLIGHTED
4347
return EFFECTS.NONE

levels/insertion_sort.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func next():
3939
func get_effect(i):
4040
if i == _index or i == _index - 1:
4141
return EFFECTS.HIGHLIGHTED
42+
if i < _end:
43+
return EFFECTS.DIMMED
4244
return EFFECTS.NONE
4345

4446
func _grow():

levels/selection_sort.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,6 @@ func next():
4040
func get_effect(i):
4141
if i == _index or i == _base:
4242
return EFFECTS.HIGHLIGHTED
43+
if i <= _base:
44+
return EFFECTS.DIMMED
4345
return EFFECTS.NONE

0 commit comments

Comments
 (0)