File tree Expand file tree Collapse file tree 6 files changed +74
-14
lines changed Expand file tree Collapse file tree 6 files changed +74
-14
lines changed Original file line number Diff line number Diff line change 1+ """
2+ A plain old one-dimensional random access array.
3+ """
4+
5+ extends Reference
6+ class_name ArrayModel
7+
8+ var array = []
9+ var size
10+
11+ func _init (size ):
12+ for i in range (1 , size + 1 ):
13+ array .append (Element .new (i ))
14+ array .shuffle ()
15+ self .size = size
16+
17+ func get (index ):
18+ return array [index ]
19+
20+ class Element :
21+ var value
22+ var emphasized
23+
24+ func _init (value ):
25+ self .value = value
26+ self .emphasized = false
Original file line number Diff line number Diff line change 88
99config_version =4
1010
11- _global_script_classes =[ ]
11+ _global_script_classes =[ {
12+ "base" : "Reference" ,
13+ "class" : "ArrayModel" ,
14+ "language" : "GDScript" ,
15+ "path" : "res://models/array_model.gd"
16+ }, {
17+ "base" : "HBoxContainer" ,
18+ "class" : "ArrayView" ,
19+ "language" : "GDScript" ,
20+ "path" : "res://views/array_view.gd"
21+ } ]
1222_global_script_class_icons ={
13-
23+ "ArrayModel" : "" ,
24+ "ArrayView" : ""
1425}
1526
1627[application ]
Original file line number Diff line number Diff line change @@ -55,12 +55,6 @@ margin_bottom = 1020.0
5555size_flags_vertical = 3
5656script = ExtResource ( 3 )
5757
58- [node name ="Display" type ="Control" parent ="PlayingScreen/DisplayBorder" ]
59- margin_left = 20.0
60- margin_top = 20.0
61- margin_right = 1840.0
62- margin_bottom = 914.0
63-
6458[node name ="Timer" type ="Timer" parent ="." ]
6559one_shot = true
6660autostart = true
Original file line number Diff line number Diff line change @@ -3,20 +3,26 @@ extends VBoxContainer
33var start_time = - 1
44
55func _ready ():
6+ $ HUDBorder/HUD/Level .text = scene .get_param ("level" )
7+ # Show ready text
68 var label = Label .new ()
79 label .text = "ready..."
810 label .align = Label .ALIGN_CENTER
911 label .set_anchors_preset (Control .PRESET_HCENTER_WIDE )
10- $ DisplayBorder/Display .add_child (label )
11- $ HUDBorder/HUD/Level .text = scene .get_param ("level" )
12- match scene .get_param ("level" ):
13- "BUBBLE SORT" :
14- pass
12+ $ DisplayBorder .add_child (label )
1513
1614func _process (delta ):
15+ # Show elapsed time in milliseconds
1716 var elapsed_time = stepify ((OS .get_ticks_msec () - start_time ) / 1000.0 , 0.001 )
1817 $ HUDBorder/HUD/Score .text = "0.000" if start_time == - 1 else "%.3f " % elapsed_time
1918
2019func _on_Timer_timeout ():
21- $ DisplayBorder/Display .get_child (0 ).queue_free ()
2220 start_time = OS .get_ticks_msec ()
21+ # Delete ready text
22+ $ DisplayBorder .get_child (0 ).queue_free ()
23+ # Load level
24+ var array = ArrayModel .new (10 )
25+ match scene .get_param ("level" ):
26+ "BUBBLE SORT" :
27+ pass
28+ $ DisplayBorder .add_child (ArrayView .new (array ))
Original file line number Diff line number Diff line change 1+ extends HBoxContainer
2+ class_name ArrayView
3+
4+ const GREEN = Color (0.2 , 1 , 0.2 )
5+ const ORANGE = Color (1 , 0.69 , 0 )
6+
7+ var model : ArrayModel
8+ var rects = []
9+
10+ func _init (model ):
11+ self .model = model
12+ for i in range (model .size ):
13+ var rect = ColorRect .new ()
14+ rect .size_flags_horizontal = Control .SIZE_EXPAND_FILL
15+ rect .size_flags_vertical = Control .SIZE_SHRINK_END
16+ rect .color = GREEN
17+ rects .append (rect )
18+ add_child (rect )
19+
20+ func _draw ():
21+ for i in range (model .size ):
22+ rects [i ].rect_scale .y = - 1 # Override parent Control scale
23+ rects [i ].rect_size .y = rect_size .y * model .get (i ).value / model .size
You can’t perform that action at this time.
0 commit comments