Skip to content

Commit e5ddba7

Browse files
committed
feat: add selectable levels and previews
Added two more level names and their descriptions to test out if the game would handle multiple levels correctly. Also changed levels.json into a dict where the keys are level names and the value is another dict with its properties.
1 parent d20e322 commit e5ddba7

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

LevelSelect.gd

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
extends HBoxContainer
22

3+
var levels
4+
35
func _ready():
4-
var file = File.new()
5-
file.open("res://levels.json", file.READ)
6-
var levels = parse_json(file.get_as_text())
6+
var descriptions = File.new()
7+
descriptions.open("res://levels.json", descriptions.READ)
8+
levels = parse_json(descriptions.get_as_text())
9+
var first = true
710
for level in levels:
811
var button = Button.new()
9-
button.text = level.name
12+
button.text = level
1013
button.align = Button.ALIGN_LEFT
14+
button.connect("focus_entered", self, "_on_Button_focus_changed")
1115
$LevelsBorder/Levels.add_child(button)
12-
$PreviewBorder/Preview/Info.text = level.documentation
16+
if first:
17+
button.grab_focus()
18+
first = false
19+
20+
func _on_Button_focus_changed():
21+
$PreviewBorder/Preview/Info.text = levels[get_focus_owner().text]["about"]

MainMenu.gd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
extends VBoxContainer
22

3+
func _ready():
4+
$StartButton.grab_focus()
5+
36
func _on_StartButton_pressed():
47
get_tree().change_scene("res://LevelSelect.tscn")

levels.json

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1-
[
1+
{
2+
"BUBBLE SORT":
23
{
3-
"name": "BUBBLE SORT",
4-
"documentation": "Bubble sort is a simple sorting algorithm typically taught in introductory computer science classes. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla et iaculis neque. Vivamus pellentesque dictum rutrum."
4+
"about": "Bubble sort is a simple sorting algorithm, typically the first taught in introductory computer science classes."
5+
},
6+
"SELECTION SORT":
7+
{
8+
"about": "Why would you use selection sort when there's bubble sort and insertion sort..."
9+
},
10+
"INSERTION SORT":
11+
{
12+
"about": "Lorem ipsum sit dolor amet"
513
}
6-
]
14+
}

project.godot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ _global_script_class_icons={
1616
[application]
1717

1818
config/name="Human Computer Simulator"
19-
run/main_scene="res://MainMenu.tscn"
19+
run/main_scene="res://LevelSelect.tscn"
2020
run/low_processor_mode=true
2121
boot_splash/image="res://splash.png"
2222

0 commit comments

Comments
 (0)