Compare commits
4 Commits
9014e36014
...
feature-re
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a4565428d | |||
| f02bb75e4f | |||
|
|
e0c3b446af | ||
|
|
8832b6c833 |
@@ -3,13 +3,15 @@
|
|||||||
|
|
||||||
globals = {
|
globals = {
|
||||||
"Util",
|
"Util",
|
||||||
"DecisionManager",
|
"Decision",
|
||||||
"ScreenManager",
|
"Screen",
|
||||||
"UI",
|
"UI",
|
||||||
"Print",
|
"Print",
|
||||||
"Input",
|
"Input",
|
||||||
"Audio",
|
"Audio",
|
||||||
"Context",
|
"Context",
|
||||||
|
"Meters",
|
||||||
|
"Minigames",
|
||||||
"mset",
|
"mset",
|
||||||
"mget",
|
"mget",
|
||||||
"btnp",
|
"btnp",
|
||||||
@@ -30,7 +32,7 @@ globals = {
|
|||||||
"exit",
|
"exit",
|
||||||
"trace",
|
"trace",
|
||||||
"index_menu",
|
"index_menu",
|
||||||
"MapManager",
|
"Map",
|
||||||
"map",
|
"map",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
Makefile
1
Makefile
@@ -85,6 +85,7 @@ lint:
|
|||||||
@touch $(LINT_TMP_LUA)
|
@touch $(LINT_TMP_LUA)
|
||||||
@line=1; \
|
@line=1; \
|
||||||
while IFS= read -r f || [ -n "$$f" ]; do \
|
while IFS= read -r f || [ -n "$$f" ]; do \
|
||||||
|
f=$$(printf '%s' "$$f" | tr -d '\r'); \
|
||||||
[ -z "$$f" ] && continue; \
|
[ -z "$$f" ] && continue; \
|
||||||
before=$$(wc -l < $(LINT_TMP_LUA)); \
|
before=$$(wc -l < $(LINT_TMP_LUA)); \
|
||||||
cat "$(SRC_DIR)/$$f" >> $(LINT_TMP_LUA); \
|
cat "$(SRC_DIR)/$$f" >> $(LINT_TMP_LUA); \
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ meta/meta.header.lua
|
|||||||
init/init.modules.lua
|
init/init.modules.lua
|
||||||
init/init.config.lua
|
init/init.config.lua
|
||||||
init/init.minigames.lua
|
init/init.minigames.lua
|
||||||
|
init/init.meters.lua
|
||||||
system/system.util.lua
|
system/system.util.lua
|
||||||
init/init.windows.lua
|
init/init.windows.lua
|
||||||
decision/decision.manager.lua
|
decision/decision.manager.lua
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "go_to_home",
|
id = "go_to_home",
|
||||||
label = "Go to Home",
|
label = "Go to Home",
|
||||||
handle = function()
|
handle = function()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "go_to_office",
|
id = "go_to_office",
|
||||||
label = "Go to Office",
|
label = "Go to Office",
|
||||||
handle = function()
|
handle = function()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "go_to_toilet",
|
id = "go_to_toilet",
|
||||||
label = "Go to Toilet",
|
label = "Go to Toilet",
|
||||||
handle = function()
|
handle = function()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "go_to_walking_to_home",
|
id = "go_to_walking_to_home",
|
||||||
label = "Walking to home",
|
label = "Walking to home",
|
||||||
handle = function()
|
handle = function()
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "go_to_walking_to_office",
|
id = "go_to_walking_to_office",
|
||||||
label = "Walking to office",
|
label = "Walking to office",
|
||||||
handle = function()
|
handle = function()
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local _decisions = {}
|
local _decisions = {}
|
||||||
|
|
||||||
function DecisionManager.register(decision)
|
function Decision.register(decision)
|
||||||
if not decision or not decision.id then
|
if not decision or not decision.id then
|
||||||
PopupWindow.show({"Error: Invalid decision object registered (missing id)!"})
|
PopupWindow.show({"Error: Invalid decision object registered (missing id)!"})
|
||||||
return
|
return
|
||||||
@@ -22,10 +22,10 @@ function DecisionManager.register(decision)
|
|||||||
_decisions[decision.id] = decision
|
_decisions[decision.id] = decision
|
||||||
end
|
end
|
||||||
|
|
||||||
function DecisionManager.get(id)
|
function Decision.get(id)
|
||||||
return _decisions[id]
|
return _decisions[id]
|
||||||
end
|
end
|
||||||
|
|
||||||
function DecisionManager.get_all()
|
function Decision.get_all()
|
||||||
return _decisions
|
return _decisions
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "play_button_mash",
|
id = "play_button_mash",
|
||||||
label = "Play Button Mash",
|
label = "Play Button Mash",
|
||||||
handle = function() MinigameButtonMashWindow.start(WINDOW_GAME) end,
|
handle = function() Meters.hide() MinigameButtonMashWindow.start(WINDOW_GAME) end,
|
||||||
condition = function() return true end
|
condition = function() return true end
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "play_ddr",
|
id = "play_ddr",
|
||||||
label = "Play DDR (Random)",
|
label = "Play DDR (Random)",
|
||||||
handle = function() MinigameDDRWindow.start(WINDOW_GAME, nil) end,
|
handle = function() Meters.hide() MinigameDDRWindow.start(WINDOW_GAME, nil) end,
|
||||||
condition = function() return true end
|
condition = function() return true end
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
DecisionManager.register({
|
Decision.register({
|
||||||
id = "play_rhythm",
|
id = "play_rhythm",
|
||||||
label = "Play Rhythm Game",
|
label = "Play Rhythm Game",
|
||||||
handle = function() MinigameRhythmWindow.start(WINDOW_GAME) end,
|
handle = function() Meters.hide() MinigameRhythmWindow.start(WINDOW_GAME) end,
|
||||||
condition = function() return true end
|
condition = function() return true end
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -7,9 +7,12 @@ local DEFAULT_CONFIG = {
|
|||||||
black = 0,
|
black = 0,
|
||||||
light_grey = 13,
|
light_grey = 13,
|
||||||
dark_grey = 14,
|
dark_grey = 14,
|
||||||
|
red = 2,
|
||||||
green = 6,
|
green = 6,
|
||||||
blue = 9,
|
blue = 9,
|
||||||
item = 12
|
white = 12,
|
||||||
|
item = 12,
|
||||||
|
meter_bg = 12
|
||||||
},
|
},
|
||||||
player = {
|
player = {
|
||||||
sprite_id = 1
|
sprite_id = 1
|
||||||
|
|||||||
@@ -44,7 +44,8 @@ on than meets the eye.]]
|
|||||||
screens = {},
|
screens = {},
|
||||||
minigame_ddr = Minigames.get_default_ddr(),
|
minigame_ddr = Minigames.get_default_ddr(),
|
||||||
minigame_button_mash = Minigames.get_default_button_mash(),
|
minigame_button_mash = Minigames.get_default_button_mash(),
|
||||||
minigame_rhythm = Minigames.get_default_rhythm()
|
minigame_rhythm = Minigames.get_default_rhythm(),
|
||||||
|
meters = Meters.get_initial()
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ local function reset_context_to_initial_state()
|
|||||||
Context.screen_indices_by_id = {}
|
Context.screen_indices_by_id = {}
|
||||||
local screen_order = {"home", "toilet", "walking_to_office", "office", "walking_to_home"}
|
local screen_order = {"home", "toilet", "walking_to_office", "office", "walking_to_home"}
|
||||||
for i, screen_id in ipairs(screen_order) do
|
for i, screen_id in ipairs(screen_order) do
|
||||||
local screen_data = ScreenManager.get_by_id(screen_id)
|
local screen_data = Screen.get_by_id(screen_id)
|
||||||
if screen_data then
|
if screen_data then
|
||||||
table.insert(Context.screens, screen_data)
|
table.insert(Context.screens, screen_data)
|
||||||
Context.screen_indices_by_id[screen_id] = i
|
Context.screen_indices_by_id[screen_id] = i
|
||||||
|
|||||||
75
inc/init/init.meters.lua
Normal file
75
inc/init/init.meters.lua
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
local METER_MAX = 1000
|
||||||
|
local METER_DEFAULT = 500
|
||||||
|
local METER_DECAY_PER_FRAME = 0.02
|
||||||
|
local METER_GAIN_PER_CHORE = 100
|
||||||
|
local COMBO_BASE_BONUS = 0.02
|
||||||
|
local COMBO_MAX_BONUS = 0.16
|
||||||
|
local COMBO_TIMEOUT_FRAMES = 600
|
||||||
|
|
||||||
|
Meters.COLOR_ISM = Config.colors.red
|
||||||
|
Meters.COLOR_WPM = Config.colors.blue
|
||||||
|
Meters.COLOR_BM = Config.colors.black
|
||||||
|
Meters.COLOR_BG = Config.colors.meter_bg
|
||||||
|
|
||||||
|
function Meters.get_initial()
|
||||||
|
return {
|
||||||
|
ism = METER_DEFAULT,
|
||||||
|
wpm = METER_DEFAULT,
|
||||||
|
bm = METER_DEFAULT,
|
||||||
|
combo = 0,
|
||||||
|
combo_timer = 0,
|
||||||
|
hidden = false,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function Meters.hide()
|
||||||
|
if Context and Context.meters then Context.meters.hidden = true end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Meters.show()
|
||||||
|
if Context and Context.meters then Context.meters.hidden = false end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Meters.get_max()
|
||||||
|
return METER_MAX
|
||||||
|
end
|
||||||
|
|
||||||
|
function Meters.get_combo_multiplier()
|
||||||
|
if not Context or not Context.meters then return 1 end
|
||||||
|
local combo = Context.meters.combo
|
||||||
|
if combo == 0 then return 1 end
|
||||||
|
return 1 + math.min(COMBO_MAX_BONUS, COMBO_BASE_BONUS * (2 ^ (combo - 1)))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Meters.update()
|
||||||
|
if not Context or not Context.game_in_progress or not Context.meters then return end
|
||||||
|
local m = Context.meters
|
||||||
|
m.ism = math.max(0, m.ism - METER_DECAY_PER_FRAME)
|
||||||
|
m.wpm = math.max(0, m.wpm - METER_DECAY_PER_FRAME)
|
||||||
|
m.bm = math.max(0, m.bm - METER_DECAY_PER_FRAME)
|
||||||
|
if m.combo > 0 then
|
||||||
|
m.combo_timer = m.combo_timer + 1
|
||||||
|
if m.combo_timer >= COMBO_TIMEOUT_FRAMES then
|
||||||
|
m.combo = 0
|
||||||
|
m.combo_timer = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Meters.add(key, amount)
|
||||||
|
if not Context or not Context.meters then return end
|
||||||
|
local m = Context.meters
|
||||||
|
if m[key] ~= nil then
|
||||||
|
m[key] = math.min(METER_MAX, m[key] + amount)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Meters.on_minigame_complete()
|
||||||
|
local m = Context.meters
|
||||||
|
local gain = math.floor(METER_GAIN_PER_CHORE * Meters.get_combo_multiplier())
|
||||||
|
Meters.add("wpm", gain)
|
||||||
|
Meters.add("ism", gain)
|
||||||
|
Meters.add("bm", gain)
|
||||||
|
m.combo = m.combo + 1
|
||||||
|
m.combo_timer = 0
|
||||||
|
end
|
||||||
@@ -9,10 +9,11 @@ local MinigameButtonMashWindow = {}
|
|||||||
local MinigameRhythmWindow = {}
|
local MinigameRhythmWindow = {}
|
||||||
local MinigameDDRWindow = {}
|
local MinigameDDRWindow = {}
|
||||||
Util = {}
|
Util = {}
|
||||||
|
Meters = {}
|
||||||
Minigames = {}
|
Minigames = {}
|
||||||
DecisionManager = {}
|
Decision = {}
|
||||||
ScreenManager = {}
|
Screen = {}
|
||||||
MapManager = {}
|
Map = {}
|
||||||
UI = {}
|
UI = {}
|
||||||
Print = {}
|
Print = {}
|
||||||
Input = {}
|
Input = {}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
MapManager.register({
|
Map.register({
|
||||||
id = "bedroom",
|
id = "bedroom",
|
||||||
from_x = 0,
|
from_x = 0,
|
||||||
from_y = 0,
|
from_y = 0,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local _maps = {}
|
local _maps = {}
|
||||||
|
|
||||||
function MapManager.get_maps_array()
|
function Map.get_maps_array()
|
||||||
local maps_array = {}
|
local maps_array = {}
|
||||||
for _, map_data in pairs(_maps) do
|
for _, map_data in pairs(_maps) do
|
||||||
table.insert(maps_array, map_data)
|
table.insert(maps_array, map_data)
|
||||||
@@ -8,19 +8,19 @@ function MapManager.get_maps_array()
|
|||||||
return maps_array
|
return maps_array
|
||||||
end
|
end
|
||||||
|
|
||||||
function MapManager.register(map_data)
|
function Map.register(map_data)
|
||||||
if _maps[map_data.id] then
|
if _maps[map_data.id] then
|
||||||
trace("Warning: Overwriting map with id: " .. map_data.id)
|
trace("Warning: Overwriting map with id: " .. map_data.id)
|
||||||
end
|
end
|
||||||
_maps[map_data.id] = map_data
|
_maps[map_data.id] = map_data
|
||||||
end
|
end
|
||||||
|
|
||||||
function MapManager.get_by_id(map_id)
|
function Map.get_by_id(map_id)
|
||||||
return _maps[map_id]
|
return _maps[map_id]
|
||||||
end
|
end
|
||||||
|
|
||||||
function MapManager.draw(map_id)
|
function Map.draw(map_id)
|
||||||
local map_data = MapManager.get_by_id(map_id)
|
local map_data = Map.get_by_id(map_id)
|
||||||
if not map_data then
|
if not map_data then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
ScreenManager.register({
|
Screen.register({
|
||||||
id = "home",
|
id = "home",
|
||||||
name = "Home",
|
name = "Home",
|
||||||
decisions = {
|
decisions = {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
local _screens = {}
|
local _screens = {}
|
||||||
|
|
||||||
function ScreenManager.get_screens_array()
|
function Screen.get_screens_array()
|
||||||
local screens_array = {}
|
local screens_array = {}
|
||||||
for _, screen_data in pairs(_screens) do
|
for _, screen_data in pairs(_screens) do
|
||||||
table.insert(screens_array, screen_data)
|
table.insert(screens_array, screen_data)
|
||||||
@@ -8,13 +8,13 @@ function ScreenManager.get_screens_array()
|
|||||||
return screens_array
|
return screens_array
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScreenManager.register(screen_data)
|
function Screen.register(screen_data)
|
||||||
if _screens[screen_data.id] then
|
if _screens[screen_data.id] then
|
||||||
trace("Warning: Overwriting screen with id: " .. screen_data.id)
|
trace("Warning: Overwriting screen with id: " .. screen_data.id)
|
||||||
end
|
end
|
||||||
_screens[screen_data.id] = screen_data
|
_screens[screen_data.id] = screen_data
|
||||||
end
|
end
|
||||||
|
|
||||||
function ScreenManager.get_by_id(screen_id)
|
function Screen.get_by_id(screen_id)
|
||||||
return _screens[screen_id]
|
return _screens[screen_id]
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
ScreenManager.register({
|
Screen.register({
|
||||||
id = "office",
|
id = "office",
|
||||||
name = "Office",
|
name = "Office",
|
||||||
decisions = {
|
decisions = {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
ScreenManager.register({
|
Screen.register({
|
||||||
id = "toilet",
|
id = "toilet",
|
||||||
name = "Toilet",
|
name = "Toilet",
|
||||||
decisions = {
|
decisions = {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
ScreenManager.register({
|
Screen.register({
|
||||||
id = "walking_to_home",
|
id = "walking_to_home",
|
||||||
name = "Walking to home",
|
name = "Walking to home",
|
||||||
decisions = {
|
decisions = {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
ScreenManager.register({
|
Screen.register({
|
||||||
id = "walking_to_office",
|
id = "walking_to_office",
|
||||||
name = "Walking to office",
|
name = "Walking to office",
|
||||||
decisions = {
|
decisions = {
|
||||||
|
|||||||
@@ -58,4 +58,8 @@ function TIC()
|
|||||||
if handler then
|
if handler then
|
||||||
handler()
|
handler()
|
||||||
end
|
end
|
||||||
|
Meters.update()
|
||||||
|
if Context.game_in_progress then
|
||||||
|
UI.draw_meters()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -97,6 +97,38 @@ function UI.draw_decision_selector(decisions, selected_decision_index)
|
|||||||
Print.text(decision_label, text_x, text_y, Config.colors.item) Print.text(">", Config.screen.width - 6, text_y, Config.colors.green) end
|
Print.text(decision_label, text_x, text_y, Config.colors.item) Print.text(">", Config.screen.width - 6, text_y, Config.colors.green) end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.draw_meters()
|
||||||
|
if not Context or not Context.game_in_progress or not Context.meters then return end
|
||||||
|
if Context.meters.hidden then return end
|
||||||
|
|
||||||
|
local m = Context.meters
|
||||||
|
local max = Meters.get_max()
|
||||||
|
local bar_w = 44
|
||||||
|
local bar_h = 2
|
||||||
|
local bar_x = 182
|
||||||
|
local label_x = 228
|
||||||
|
local line_h = 5
|
||||||
|
local start_y = 11
|
||||||
|
local bar_offset = math.floor((line_h - bar_h) / 2)
|
||||||
|
|
||||||
|
local meter_list = {
|
||||||
|
{ key = "wpm", label = "WPM", color = Meters.COLOR_WPM, row = 0 },
|
||||||
|
{ key = "ism", label = "ISM", color = Meters.COLOR_ISM, row = 1 },
|
||||||
|
{ key = "bm", label = "BM", color = Meters.COLOR_BM, row = 2 },
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, meter in ipairs(meter_list) do
|
||||||
|
local label_y = start_y + meter.row * line_h
|
||||||
|
local bar_y = label_y + bar_offset
|
||||||
|
local fill_w = math.max(0, math.floor((m[meter.key] / max) * bar_w))
|
||||||
|
rect(bar_x, bar_y, bar_w, bar_h, Meters.COLOR_BG)
|
||||||
|
if fill_w > 0 then
|
||||||
|
rect(bar_x, bar_y, fill_w, bar_h, meter.color)
|
||||||
|
end
|
||||||
|
print(meter.label, label_x, label_y, meter.color, false, 1, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function UI.update_decision_selector(decisions, selected_decision_index)
|
function UI.update_decision_selector(decisions, selected_decision_index)
|
||||||
if Input.left() then
|
if Input.left() then
|
||||||
Audio.sfx_beep()
|
Audio.sfx_beep()
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
function GameWindow.draw()
|
function GameWindow.draw()
|
||||||
local screen = Context.screens[Context.current_screen]
|
local screen = Context.screens[Context.current_screen]
|
||||||
MapManager.draw(screen.background)
|
Map.draw(screen.background)
|
||||||
UI.draw_top_bar(screen.name)
|
UI.draw_top_bar(screen.name)
|
||||||
if screen and screen.decisions and #screen.decisions > 0 then
|
if screen and screen.decisions and #screen.decisions > 0 then
|
||||||
local available_decisions = {}
|
local available_decisions = {}
|
||||||
for _, decision_id in ipairs(screen.decisions) do
|
for _, decision_id in ipairs(screen.decisions) do
|
||||||
local decision = DecisionManager.get(decision_id)
|
local decision = Decision.get(decision_id)
|
||||||
if decision and decision.condition() then
|
if decision and decision.condition() then
|
||||||
table.insert(available_decisions, decision)
|
table.insert(available_decisions, decision)
|
||||||
end
|
end
|
||||||
@@ -39,7 +39,7 @@ function GameWindow.update()
|
|||||||
if screen and screen.decisions and #screen.decisions > 0 then
|
if screen and screen.decisions and #screen.decisions > 0 then
|
||||||
local available_decisions = {}
|
local available_decisions = {}
|
||||||
for _, decision_id in ipairs(screen.decisions) do
|
for _, decision_id in ipairs(screen.decisions) do
|
||||||
local decision = DecisionManager.get(decision_id)
|
local decision = Decision.get(decision_id)
|
||||||
if decision and decision.condition() then table.insert(available_decisions, decision)
|
if decision and decision.condition() then table.insert(available_decisions, decision)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,16 +5,13 @@ end
|
|||||||
function MinigameDDRWindow.start(return_window, song_key, params)
|
function MinigameDDRWindow.start(return_window, song_key, params)
|
||||||
MinigameDDRWindow.init(params)
|
MinigameDDRWindow.init(params)
|
||||||
Context.minigame_ddr.return_window = return_window or WINDOW_GAME
|
Context.minigame_ddr.return_window = return_window or WINDOW_GAME
|
||||||
-- Debug: Store song_key for display
|
|
||||||
Context.minigame_ddr.debug_song_key = song_key
|
Context.minigame_ddr.debug_song_key = song_key
|
||||||
-- Load song pattern if specified
|
|
||||||
if song_key and Songs and Songs[song_key] then
|
if song_key and Songs and Songs[song_key] then
|
||||||
Context.minigame_ddr.current_song = Songs[song_key]
|
Context.minigame_ddr.current_song = Songs[song_key]
|
||||||
Context.minigame_ddr.use_pattern = true
|
Context.minigame_ddr.use_pattern = true
|
||||||
Context.minigame_ddr.pattern_index = 1
|
Context.minigame_ddr.pattern_index = 1
|
||||||
Context.minigame_ddr.debug_status = "Pattern loaded: " .. song_key
|
Context.minigame_ddr.debug_status = "Pattern loaded: " .. song_key
|
||||||
else
|
else
|
||||||
-- Default to random spawning
|
|
||||||
Context.minigame_ddr.use_pattern = false
|
Context.minigame_ddr.use_pattern = false
|
||||||
if song_key then
|
if song_key then
|
||||||
Context.minigame_ddr.debug_status = "Song not found: " .. tostring(song_key)
|
Context.minigame_ddr.debug_status = "Song not found: " .. tostring(song_key)
|
||||||
@@ -25,21 +22,18 @@ function MinigameDDRWindow.start(return_window, song_key, params)
|
|||||||
Context.active_window = WINDOW_MINIGAME_DDR
|
Context.active_window = WINDOW_MINIGAME_DDR
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Spawn a new arrow (random direction)
|
|
||||||
local function spawn_arrow()
|
local function spawn_arrow()
|
||||||
local mg = Context.minigame_ddr
|
local mg = Context.minigame_ddr
|
||||||
local target = mg.target_arrows[math.random(1, 4)]
|
local target = mg.target_arrows[math.random(1, 4)]
|
||||||
table.insert(mg.arrows, {
|
table.insert(mg.arrows, {
|
||||||
dir = target.dir,
|
dir = target.dir,
|
||||||
x = target.x,
|
x = target.x,
|
||||||
y = mg.bar_y + mg.bar_height + 10 -- Start below progress bar
|
y = mg.bar_y + mg.bar_height + 10
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Spawn an arrow with specific direction
|
|
||||||
local function spawn_arrow_dir(direction)
|
local function spawn_arrow_dir(direction)
|
||||||
local mg = Context.minigame_ddr
|
local mg = Context.minigame_ddr
|
||||||
-- Find the target arrow for this direction
|
|
||||||
for _, target in ipairs(mg.target_arrows) do
|
for _, target in ipairs(mg.target_arrows) do
|
||||||
if target.dir == direction then
|
if target.dir == direction then
|
||||||
table.insert(mg.arrows, {
|
table.insert(mg.arrows, {
|
||||||
@@ -52,38 +46,30 @@ local function spawn_arrow_dir(direction)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if arrow is close enough for a hit
|
|
||||||
local function check_hit(arrow)
|
local function check_hit(arrow)
|
||||||
local mg = Context.minigame_ddr
|
local mg = Context.minigame_ddr
|
||||||
local distance = math.abs(arrow.y - mg.target_y)
|
local distance = math.abs(arrow.y - mg.target_y)
|
||||||
return distance <= mg.hit_threshold
|
return distance <= mg.hit_threshold
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check if arrow has passed the target
|
|
||||||
local function check_miss(arrow)
|
local function check_miss(arrow)
|
||||||
local mg = Context.minigame_ddr
|
local mg = Context.minigame_ddr
|
||||||
return arrow.y > mg.target_y + mg.hit_threshold
|
return arrow.y > mg.target_y + mg.hit_threshold
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw a single arrow sprite
|
|
||||||
local function draw_arrow(x, y, direction, color)
|
local function draw_arrow(x, y, direction, color)
|
||||||
local size = 12
|
local size = 12
|
||||||
local half = size / 2
|
local half = size / 2
|
||||||
-- Draw arrow shape based on direction
|
|
||||||
if direction == "left" then
|
if direction == "left" then
|
||||||
-- Triangle pointing left
|
|
||||||
tri(x + half, y, x, y + half, x + half, y + size, color)
|
tri(x + half, y, x, y + half, x + half, y + size, color)
|
||||||
rect(x + half, y + half - 2, half, 4, color)
|
rect(x + half, y + half - 2, half, 4, color)
|
||||||
elseif direction == "right" then
|
elseif direction == "right" then
|
||||||
-- Triangle pointing right
|
|
||||||
tri(x + half, y, x + size, y + half, x + half, y + size, color)
|
tri(x + half, y, x + size, y + half, x + half, y + size, color)
|
||||||
rect(x, y + half - 2, half, 4, color)
|
rect(x, y + half - 2, half, 4, color)
|
||||||
elseif direction == "up" then
|
elseif direction == "up" then
|
||||||
-- Triangle pointing up
|
|
||||||
tri(x, y + half, x + half, y, x + size, y + half, color)
|
tri(x, y + half, x + half, y, x + size, y + half, color)
|
||||||
rect(x + half - 2, y + half, 4, half, color)
|
rect(x + half - 2, y + half, 4, half, color)
|
||||||
elseif direction == "down" then
|
elseif direction == "down" then
|
||||||
-- Triangle pointing down
|
|
||||||
tri(x, y + half, x + half, y + size, x + size, y + half, color)
|
tri(x, y + half, x + half, y + size, x + size, y + half, color)
|
||||||
rect(x + half - 2, y, 4, half, color)
|
rect(x + half - 2, y, 4, half, color)
|
||||||
end
|
end
|
||||||
@@ -91,77 +77,64 @@ end
|
|||||||
|
|
||||||
function MinigameDDRWindow.update()
|
function MinigameDDRWindow.update()
|
||||||
local mg = Context.minigame_ddr
|
local mg = Context.minigame_ddr
|
||||||
-- Check for completion (bar filled to 100%)
|
|
||||||
if mg.bar_fill >= mg.max_fill then
|
if mg.bar_fill >= mg.max_fill then
|
||||||
|
Meters.on_minigame_complete()
|
||||||
|
Meters.show()
|
||||||
Context.active_window = mg.return_window
|
Context.active_window = mg.return_window
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Increment frame counter
|
|
||||||
mg.frame_counter = mg.frame_counter + 1
|
mg.frame_counter = mg.frame_counter + 1
|
||||||
-- Check if song has ended (pattern mode only)
|
|
||||||
if mg.use_pattern and mg.current_song and mg.current_song.end_frame then
|
if mg.use_pattern and mg.current_song and mg.current_song.end_frame then
|
||||||
-- Song has ended if we've passed the end frame AND all arrows are cleared
|
|
||||||
if mg.frame_counter > mg.current_song.end_frame and #mg.arrows == 0 then
|
if mg.frame_counter > mg.current_song.end_frame and #mg.arrows == 0 then
|
||||||
-- Song complete! Return to previous window
|
Meters.on_minigame_complete()
|
||||||
|
Meters.show()
|
||||||
Context.active_window = mg.return_window
|
Context.active_window = mg.return_window
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Spawn arrows based on mode (pattern or random)
|
|
||||||
if mg.use_pattern and mg.current_song and mg.current_song.pattern then
|
if mg.use_pattern and mg.current_song and mg.current_song.pattern then
|
||||||
-- Pattern-based spawning (synced to song)
|
|
||||||
local pattern = mg.current_song.pattern
|
local pattern = mg.current_song.pattern
|
||||||
-- Check if current frame matches any pattern entry
|
|
||||||
while mg.pattern_index <= #pattern do
|
while mg.pattern_index <= #pattern do
|
||||||
local spawn_entry = pattern[mg.pattern_index]
|
local spawn_entry = pattern[mg.pattern_index]
|
||||||
if mg.frame_counter >= spawn_entry.frame then
|
if mg.frame_counter >= spawn_entry.frame then
|
||||||
-- Time to spawn this arrow!
|
|
||||||
spawn_arrow_dir(spawn_entry.dir)
|
spawn_arrow_dir(spawn_entry.dir)
|
||||||
mg.pattern_index = mg.pattern_index + 1
|
mg.pattern_index = mg.pattern_index + 1
|
||||||
else
|
else
|
||||||
-- Not time yet, break the loop
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
-- Random spawning mode (original behavior)
|
|
||||||
mg.arrow_spawn_timer = mg.arrow_spawn_timer + 1
|
mg.arrow_spawn_timer = mg.arrow_spawn_timer + 1
|
||||||
if mg.arrow_spawn_timer >= mg.arrow_spawn_interval then
|
if mg.arrow_spawn_timer >= mg.arrow_spawn_interval then
|
||||||
spawn_arrow()
|
spawn_arrow()
|
||||||
mg.arrow_spawn_timer = 0
|
mg.arrow_spawn_timer = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Update falling arrows
|
|
||||||
local arrows_to_remove = {}
|
local arrows_to_remove = {}
|
||||||
for i, arrow in ipairs(mg.arrows) do
|
for i, arrow in ipairs(mg.arrows) do
|
||||||
arrow.y = arrow.y + mg.arrow_fall_speed
|
arrow.y = arrow.y + mg.arrow_fall_speed
|
||||||
-- Check if arrow went off-screen (miss)
|
|
||||||
if check_miss(arrow) then
|
if check_miss(arrow) then
|
||||||
table.insert(arrows_to_remove, i)
|
table.insert(arrows_to_remove, i)
|
||||||
-- Penalty for missing
|
|
||||||
mg.bar_fill = mg.bar_fill - mg.miss_penalty
|
mg.bar_fill = mg.bar_fill - mg.miss_penalty
|
||||||
if mg.bar_fill < 0 then
|
if mg.bar_fill < 0 then
|
||||||
mg.bar_fill = 0
|
mg.bar_fill = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Remove off-screen arrows (iterate backwards to avoid index issues)
|
-- iterate backwards to avoid index shift issues
|
||||||
for i = #arrows_to_remove, 1, -1 do
|
for i = #arrows_to_remove, 1, -1 do
|
||||||
table.remove(mg.arrows, arrows_to_remove[i])
|
table.remove(mg.arrows, arrows_to_remove[i])
|
||||||
end
|
end
|
||||||
-- Update input cooldowns
|
|
||||||
for dir, _ in pairs(mg.input_cooldowns) do
|
for dir, _ in pairs(mg.input_cooldowns) do
|
||||||
if mg.input_cooldowns[dir] > 0 then
|
if mg.input_cooldowns[dir] > 0 then
|
||||||
mg.input_cooldowns[dir] = mg.input_cooldowns[dir] - 1
|
mg.input_cooldowns[dir] = mg.input_cooldowns[dir] - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Update button press timers
|
|
||||||
for dir, _ in pairs(mg.button_pressed_timers) do
|
for dir, _ in pairs(mg.button_pressed_timers) do
|
||||||
if mg.button_pressed_timers[dir] > 0 then
|
if mg.button_pressed_timers[dir] > 0 then
|
||||||
mg.button_pressed_timers[dir] = mg.button_pressed_timers[dir] - 1
|
mg.button_pressed_timers[dir] = mg.button_pressed_timers[dir] - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Check for arrow key inputs
|
|
||||||
local input_map = {
|
local input_map = {
|
||||||
left = Input.left(),
|
left = Input.left(),
|
||||||
down = Input.down(),
|
down = Input.down(),
|
||||||
@@ -172,11 +145,9 @@ function MinigameDDRWindow.update()
|
|||||||
if pressed and mg.input_cooldowns[dir] == 0 then
|
if pressed and mg.input_cooldowns[dir] == 0 then
|
||||||
mg.input_cooldowns[dir] = mg.input_cooldown_duration
|
mg.input_cooldowns[dir] = mg.input_cooldown_duration
|
||||||
mg.button_pressed_timers[dir] = mg.button_press_duration
|
mg.button_pressed_timers[dir] = mg.button_press_duration
|
||||||
-- Check if any arrow matches this direction and is in hit range
|
|
||||||
local hit = false
|
local hit = false
|
||||||
for i, arrow in ipairs(mg.arrows) do
|
for i, arrow in ipairs(mg.arrows) do
|
||||||
if arrow.dir == dir and check_hit(arrow) then
|
if arrow.dir == dir and check_hit(arrow) then
|
||||||
-- Perfect hit!
|
|
||||||
mg.bar_fill = mg.bar_fill + mg.fill_per_hit
|
mg.bar_fill = mg.bar_fill + mg.fill_per_hit
|
||||||
if mg.bar_fill > mg.max_fill then
|
if mg.bar_fill > mg.max_fill then
|
||||||
mg.bar_fill = mg.max_fill
|
mg.bar_fill = mg.max_fill
|
||||||
@@ -186,7 +157,6 @@ function MinigameDDRWindow.update()
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- If pressed but no arrow to hit, apply small penalty
|
|
||||||
if not hit then
|
if not hit then
|
||||||
mg.bar_fill = mg.bar_fill - 2
|
mg.bar_fill = mg.bar_fill - 2
|
||||||
if mg.bar_fill < 0 then
|
if mg.bar_fill < 0 then
|
||||||
@@ -199,7 +169,6 @@ end
|
|||||||
|
|
||||||
function MinigameDDRWindow.draw()
|
function MinigameDDRWindow.draw()
|
||||||
local mg = Context.minigame_ddr
|
local mg = Context.minigame_ddr
|
||||||
-- Safety check
|
|
||||||
if not mg then
|
if not mg then
|
||||||
cls(0)
|
cls(0)
|
||||||
print("DDR ERROR: Context not initialized", 10, 10, 12)
|
print("DDR ERROR: Context not initialized", 10, 10, 12)
|
||||||
@@ -209,31 +178,24 @@ function MinigameDDRWindow.draw()
|
|||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Draw the underlying window first (for overlay effect)
|
|
||||||
if mg.return_window == WINDOW_GAME then
|
if mg.return_window == WINDOW_GAME then
|
||||||
GameWindow.draw()
|
GameWindow.draw()
|
||||||
end
|
end
|
||||||
-- Draw semi-transparent overlay background
|
|
||||||
rect(0, 0, Config.screen.width, Config.screen.height, Config.colors.black)
|
rect(0, 0, Config.screen.width, Config.screen.height, Config.colors.black)
|
||||||
-- Draw progress bar background
|
|
||||||
rect(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.light_grey)
|
rect(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.light_grey)
|
||||||
rectb(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.dark_grey)
|
rectb(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.dark_grey)
|
||||||
-- Draw progress bar fill
|
|
||||||
local fill_width = (mg.bar_fill / mg.max_fill) * mg.bar_width
|
local fill_width = (mg.bar_fill / mg.max_fill) * mg.bar_width
|
||||||
if fill_width > 0 then
|
if fill_width > 0 then
|
||||||
-- Color changes as bar fills
|
|
||||||
local bar_color = Config.colors.green
|
local bar_color = Config.colors.green
|
||||||
if mg.bar_fill > 66 then
|
if mg.bar_fill > 66 then
|
||||||
bar_color = Config.colors.item -- yellow
|
bar_color = Config.colors.item
|
||||||
elseif mg.bar_fill > 33 then
|
elseif mg.bar_fill > 33 then
|
||||||
bar_color = Config.colors.blue
|
bar_color = Config.colors.blue
|
||||||
end
|
end
|
||||||
rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color)
|
rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color)
|
||||||
end
|
end
|
||||||
-- Draw progress percentage
|
|
||||||
local percentage = math.floor((mg.bar_fill / mg.max_fill) * 100)
|
local percentage = math.floor((mg.bar_fill / mg.max_fill) * 100)
|
||||||
Print.text_center(percentage .. "%", mg.bar_x + mg.bar_width / 2, mg.bar_y + 2, Config.colors.black)
|
Print.text_center(percentage .. "%", mg.bar_x + mg.bar_width / 2, mg.bar_y + 2, Config.colors.black)
|
||||||
-- Draw target arrows at bottom (light grey when not pressed)
|
|
||||||
if mg.target_arrows then
|
if mg.target_arrows then
|
||||||
for _, target in ipairs(mg.target_arrows) do
|
for _, target in ipairs(mg.target_arrows) do
|
||||||
local is_pressed = mg.button_pressed_timers[target.dir] and mg.button_pressed_timers[target.dir] > 0
|
local is_pressed = mg.button_pressed_timers[target.dir] and mg.button_pressed_timers[target.dir] > 0
|
||||||
@@ -241,15 +203,12 @@ function MinigameDDRWindow.draw()
|
|||||||
draw_arrow(target.x, mg.target_y, target.dir, color)
|
draw_arrow(target.x, mg.target_y, target.dir, color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Draw falling arrows (blue)
|
|
||||||
if mg.arrows then
|
if mg.arrows then
|
||||||
for _, arrow in ipairs(mg.arrows) do
|
for _, arrow in ipairs(mg.arrows) do
|
||||||
draw_arrow(arrow.x, arrow.y, arrow.dir, Config.colors.blue) -- blue color
|
draw_arrow(arrow.x, arrow.y, arrow.dir, Config.colors.blue)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Draw instruction text
|
|
||||||
Print.text_center("Hit the arrows!", Config.screen.width / 2, mg.bar_y + mg.bar_height + 10, Config.colors.light_grey)
|
Print.text_center("Hit the arrows!", Config.screen.width / 2, mg.bar_y + mg.bar_height + 10, Config.colors.light_grey)
|
||||||
-- Debug info (large and visible)
|
|
||||||
local debug_y = 60
|
local debug_y = 60
|
||||||
if mg.debug_status then
|
if mg.debug_status then
|
||||||
Print.text_center(mg.debug_status, Config.screen.width / 2, debug_y, Config.colors.item)
|
Print.text_center(mg.debug_status, Config.screen.width / 2, debug_y, Config.colors.item)
|
||||||
@@ -273,4 +232,4 @@ function MinigameDDRWindow.draw()
|
|||||||
else
|
else
|
||||||
Print.text_center("RANDOM MODE", Config.screen.width / 2, debug_y, Config.colors.blue)
|
Print.text_center("RANDOM MODE", Config.screen.width / 2, debug_y, Config.colors.blue)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,28 +10,24 @@ end
|
|||||||
|
|
||||||
function MinigameButtonMashWindow.update()
|
function MinigameButtonMashWindow.update()
|
||||||
local mg = Context.minigame_button_mash
|
local mg = Context.minigame_button_mash
|
||||||
-- Check for Z button press
|
|
||||||
if Input.select() then
|
if Input.select() then
|
||||||
mg.bar_fill = mg.bar_fill + mg.fill_per_press
|
mg.bar_fill = mg.bar_fill + mg.fill_per_press
|
||||||
mg.button_pressed_timer = mg.button_press_duration
|
mg.button_pressed_timer = mg.button_press_duration
|
||||||
-- Clamp to max
|
|
||||||
if mg.bar_fill > mg.max_fill then
|
if mg.bar_fill > mg.max_fill then
|
||||||
mg.bar_fill = mg.max_fill
|
mg.bar_fill = mg.max_fill
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Check if bar is full (completed)
|
|
||||||
if mg.bar_fill >= mg.max_fill then
|
if mg.bar_fill >= mg.max_fill then
|
||||||
|
Meters.on_minigame_complete()
|
||||||
|
Meters.show()
|
||||||
Context.active_window = mg.return_window
|
Context.active_window = mg.return_window
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Automatic degradation (increases with bar fill level)
|
|
||||||
local degradation = mg.base_degradation + (mg.bar_fill * mg.degradation_multiplier)
|
local degradation = mg.base_degradation + (mg.bar_fill * mg.degradation_multiplier)
|
||||||
mg.bar_fill = mg.bar_fill - degradation
|
mg.bar_fill = mg.bar_fill - degradation
|
||||||
-- Clamp to minimum
|
|
||||||
if mg.bar_fill < 0 then
|
if mg.bar_fill < 0 then
|
||||||
mg.bar_fill = 0
|
mg.bar_fill = 0
|
||||||
end
|
end
|
||||||
-- Update button press timer
|
|
||||||
if mg.button_pressed_timer > 0 then
|
if mg.button_pressed_timer > 0 then
|
||||||
mg.button_pressed_timer = mg.button_pressed_timer - 1
|
mg.button_pressed_timer = mg.button_pressed_timer - 1
|
||||||
end
|
end
|
||||||
@@ -39,42 +35,32 @@ end
|
|||||||
|
|
||||||
function MinigameButtonMashWindow.draw()
|
function MinigameButtonMashWindow.draw()
|
||||||
local mg = Context.minigame_button_mash
|
local mg = Context.minigame_button_mash
|
||||||
-- Draw the underlying window first (for overlay effect)
|
|
||||||
if mg.return_window == WINDOW_GAME then
|
if mg.return_window == WINDOW_GAME then
|
||||||
GameWindow.draw()
|
GameWindow.draw()
|
||||||
end
|
end
|
||||||
-- Draw semi-transparent overlay background
|
|
||||||
-- Draw darker rectangles to create overlay effect
|
|
||||||
rect(0, 0, Config.screen.width, Config.screen.height, Config.colors.black)
|
rect(0, 0, Config.screen.width, Config.screen.height, Config.colors.black)
|
||||||
-- Draw progress bar background
|
|
||||||
rect(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.light_grey)
|
rect(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.light_grey)
|
||||||
rectb(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.dark_grey)
|
rectb(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.dark_grey)
|
||||||
-- Draw progress bar fill
|
|
||||||
local fill_width = (mg.bar_fill / mg.max_fill) * mg.bar_width
|
local fill_width = (mg.bar_fill / mg.max_fill) * mg.bar_width
|
||||||
if fill_width > 0 then
|
if fill_width > 0 then
|
||||||
-- Color changes as bar fills (green -> yellow -> red analogy using available colors)
|
|
||||||
local bar_color = Config.colors.green
|
local bar_color = Config.colors.green
|
||||||
if mg.bar_fill > 66 then
|
if mg.bar_fill > 66 then
|
||||||
bar_color = Config.colors.item -- yellow
|
bar_color = Config.colors.item
|
||||||
elseif mg.bar_fill > 33 then
|
elseif mg.bar_fill > 33 then
|
||||||
bar_color = Config.colors.blue
|
bar_color = Config.colors.blue
|
||||||
end
|
end
|
||||||
rect(mg.bar_x, mg.bar_y, fill_width, bar_color)
|
rect(mg.bar_x, mg.bar_y, fill_width, mg.bar_height, bar_color)
|
||||||
end
|
end
|
||||||
-- Draw button indicator
|
|
||||||
local button_color = Config.colors.light_grey
|
local button_color = Config.colors.light_grey
|
||||||
if mg.button_pressed_timer > 0 then
|
if mg.button_pressed_timer > 0 then
|
||||||
button_color = Config.colors.green -- Highlight when pressed
|
button_color = Config.colors.green
|
||||||
end
|
end
|
||||||
circb(mg.button_x, mg.button_y, mg.button_size, button_color)
|
circb(mg.button_x, mg.button_y, mg.button_size, button_color)
|
||||||
if mg.button_pressed_timer > 0 then
|
if mg.button_pressed_timer > 0 then
|
||||||
circ(mg.button_x, mg.button_y, mg.button_size - 2, button_color)
|
circ(mg.button_x, mg.button_y, mg.button_size - 2, button_color)
|
||||||
end
|
end
|
||||||
-- Draw Z text in the button
|
|
||||||
Print.text_center(" Z", mg.button_x - 2, mg.button_y - 3, Config.colors.light_grey)
|
Print.text_center(" Z", mg.button_x - 2, mg.button_y - 3, Config.colors.light_grey)
|
||||||
-- Draw instruction text
|
|
||||||
Print.text_center("MASH Z!", Config.screen.width / 2, mg.bar_y + mg.bar_height + 10, Config.colors.light_grey)
|
Print.text_center("MASH Z!", Config.screen.width / 2, mg.bar_y + mg.bar_height + 10, Config.colors.light_grey)
|
||||||
-- Draw progress percentage
|
|
||||||
local percentage = math.floor((mg.bar_fill / mg.max_fill) * 100)
|
local percentage = math.floor((mg.bar_fill / mg.max_fill) * 100)
|
||||||
Print.text_center(percentage .. "%", mg.bar_x + mg.bar_width / 2, mg.bar_y + 2, Config.colors.black)
|
Print.text_center(percentage .. "%", mg.bar_x + mg.bar_width / 2, mg.bar_y + 2, Config.colors.black)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,9 +10,7 @@ end
|
|||||||
|
|
||||||
function MinigameRhythmWindow.update()
|
function MinigameRhythmWindow.update()
|
||||||
local mg = Context.minigame_rhythm
|
local mg = Context.minigame_rhythm
|
||||||
-- Move the line across the bar (bidirectional)
|
|
||||||
mg.line_position = mg.line_position + (mg.line_speed * mg.line_direction)
|
mg.line_position = mg.line_position + (mg.line_speed * mg.line_direction)
|
||||||
-- Reverse direction when reaching either end
|
|
||||||
if mg.line_position > 1 then
|
if mg.line_position > 1 then
|
||||||
mg.line_position = 1
|
mg.line_position = 1
|
||||||
mg.line_direction = -1
|
mg.line_direction = -1
|
||||||
@@ -20,40 +18,33 @@ function MinigameRhythmWindow.update()
|
|||||||
mg.line_position = 0
|
mg.line_position = 0
|
||||||
mg.line_direction = 1
|
mg.line_direction = 1
|
||||||
end
|
end
|
||||||
-- Decrease cooldown timer
|
|
||||||
if mg.press_cooldown > 0 then
|
if mg.press_cooldown > 0 then
|
||||||
mg.press_cooldown = mg.press_cooldown - 1
|
mg.press_cooldown = mg.press_cooldown - 1
|
||||||
end
|
end
|
||||||
-- Check for Z button press (only if cooldown expired)
|
|
||||||
if Input.select() and mg.press_cooldown == 0 then
|
if Input.select() and mg.press_cooldown == 0 then
|
||||||
mg.button_pressed_timer = mg.button_press_duration
|
mg.button_pressed_timer = mg.button_press_duration
|
||||||
mg.press_cooldown = mg.press_cooldown_duration
|
mg.press_cooldown = mg.press_cooldown_duration
|
||||||
-- Calculate if line is within target area
|
|
||||||
local target_left = mg.target_center - (mg.target_width / 2)
|
local target_left = mg.target_center - (mg.target_width / 2)
|
||||||
local target_right = mg.target_center + (mg.target_width / 2)
|
local target_right = mg.target_center + (mg.target_width / 2)
|
||||||
if mg.line_position >= target_left and mg.line_position <= target_right then
|
if mg.line_position >= target_left and mg.line_position <= target_right then
|
||||||
-- HIT! Award point
|
|
||||||
mg.score = mg.score + 1
|
mg.score = mg.score + 1
|
||||||
else
|
else
|
||||||
-- MISS! Deduct point (but not below 0)
|
|
||||||
mg.score = mg.score - 1
|
mg.score = mg.score - 1
|
||||||
if mg.score < 0 then
|
if mg.score < 0 then
|
||||||
mg.score = 0
|
mg.score = 0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Calculate target width dynamically based on score
|
|
||||||
-- Each point shrinks by 10%, so reverse the formula
|
|
||||||
mg.target_width = mg.initial_target_width * (mg.target_shrink_rate ^ mg.score)
|
mg.target_width = mg.initial_target_width * (mg.target_shrink_rate ^ mg.score)
|
||||||
if mg.target_width < mg.min_target_width then
|
if mg.target_width < mg.min_target_width then
|
||||||
mg.target_width = mg.min_target_width
|
mg.target_width = mg.min_target_width
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Check win condition
|
|
||||||
if mg.score >= mg.max_score then
|
if mg.score >= mg.max_score then
|
||||||
|
Meters.on_minigame_complete()
|
||||||
|
Meters.show()
|
||||||
Context.active_window = mg.return_window
|
Context.active_window = mg.return_window
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
-- Update button press timer
|
|
||||||
if mg.button_pressed_timer > 0 then
|
if mg.button_pressed_timer > 0 then
|
||||||
mg.button_pressed_timer = mg.button_pressed_timer - 1
|
mg.button_pressed_timer = mg.button_pressed_timer - 1
|
||||||
end
|
end
|
||||||
@@ -61,46 +52,34 @@ end
|
|||||||
|
|
||||||
function MinigameRhythmWindow.draw()
|
function MinigameRhythmWindow.draw()
|
||||||
local mg = Context.minigame_rhythm
|
local mg = Context.minigame_rhythm
|
||||||
-- Draw the underlying window first (for overlay effect)
|
|
||||||
if mg.return_window == WINDOW_GAME then
|
if mg.return_window == WINDOW_GAME then
|
||||||
GameWindow.draw()
|
GameWindow.draw()
|
||||||
end
|
end
|
||||||
-- Draw semi-transparent overlay background
|
|
||||||
rect(0, 0, Config.screen.width, Config.screen.height, Config.colors.black)
|
rect(0, 0, Config.screen.width, Config.screen.height, Config.colors.black)
|
||||||
-- Calculate actual pixel positions
|
|
||||||
-- Draw bar container background
|
|
||||||
rect(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.light_grey)
|
rect(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.light_grey)
|
||||||
rectb(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.dark_grey)
|
rectb(mg.bar_x - 2, mg.bar_y - 2, mg.bar_width + 4, mg.bar_height + 4, Config.colors.dark_grey)
|
||||||
-- Draw bar background (empty area)
|
|
||||||
rect(mg.bar_x, mg.bar_y, mg.bar_width, mg.bar_height, Config.colors.dark_grey)
|
rect(mg.bar_x, mg.bar_y, mg.bar_width, mg.bar_height, Config.colors.dark_grey)
|
||||||
-- Draw target area (highlighted section in middle)
|
|
||||||
local target_left = mg.target_center - (mg.target_width / 2)
|
local target_left = mg.target_center - (mg.target_width / 2)
|
||||||
local target_x = mg.bar_x + (target_left * mg.bar_width)
|
local target_x = mg.bar_x + (target_left * mg.bar_width)
|
||||||
local target_width_pixels = mg.target_width * mg.bar_width
|
local target_width_pixels = mg.target_width * mg.bar_width
|
||||||
rect(target_x, mg.bar_y, target_width_pixels, mg.bar_height, Config.colors.green)
|
rect(target_x, mg.bar_y, target_width_pixels, mg.bar_height, Config.colors.green)
|
||||||
-- Draw the moving line
|
|
||||||
local line_x = mg.bar_x + (mg.line_position * mg.bar_width)
|
local line_x = mg.bar_x + (mg.line_position * mg.bar_width)
|
||||||
rect(line_x - 1, mg.bar_y, 2, mg.bar_height, Config.colors.item) -- Yellow line
|
rect(line_x - 1, mg.bar_y, 2, mg.bar_height, Config.colors.item)
|
||||||
-- Draw score text
|
|
||||||
local score_text = "SCORE: " .. mg.score .. " / " .. mg.max_score
|
local score_text = "SCORE: " .. mg.score .. " / " .. mg.max_score
|
||||||
Print.text_center(score_text, Config.screen.width / 2, mg.bar_y + mg.bar_height + 8, Config.colors.light_grey)
|
Print.text_center(score_text, Config.screen.width / 2, mg.bar_y + mg.bar_height + 8, Config.colors.light_grey)
|
||||||
-- Draw instruction text
|
|
||||||
Print.text_center(
|
Print.text_center(
|
||||||
"Press Z when line is in green!",
|
"Press Z when line is in green!",
|
||||||
Config.screen.width / 2,
|
Config.screen.width / 2,
|
||||||
mg.bar_y + mg.bar_height + 20,
|
mg.bar_y + mg.bar_height + 20,
|
||||||
Config.colors.light_grey
|
Config.colors.light_grey
|
||||||
)
|
)
|
||||||
-- Draw button indicator in bottom-right corner
|
|
||||||
local button_color = Config.colors.light_grey
|
local button_color = Config.colors.light_grey
|
||||||
if mg.button_pressed_timer > 0 then
|
if mg.button_pressed_timer > 0 then
|
||||||
button_color = Config.colors.green -- Highlight when pressed
|
button_color = Config.colors.green
|
||||||
end
|
end
|
||||||
-- Draw button circle
|
|
||||||
circb(mg.button_x, mg.button_y, mg.button_size, button_color)
|
circb(mg.button_x, mg.button_y, mg.button_size, button_color)
|
||||||
if mg.button_pressed_timer > 0 then
|
if mg.button_pressed_timer > 0 then
|
||||||
circ(mg.button_x, mg.button_y, mg.button_size - 2, button_color)
|
circ(mg.button_x, mg.button_y, mg.button_size - 2, button_color)
|
||||||
end
|
end
|
||||||
-- Draw Z text in the button
|
|
||||||
Print.text_center("Z", mg.button_x - 2, mg.button_y - 3, button_color)
|
Print.text_center("Z", mg.button_x - 2, mg.button_y - 3, button_color)
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user