From 16bd8317c1f52b02f75020fc00da75a751d8334c Mon Sep 17 00:00:00 2001 From: akorzunin Date: Fri, 13 Sep 2024 15:40:40 +0300 Subject: [PATCH] feat: added level select UI --- src/components/EndRay.gd | 2 +- src/components/GameProgress.gd | 7 +--- src/components/controls/MenuControls.gd | 11 +++++ src/components/gui/menu/MenuActions.gd | 4 ++ src/components/gui/menu/MenuStruct.gd | 4 +- src/components/level_system/LevelPatterns.gd | 44 ++++++++++++++++++-- src/components/level_system/PatternGen.gd | 9 +++- 7 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/components/EndRay.gd b/src/components/EndRay.gd index e1c5ce2..d923aa2 100644 --- a/src/components/EndRay.gd +++ b/src/components/EndRay.gd @@ -41,7 +41,7 @@ enum AngleType {ANGLE_WRONG, ANGLE_OK, ANGLE_GOOD} func check_angle(v: Vector3) -> AngleType: var a = AngleType - if pass_vec.angle_to(v) < 0.2: + if pass_vec.angle_to(v) < 0.22: return a.ANGLE_GOOD if pass_vec.angle_to(v) < 0.5: return a.ANGLE_OK diff --git a/src/components/GameProgress.gd b/src/components/GameProgress.gd index 5e4fd60..015926c 100644 --- a/src/components/GameProgress.gd +++ b/src/components/GameProgress.gd @@ -14,15 +14,10 @@ var time_passed_formated: String: return loop_timer.get_elapsed_time() var max_reached_level := 0 -static func is_level_up(nodes: int, level: int) -> bool: - match level: - 0: return nodes > 10 - #1: return nodes > 20 - _: return false func add_one(): figures_passed += 1 - if is_level_up(figures_passed, pattern_gen.level): + if LevelPatterns.is_level_up(figures_passed, pattern_gen.level): G.level_changed.emit(pattern_gen.level + 1) func reset(): diff --git a/src/components/controls/MenuControls.gd b/src/components/controls/MenuControls.gd index 715b922..7606f02 100644 --- a/src/components/controls/MenuControls.gd +++ b/src/components/controls/MenuControls.gd @@ -29,6 +29,9 @@ func get_controlled_node() -> Node3D: return menuSpawner.get_node("Anchor") return null + + + ## Get selected menu intem and execute action that item meant to do func call_menu_action(): var selected = menu_selector.get_selected_item() @@ -37,8 +40,16 @@ func call_menu_action(): var action = selected.get("action") if action == "menu_start_game": sfx_player.on_action_select.emit() + G.data.level = selected.items.level else: sfx_player.on_section_select.emit() + if action == "menu_level_select": + menuSpawner.open_menu_section( + controlledNode, + {items = LevelPatterns.get_menu_levels(G.settings.MAX_LEVEL)} + ) + return + if action != "placeholder_action": actions.call(selected.action) return diff --git a/src/components/gui/menu/MenuActions.gd b/src/components/gui/menu/MenuActions.gd index e3f0ed6..0b2abb0 100644 --- a/src/components/gui/menu/MenuActions.gd +++ b/src/components/gui/menu/MenuActions.gd @@ -15,6 +15,10 @@ func menu_start_game(): return Utils.set_scene(self, 'LoopScene') +func menu_level_select(): + # handeled in MenuControls.call_menu_action + return + func settings_fps_counter_on(): config.set_fps_counter_state.emit(true) diff --git a/src/components/gui/menu/MenuStruct.gd b/src/components/gui/menu/MenuStruct.gd index b5a3907..74906e3 100644 --- a/src/components/gui/menu/MenuStruct.gd +++ b/src/components/gui/menu/MenuStruct.gd @@ -135,7 +135,7 @@ static var menu_items := { items = { 1: { name = "start", - action = "menu_start_game", + action = "menu_level_select", }, 2: { name = "settings", @@ -165,7 +165,7 @@ static var menu_items_emoji := { items = { 1: { 'name': "🎮", - 'action': "menu_start_game", + 'action': "menu_level_select", }, 2: { 'name': "⚙️", diff --git a/src/components/level_system/LevelPatterns.gd b/src/components/level_system/LevelPatterns.gd index eae1387..76f6855 100644 --- a/src/components/level_system/LevelPatterns.gd +++ b/src/components/level_system/LevelPatterns.gd @@ -5,8 +5,14 @@ const patterns: Dictionary = { 0: [19, 18], 1: [17, 18], 2: [19, 17], - 3: [17, 17, 17], - 4: [19, 19], + # level 1 + 3: [17, 19, 14], # 1 motion + 4: [2, 3], # 2 simple motions + 5: [13, 7], # 2 motions + # level 2 + 6: [15, 1, 2], + 7: [12, 8], + 8: [6, 16], } const levels: Dictionary = { @@ -15,7 +21,39 @@ const levels: Dictionary = { random = false, }, 1: { - level_patterns = [3, 4], + level_patterns = [3, 4, 5], random = true, + # game_speed = 20, + }, + 2: { + level_patterns = [6, 7, 8], + random = true, + # game_speed = 10, } } + +static func is_level_up(nodes: int, level: int) -> bool: + match level: + 0: return nodes > 10 + 1: return nodes > 20 + _: return false + +const tutorial_item := { + name = "tutorial", + action = "menu_start_game", + level = 0, +} + +static func get_menu_levels(max_level: int): + if max_level == 0: + return {1: tutorial_item } + var menu_entries = {} + for i in range(max_level, 0, -1): + menu_entries[max_level - i + 1] = { + name = "level %s" % i, + action = "menu_start_game", + level = i, + } + menu_entries[6] = tutorial_item + + return menu_entries diff --git a/src/components/level_system/PatternGen.gd b/src/components/level_system/PatternGen.gd index cbc4d24..6a2420a 100644 --- a/src/components/level_system/PatternGen.gd +++ b/src/components/level_system/PatternGen.gd @@ -4,7 +4,7 @@ class_name PatternGen const MAX_LEVEL := 10 enum SpawnMode {TUTORIAL, DEBUG, QUEUE} -@export var level: int = G.settings.DEFAULT_LEVEL: +@export var level: int = 0: set(val): level = clamp(0, MAX_LEVEL, val) @@ -12,9 +12,16 @@ var level_queue := LevelQueue.new() func _ready(): G.level_changed.connect(_on_level_changed) + var l = G.data.get("level") + if l: + level = l add_patterns() func _on_level_changed(new_level: int): + var new_gs = LevelPatterns.levels[new_level].get("game_speed") + if new_gs: + G.settings.GAME_SPEED = new_gs + G.reload_settings.emit() level = new_level func next_pattern() -> int: