Skip to content

Commit

Permalink
fix: levelup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
akorzunin committed Aug 26, 2024
1 parent b728121 commit 5acb39a
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 31 deletions.
11 changes: 11 additions & 0 deletions src/components/GameProgress.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,25 @@ class_name GameProgress
@onready var loop_timer: LoopTimer = %LoopTimer
@onready var debug_stats_container: DebugStatsContainer = %DebugStatsContainer
@onready var gui: LoopGui = $'../Gui'
@onready var pattern_gen: PatternGen = %PatternGen

var figures_passed := 0
var time_passed := 0.
var time_passed_formated: String:
get:
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):
G.level_changed.emit(pattern_gen.level + 1)

func reset():
figures_passed = 0
Expand All @@ -39,6 +49,7 @@ func _on_game_state(old_state: GameStateManager.GameState, new_state: GameStateM
func _physics_process(delta: float) -> void:
debug_stats_container.nodes_passed.label_text = str(figures_passed)
debug_stats_container.time_passed.label_text = loop_timer.get_elapsed_time()
debug_stats_container.current_level.label_text = str(pattern_gen.level)
gui.game_state_label.set_text(str(figures_passed))

func get_score():
Expand Down
1 change: 1 addition & 0 deletions src/components/gui/DebugStatsContainer.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class_name DebugStatsContainer
@onready var angle: Label = $VBoxContainer/Angle
@onready var nodes_passed: DebugLabel = $VBoxContainer/NodesPassed
@onready var time_passed: DebugLabel = $VBoxContainer/TimePassed
@onready var current_level: DebugLabel = $VBoxContainer/CurrentLevel

var width_percent := 20

Expand Down
6 changes: 6 additions & 0 deletions src/components/gui/DebugStatsContainer.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ label_text = "0"
type = 8
regular_update = true

[node name="CurrentLevel" type="Label" parent="VBoxContainer"]
layout_mode = 2
text = ": 0"
script = ExtResource("3_ows3h")
label_text = "0"

[node name="DebugStatsTimer" type="Timer" parent="."]
unique_name_in_owner = true
autostart = true
38 changes: 15 additions & 23 deletions src/components/level_system/PatternGen.gd
Original file line number Diff line number Diff line change
@@ -1,45 +1,37 @@
extends Node
class_name PatternGen

var level_queue := LevelQueue.new()

const MAX_LEVEL := 10

enum SpawnMode {TUTORIAL, DEBUG, QUEUE}

@export var level := 0:
@export var level: int = G.settings.DEFAULT_LEVEL:
set(val):
level = clamp(0, MAX_LEVEL, val)

var level_queue := LevelQueue.new()

func _ready():
G.level_changed.connect(_on_level_changed)
add_patterns()

func upgrade_level():
level += 1

func downgrade_level():
level -= 1
func _on_level_changed(new_level: int):
level = new_level

func next_pattern() -> int:
if level_queue.length <= 0:
add_patterns()
return level_queue.next_item()


func add_patterns():
var current_level: Dictionary = LevelPatterns.levels[level]
if current_level.get("random"):
var p: int = current_level.level_patterns.pick_random()
for i in LevelPatterns.patterns[p]:
level_queue.add_item(i)
else:
for pattern in current_level.level_patterns:
for type in LevelPatterns.patterns[pattern]:
level_queue.add_item(type)

func update_patterns_based_on_level():
# Clear the queue to avoid mixing patterns from different levels
level_queue.items_queue.clear()
# Add patterns corresponding to the current level
add_patterns()
var random_pattern: int = current_level.level_patterns.pick_random()
queue_pattern(random_pattern)
return

for pattern in current_level.level_patterns:
queue_pattern(pattern)

func queue_pattern(pattern: int):
for type in LevelPatterns.patterns[pattern]:
level_queue.add_item(type)
2 changes: 2 additions & 0 deletions src/components/settings/DefaultConfig.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const settings = {
DESPAWNER_MODE=16633,
SCALE_FACTOR=10,
ROTATION_SPEED=12,
MAX_LEVEL=0,
},
user_settings = {
FPS_COUNTER_ENABLED=true,
Expand All @@ -17,5 +18,6 @@ const settings = {
VSYNC_ENABLED=true,
CONTROL_TYPE="FREE_SPIN",
IS_CONTROL_INVERTED=false,
DEFAULT_LEVEL=0,
}
}
13 changes: 6 additions & 7 deletions src/components/spawners/LoopSpawner.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class_name LoopSpawner
@onready var loop_timer: LoopTimer = %LoopTimer
@onready var scale_timer: ScaleTimer = %ScaleTimer
@onready var game_progress: GameProgress = %GameProgress
@onready var pattern_gen: PatternGen = %PatternGen

@export var figureRoot: FigureRoot

Expand Down Expand Up @@ -69,16 +70,14 @@ enum FigureType {ICOSAHEDRON, OCTAHEDRON}
enum SpawnMode {CENTER, SIDE, RANDOM, QUEUE}

func get_spawn_type():
var s = SpawnMode
var s = PatternGen.SpawnMode
match G.settings.SPAWN_MODE:
s.CENTER: # 0
s.TUTORIAL: # 0
return 3
s.SIDE: # 1
s.DEBUG: # 1
return 1
s.RANDOM: # 2
return randi_range(0, 19)
s.QUEUE: # 3
pass
s.QUEUE: # 2
return pattern_gen.next_pattern()

func spawn_figure(figure: Figure) -> void:
var new_figure
Expand Down
3 changes: 3 additions & 0 deletions src/globals.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ var settings := {}
enum FontType {HEX, EMOJI}
@warning_ignore("unused_signal")
signal font_changed(new_font: FontType)

@warning_ignore("unused_signal")
signal level_changed(new_level: int)
7 changes: 6 additions & 1 deletion src/scenes/LoopScene.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=34 format=3 uid="uid://dhbnayqnukkof"]
[gd_scene load_steps=35 format=3 uid="uid://dhbnayqnukkof"]

[ext_resource type="Script" path="res://src/scenes/init/LoopScene.gd" id="1_rcesrc"]
[ext_resource type="Shader" path="res://src/shaders/LoopSceneSky.gdshader" id="1_xr744"]
Expand Down Expand Up @@ -26,6 +26,7 @@
[ext_resource type="Texture2D" uid="uid://dho54u5o0pgkt" path="res://assets/build/textures/1x/LoopGuiTileInv.png" id="14_xcs0c"]
[ext_resource type="Script" path="res://src/components/settings/Config.gd" id="18_tjx6c"]
[ext_resource type="Script" path="res://src/components/GameProgress.gd" id="19_mtejl"]
[ext_resource type="Script" path="res://src/components/level_system/PatternGen.gd" id="27_sueui"]

[sub_resource type="ShaderMaterial" id="ShaderMaterial_kgifq"]
shader = ExtResource("1_xr744")
Expand Down Expand Up @@ -258,3 +259,7 @@ script = ExtResource("18_tjx6c")
[node name="GameProgress" type="Node" parent="."]
unique_name_in_owner = true
script = ExtResource("19_mtejl")

[node name="PatternGen" type="Node" parent="."]
unique_name_in_owner = true
script = ExtResource("27_sueui")

0 comments on commit 5acb39a

Please sign in to comment.