feat: moved minigames to their separate context
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -8,6 +8,7 @@ local DEFAULT_CONFIG = {
|
||||
light_grey = 13,
|
||||
dark_grey = 14,
|
||||
green = 6,
|
||||
blue = 9,
|
||||
item = 12
|
||||
},
|
||||
player = {
|
||||
|
||||
107
inc/init/init.minigames.lua
Normal file
107
inc/init/init.minigames.lua
Normal file
@@ -0,0 +1,107 @@
|
||||
Minigames = {}
|
||||
|
||||
local function apply_params(defaults, params)
|
||||
if not params then return defaults end
|
||||
for k, v in pairs(params) do
|
||||
defaults[k] = v
|
||||
end
|
||||
return defaults
|
||||
end
|
||||
|
||||
function Minigames.get_default_ddr()
|
||||
local arrow_size = 12
|
||||
local arrow_spacing = 30
|
||||
local total_width = (4 * arrow_size) + (3 * arrow_spacing)
|
||||
local start_x = (Config.screen.width - total_width) / 2
|
||||
return {
|
||||
bar_fill = 0,
|
||||
max_fill = 100,
|
||||
fill_per_hit = 10,
|
||||
miss_penalty = 5,
|
||||
bar_x = 20,
|
||||
bar_y = 10,
|
||||
bar_width = 200,
|
||||
bar_height = 12,
|
||||
arrow_size = arrow_size,
|
||||
arrow_spawn_timer = 0,
|
||||
arrow_spawn_interval = 45,
|
||||
arrow_fall_speed = 1.5,
|
||||
arrows = {},
|
||||
target_y = 115,
|
||||
target_arrows = {
|
||||
{ dir = "left", x = start_x },
|
||||
{ dir = "down", x = start_x + arrow_size + arrow_spacing },
|
||||
{ dir = "up", x = start_x + (arrow_size + arrow_spacing) * 2 },
|
||||
{ dir = "right", x = start_x + (arrow_size + arrow_spacing) * 3 }
|
||||
},
|
||||
hit_threshold = 8,
|
||||
button_pressed_timers = {},
|
||||
button_press_duration = 8,
|
||||
input_cooldowns = { left = 0, down = 0, up = 0, right = 0 },
|
||||
input_cooldown_duration = 10,
|
||||
frame_counter = 0,
|
||||
current_song = nil,
|
||||
pattern_index = 1,
|
||||
use_pattern = false,
|
||||
return_window = nil
|
||||
}
|
||||
end
|
||||
|
||||
function Minigames.get_default_button_mash()
|
||||
return {
|
||||
bar_fill = 0,
|
||||
max_fill = 100,
|
||||
fill_per_press = 8,
|
||||
base_degradation = 0.15,
|
||||
degradation_multiplier = 0.006,
|
||||
button_pressed_timer = 0,
|
||||
button_press_duration = 8,
|
||||
return_window = nil,
|
||||
bar_x = 20,
|
||||
bar_y = 10,
|
||||
bar_width = 200,
|
||||
bar_height = 12,
|
||||
button_x = 20,
|
||||
button_y = 110,
|
||||
button_size = 12
|
||||
}
|
||||
end
|
||||
|
||||
function Minigames.get_default_rhythm()
|
||||
return {
|
||||
line_position = 0,
|
||||
line_speed = 0.015,
|
||||
line_direction = 1,
|
||||
target_center = 0.5,
|
||||
target_width = 0.3,
|
||||
initial_target_width = 0.3,
|
||||
min_target_width = 0.08,
|
||||
target_shrink_rate = 0.9,
|
||||
score = 0,
|
||||
max_score = 10,
|
||||
button_pressed_timer = 0,
|
||||
button_press_duration = 10,
|
||||
return_window = nil,
|
||||
bar_x = 20,
|
||||
bar_y = 10,
|
||||
bar_width = 200,
|
||||
bar_height = 12,
|
||||
button_x = 210,
|
||||
button_y = 110,
|
||||
button_size = 10,
|
||||
press_cooldown = 0,
|
||||
press_cooldown_duration = 15
|
||||
}
|
||||
end
|
||||
|
||||
function Minigames.configure_ddr(params)
|
||||
return apply_params(Minigames.get_default_ddr(), params)
|
||||
end
|
||||
|
||||
function Minigames.configure_button_mash(params)
|
||||
return apply_params(Minigames.get_default_button_mash(), params)
|
||||
end
|
||||
|
||||
function Minigames.configure_rhythm(params)
|
||||
return apply_params(Minigames.get_default_rhythm(), params)
|
||||
end
|
||||
@@ -1,56 +1,9 @@
|
||||
function MinigameDDRWindow.init()
|
||||
-- Calculate evenly spaced arrow positions
|
||||
local arrow_size = 12
|
||||
local arrow_spacing = 30
|
||||
local total_width = (4 * arrow_size) + (3 * arrow_spacing)
|
||||
local start_x = (Config.screen.width - total_width) / 2
|
||||
Context.minigame_ddr = {
|
||||
-- Progress bar (matching button mash style)
|
||||
bar_fill = 0, -- 0 to 100
|
||||
max_fill = 100,
|
||||
fill_per_hit = 10, -- Points gained per perfect hit
|
||||
miss_penalty = 5, -- Points lost per miss
|
||||
bar_x = 20,
|
||||
bar_y = 10,
|
||||
bar_width = 200,
|
||||
bar_height = 12,
|
||||
-- Arrow settings
|
||||
arrow_size = arrow_size,
|
||||
arrow_spawn_timer = 0,
|
||||
arrow_spawn_interval = 45, -- Frames between arrow spawns (for random mode)
|
||||
arrow_fall_speed = 1.5, -- Pixels per frame
|
||||
arrows = {}, -- Active falling arrows {dir, x, y}
|
||||
-- Target arrows at bottom (evenly spaced, centered on screen)
|
||||
target_y = 115, -- Y position of target arrows
|
||||
target_arrows = {
|
||||
{dir = "left", x = start_x},
|
||||
{dir = "down", x = start_x + arrow_size + arrow_spacing},
|
||||
{dir = "up", x = start_x + (arrow_size + arrow_spacing) * 2},
|
||||
{dir = "right", x = start_x + (arrow_size + arrow_spacing) * 3}
|
||||
},
|
||||
-- Hit detection
|
||||
hit_threshold = 8, -- Pixels of tolerance for perfect hit
|
||||
button_pressed_timers = {}, -- Visual feedback per arrow
|
||||
button_press_duration = 8,
|
||||
-- Input cooldown per direction
|
||||
input_cooldowns = {
|
||||
left = 0,
|
||||
down = 0,
|
||||
up = 0,
|
||||
right = 0
|
||||
},
|
||||
input_cooldown_duration = 10,
|
||||
-- Song/Pattern system
|
||||
frame_counter = 0, -- Tracks frames since start
|
||||
current_song = nil, -- Current song data
|
||||
pattern_index = 1, -- Current position in pattern
|
||||
use_pattern = false, -- If true, use song pattern; if false, use random spawning
|
||||
return_window = WINDOW_GAME
|
||||
}
|
||||
function MinigameDDRWindow.init(params)
|
||||
Context.minigame_ddr = Minigames.configure_ddr(params)
|
||||
end
|
||||
|
||||
function MinigameDDRWindow.start(return_window, song_key)
|
||||
MinigameDDRWindow.init()
|
||||
function MinigameDDRWindow.start(return_window, song_key, params)
|
||||
MinigameDDRWindow.init(params)
|
||||
Context.minigame_ddr.return_window = return_window or WINDOW_GAME
|
||||
-- Debug: Store song_key for display
|
||||
Context.minigame_ddr.debug_song_key = song_key
|
||||
@@ -273,7 +226,7 @@ function MinigameDDRWindow.draw()
|
||||
if mg.bar_fill > 66 then
|
||||
bar_color = Config.colors.item -- yellow
|
||||
elseif mg.bar_fill > 33 then
|
||||
bar_color = Config.colors.bar
|
||||
bar_color = Config.colors.blue
|
||||
end
|
||||
rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color)
|
||||
end
|
||||
@@ -291,7 +244,7 @@ function MinigameDDRWindow.draw()
|
||||
-- Draw falling arrows (blue)
|
||||
if mg.arrows then
|
||||
for _, arrow in ipairs(mg.arrows) do
|
||||
draw_arrow(arrow.x, arrow.y, arrow.dir, Config.colors.bar) -- blue color
|
||||
draw_arrow(arrow.x, arrow.y, arrow.dir, Config.colors.blue) -- blue color
|
||||
end
|
||||
end
|
||||
-- Draw instruction text
|
||||
@@ -318,6 +271,6 @@ function MinigameDDRWindow.draw()
|
||||
)
|
||||
end
|
||||
else
|
||||
Print.text_center("RANDOM MODE", Config.screen.width / 2, debug_y, Config.colors.bar)
|
||||
Print.text_center("RANDOM MODE", Config.screen.width / 2, debug_y, Config.colors.blue)
|
||||
end
|
||||
end
|
||||
@@ -1,25 +1,9 @@
|
||||
function MinigameButtonMashWindow.init()
|
||||
Context.minigame_button_mash = {
|
||||
bar_fill = 0, -- 0 to 100
|
||||
max_fill = 100,
|
||||
fill_per_press = 8,
|
||||
base_degradation = 0.15, -- Base degradation per frame
|
||||
degradation_multiplier = 0.006, -- Increases with bar fill
|
||||
button_pressed_timer = 0, -- Visual feedback timer
|
||||
button_press_duration = 8, -- Frames to show button press
|
||||
return_window = WINDOW_GAME, -- Window to return to after completion
|
||||
bar_x = 20,
|
||||
bar_y = 10,
|
||||
bar_width = 200,
|
||||
bar_height = 12,
|
||||
button_x = 20,
|
||||
button_y = 110,
|
||||
button_size = 12
|
||||
}
|
||||
function MinigameButtonMashWindow.init(params)
|
||||
Context.minigame_button_mash = Minigames.configure_button_mash(params)
|
||||
end
|
||||
|
||||
function MinigameButtonMashWindow.start(return_window)
|
||||
MinigameButtonMashWindow.init()
|
||||
function MinigameButtonMashWindow.start(return_window, params)
|
||||
MinigameButtonMashWindow.init(params)
|
||||
Context.minigame_button_mash.return_window = return_window or WINDOW_GAME
|
||||
Context.active_window = WINDOW_MINIGAME_BUTTON_MASH
|
||||
end
|
||||
@@ -73,7 +57,7 @@ function MinigameButtonMashWindow.draw()
|
||||
if mg.bar_fill > 66 then
|
||||
bar_color = Config.colors.item -- yellow
|
||||
elseif mg.bar_fill > 33 then
|
||||
bar_color = Config.colors.bar -- medium color
|
||||
bar_color = Config.colors.blue
|
||||
end
|
||||
rect(mg.bar_x, mg.bar_y, fill_width, bar_color)
|
||||
end
|
||||
|
||||
@@ -1,35 +1,9 @@
|
||||
function MinigameRhythmWindow.init()
|
||||
Context.minigame_rhythm = {
|
||||
line_position = 0, -- Normalized position (0 to 1)
|
||||
line_speed = 0.015, -- Movement speed per frame
|
||||
line_direction = 1, -- 1 for left-to-right, -1 for right-to-left
|
||||
target_center = 0.5, -- Center of target area (middle of bar)
|
||||
target_width = 0.3, -- Width of target area (normalized)
|
||||
initial_target_width = 0.3,
|
||||
min_target_width = 0.08, -- Minimum width to keep game possible
|
||||
target_shrink_rate = 0.9, -- Multiplier per successful hit (0.9 = 10% shrink)
|
||||
score = 0,
|
||||
max_score = 10,
|
||||
button_pressed_timer = 0,
|
||||
button_press_duration = 10,
|
||||
return_window = WINDOW_GAME,
|
||||
-- Visual layout (match button mash minigame dimensions)
|
||||
bar_x = 20,
|
||||
bar_y = 10,
|
||||
bar_width = 200,
|
||||
bar_height = 12,
|
||||
-- Button indicator
|
||||
button_x = 210,
|
||||
button_y = 110,
|
||||
button_size = 10,
|
||||
-- Cooldown to prevent multiple presses in one frame
|
||||
press_cooldown = 0,
|
||||
press_cooldown_duration = 15
|
||||
}
|
||||
function MinigameRhythmWindow.init(params)
|
||||
Context.minigame_rhythm = Minigames.configure_rhythm(params)
|
||||
end
|
||||
|
||||
function MinigameRhythmWindow.start(return_window)
|
||||
MinigameRhythmWindow.init()
|
||||
function MinigameRhythmWindow.start(return_window, params)
|
||||
MinigameRhythmWindow.init(params)
|
||||
Context.minigame_rhythm.return_window = return_window or WINDOW_GAME
|
||||
Context.active_window = WINDOW_MINIGAME_RHYTHM
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user