Skip to content

Commit 12d5a23

Browse files
committed
feat: player can control preview size and speed
In addition, dynamically adjust the inter-block spacing depending on the amount of elements for aesthetics.
1 parent 5ed98b5 commit 12d5a23

File tree

4 files changed

+50
-9
lines changed

4 files changed

+50
-9
lines changed

project.godot

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ _global_script_class_icons={
6464

6565
config/name="Human Computer Simulator"
6666
run/main_scene="res://scenes/menu.tscn"
67-
run/low_processor_mode=true
6867
boot_splash/image="res://assets/splash.png"
6968
config/icon="res://assets/icon.png"
7069

@@ -124,6 +123,26 @@ ui_down={
124123
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
125124
]
126125
}
126+
faster={
127+
"deadzone": 0.5,
128+
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":46,"unicode":0,"echo":false,"script":null)
129+
]
130+
}
131+
slower={
132+
"deadzone": 0.5,
133+
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":44,"unicode":0,"echo":false,"script":null)
134+
]
135+
}
136+
bigger={
137+
"deadzone": 0.5,
138+
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":61,"unicode":0,"echo":false,"script":null)
139+
]
140+
}
141+
smaller={
142+
"deadzone": 0.5,
143+
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":45,"unicode":0,"echo":false,"script":null)
144+
]
145+
}
127146

128147
[rendering]
129148

scenes/levels.tscn

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ margin_top = 20.0
3535
margin_right = 283.0
3636
margin_bottom = 640.0
3737

38+
[node name="Label" type="Label" parent="LevelSelect/LevelsBorder"]
39+
margin_left = 20.0
40+
margin_top = 577.0
41+
margin_right = 283.0
42+
margin_bottom = 640.0
43+
size_flags_vertical = 8
44+
text = "Use +/- and </> to adjust the size and speed of the simulation, respectively."
45+
autowrap = true
46+
3847
[node name="Preview" type="VBoxContainer" parent="LevelSelect"]
3948
margin_left = 311.0
4049
margin_right = 1220.0
@@ -81,6 +90,6 @@ size_flags_vertical = 3
8190
text = "These are the controls for the level. They should be tailored to each level for maximum efficiency and simplicity."
8291
autowrap = true
8392

84-
[node name="Timer" type="Timer" parent="."]
93+
[node name="Timer" type="Timer" parent="LevelSelect"]
8594
autostart = true
86-
[connection signal="timeout" from="Timer" to="LevelSelect" method="_on_Timer_timeout"]
95+
[connection signal="timeout" from="LevelSelect/Timer" to="LevelSelect" method="_on_Timer_timeout"]

scripts/levels.gd

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ const LEVELS = [
66
SelectionSort,
77
MergeSort,
88
]
9-
var _level: ComparisonSort
9+
const MIN_SIZE = 8
10+
const MAX_SIZE = 256
11+
12+
var _level = LEVELS[0].new(ArrayModel.new())
1013

1114
func _ready():
1215
for level in LEVELS:
@@ -28,8 +31,8 @@ func _ready():
2831
if GlobalScene.get_param("level") == null:
2932
top_button.grab_focus()
3033

31-
func _on_Button_focus_changed():
32-
_level = _get_level(get_focus_owner().text).new(ArrayModel.new())
34+
func _on_Button_focus_changed(model=ArrayModel.new(_level.array.size)):
35+
_level = _get_level(get_focus_owner().text).new(model)
3336
_level.active = false
3437
$Preview/InfoBorder/Info/About.text = _cleanup(_level.ABOUT)
3538
$Preview/InfoBorder/Info/Controls.text = _cleanup(_level.CONTROLS)
@@ -40,6 +43,16 @@ func _on_Button_focus_changed():
4043
child.queue_free()
4144
$Preview/Display.add_child(ArrayView.new(_level))
4245

46+
func _input(event):
47+
if event.is_action_pressed("faster"):
48+
$Timer.wait_time /= 2
49+
elif event.is_action_pressed("slower"):
50+
$Timer.wait_time *= 2
51+
elif event.is_action_pressed("bigger"):
52+
_on_Button_focus_changed(ArrayModel.new(min(MAX_SIZE, _level.array.size * 2)))
53+
elif event.is_action_pressed("smaller"):
54+
_on_Button_focus_changed(ArrayModel.new(max(MIN_SIZE, _level.array.size / 2)))
55+
4356
func _on_Button_pressed(name):
4457
GlobalScene.change_scene("res://scenes/play.tscn", {"level": _get_level(name)})
4558

views/array_view.gd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ class_name ArrayView
66
extends HBoxContainer
77

88
const SWAP_DURATION = 0.1
9-
const SEPARATION = 8
109

1110
var _tween = Tween.new()
1211
var _level: ComparisonSort
1312
var _rects = []
1413
var _unit_width: int
1514
var _unit_height: int
15+
onready var _separation = 128 / _level.array.size
1616

1717
func _init(level):
1818
_level = level
@@ -29,8 +29,8 @@ func _ready():
2929
rect.polygon = [
3030
Vector2(0, 0),
3131
Vector2(0, rect_size.y),
32-
Vector2(_unit_width - SEPARATION, rect_size.y),
33-
Vector2(_unit_width - SEPARATION, 0),
32+
Vector2(_unit_width - _separation, rect_size.y),
33+
Vector2(_unit_width - _separation, 0),
3434
]
3535
rect.position = Vector2(i * _unit_width, rect_size.y)
3636
_rects.append(rect)

0 commit comments

Comments
 (0)