docs
This commit is contained in:
@@ -6,6 +6,10 @@ AudioTestWindow = {
|
||||
last_pressed = false
|
||||
}
|
||||
|
||||
--- Generates menu items for audio test.
|
||||
-- @param list_func table List of audio functions.
|
||||
-- @param index_func number Current index of selected function.
|
||||
-- @return table Generated menu items.
|
||||
function AudioTestWindow.generate_menuitems(list_func, index_func)
|
||||
return {
|
||||
{
|
||||
@@ -34,6 +38,8 @@ function AudioTestWindow.generate_menuitems(list_func, index_func)
|
||||
}
|
||||
end
|
||||
|
||||
--- Generates list of audio functions.
|
||||
-- @return table A sorted list of audio function names.
|
||||
function AudioTestWindow.generate_listfunc()
|
||||
local result = {}
|
||||
|
||||
@@ -48,11 +54,13 @@ function AudioTestWindow.generate_listfunc()
|
||||
return result
|
||||
end
|
||||
|
||||
--- Navigates back from audio test window.
|
||||
function AudioTestWindow.back()
|
||||
Audio.sfx_deselect()
|
||||
GameWindow.set_state(WINDOW_MENU)
|
||||
end
|
||||
|
||||
--- Initializes audio test window.
|
||||
function AudioTestWindow.init()
|
||||
AudioTestWindow.last_pressed = false
|
||||
AudioTestWindow.index_menu = 1
|
||||
@@ -63,11 +71,13 @@ function AudioTestWindow.init()
|
||||
)
|
||||
end
|
||||
|
||||
--- Draws audio test window.
|
||||
function AudioTestWindow.draw()
|
||||
UI.draw_top_bar("Audio test")
|
||||
UI.draw_menu(AudioTestWindow.menuitems, AudioTestWindow.index_menu, 20, 50)
|
||||
end
|
||||
|
||||
--- Updates audio test window logic.
|
||||
function AudioTestWindow.update()
|
||||
if Input.up() then
|
||||
AudioTestWindow.index_menu = Util.safeindex(AudioTestWindow.menuitems, AudioTestWindow.index_menu - 1)
|
||||
|
||||
@@ -3,6 +3,7 @@ ConfigurationWindow = {
|
||||
selected_control = 1,
|
||||
}
|
||||
|
||||
--- Initializes configuration window.
|
||||
function ConfigurationWindow.init()
|
||||
ConfigurationWindow.controls = {
|
||||
UI.create_decision_item(
|
||||
@@ -16,6 +17,7 @@ function ConfigurationWindow.init()
|
||||
}
|
||||
end
|
||||
|
||||
--- Draws configuration window.
|
||||
function ConfigurationWindow.draw()
|
||||
UI.draw_top_bar("Configuration")
|
||||
|
||||
@@ -55,6 +57,7 @@ function ConfigurationWindow.draw()
|
||||
Print.text("Press B to go back", x_start, 120, Config.colors.light_grey)
|
||||
end
|
||||
|
||||
--- Updates configuration window logic.
|
||||
function ConfigurationWindow.update()
|
||||
if Input.menu_back() then
|
||||
GameWindow.set_state(WINDOW_MENU)
|
||||
@@ -88,4 +91,4 @@ function ConfigurationWindow.update()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
--- Draws the game window.
|
||||
function GameWindow.draw()
|
||||
local screen = Context.screens[Context.current_screen]
|
||||
Map.draw(screen.background)
|
||||
@@ -17,7 +18,10 @@ function GameWindow.draw()
|
||||
Sprite.draw()
|
||||
end
|
||||
|
||||
--- Updates the game window logic.
|
||||
function GameWindow.update()
|
||||
local previous_screen_index = Context.current_screen
|
||||
|
||||
if Input.menu_back() then
|
||||
Context.active_window = WINDOW_MENU
|
||||
MenuWindow.refresh_menu_items()
|
||||
@@ -37,6 +41,19 @@ function GameWindow.update()
|
||||
Context.selected_decision_index = 1 end
|
||||
|
||||
local screen = Context.screens[Context.current_screen]
|
||||
screen.update()
|
||||
|
||||
if previous_screen_index ~= Context.current_screen then
|
||||
screen.init()
|
||||
end
|
||||
|
||||
if Context.current_situation then
|
||||
local current_situation_obj = Situation.get(Context.current_situation)
|
||||
if current_situation_obj and current_situation_obj.update then
|
||||
current_situation_obj.update()
|
||||
end
|
||||
end
|
||||
|
||||
if screen and screen.decisions and #screen.decisions > 0 then
|
||||
local available_decisions = {}
|
||||
for _, decision_id in ipairs(screen.decisions) do
|
||||
@@ -64,6 +81,8 @@ function GameWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
--- Sets the active window.
|
||||
-- @param new_state number The ID of the new active window.
|
||||
function GameWindow.set_state(new_state)
|
||||
Context.active_window = new_state
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
--- Draws the intro window.
|
||||
function IntroWindow.draw()
|
||||
local x = (Config.screen.width - 132) / 2
|
||||
Print.text(Context.intro.text, x, Context.intro.y, Config.colors.green)
|
||||
end
|
||||
|
||||
--- Updates the intro window logic.
|
||||
function IntroWindow.update()
|
||||
Context.intro.y = Context.intro.y - Context.intro.speed
|
||||
|
||||
@@ -18,4 +20,4 @@ function IntroWindow.update()
|
||||
if Input.menu_confirm() then
|
||||
GameWindow.set_state(WINDOW_MENU)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
--- Draws the menu window.
|
||||
function MenuWindow.draw()
|
||||
UI.draw_top_bar("Main Menu")
|
||||
UI.draw_menu(Context.menu_items, Context.selected_menu_item, 108, 70)
|
||||
end
|
||||
|
||||
--- Updates the menu window logic.
|
||||
function MenuWindow.update()
|
||||
Context.selected_menu_item = UI.update_menu(Context.menu_items, Context.selected_menu_item)
|
||||
|
||||
@@ -15,35 +17,43 @@ function MenuWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
--- Starts a new game from the menu.
|
||||
function MenuWindow.new_game()
|
||||
Context.new_game() GameWindow.set_state(WINDOW_GAME)
|
||||
end
|
||||
|
||||
--- Loads a game from the menu.
|
||||
function MenuWindow.load_game()
|
||||
Context.load_game() GameWindow.set_state(WINDOW_GAME)
|
||||
end
|
||||
|
||||
--- Saves the current game from the menu.
|
||||
function MenuWindow.save_game()
|
||||
Context.save_game() end
|
||||
|
||||
--- Resumes the game from the menu.
|
||||
function MenuWindow.resume_game()
|
||||
GameWindow.set_state(WINDOW_GAME)
|
||||
end
|
||||
|
||||
--- Exits the game.
|
||||
function MenuWindow.exit()
|
||||
exit()
|
||||
end
|
||||
|
||||
--- Opens the configuration menu.
|
||||
function MenuWindow.configuration()
|
||||
ConfigurationWindow.init()
|
||||
GameWindow.set_state(WINDOW_CONFIGURATION)
|
||||
end
|
||||
|
||||
--- Opens the audio test menu.
|
||||
function MenuWindow.audio_test()
|
||||
AudioTestWindow.init()
|
||||
GameWindow.set_state(WINDOW_AUDIOTEST)
|
||||
end
|
||||
|
||||
--- Refreshes menu items.
|
||||
function MenuWindow.refresh_menu_items()
|
||||
Context.menu_items = {}
|
||||
if Context.game_in_progress then
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
--- Initializes DDR minigame state.
|
||||
-- @param params table Optional parameters for configuration.
|
||||
function MinigameDDRWindow.init(params)
|
||||
Context.minigame_ddr = Minigames.configure_ddr(params)
|
||||
end
|
||||
|
||||
--- Starts the DDR minigame.
|
||||
-- @param return_window number The window ID to return to after the minigame.
|
||||
-- @param[opt] song_key string The key of the song to play.
|
||||
-- @param[opt] params table Optional parameters for minigame configuration.
|
||||
function MinigameDDRWindow.start(return_window, song_key, params)
|
||||
MinigameDDRWindow.init(params)
|
||||
Context.minigame_ddr.return_window = return_window or WINDOW_GAME
|
||||
@@ -22,6 +28,7 @@ function MinigameDDRWindow.start(return_window, song_key, params)
|
||||
Context.active_window = WINDOW_MINIGAME_DDR
|
||||
end
|
||||
|
||||
--- Spawns a random arrow.
|
||||
local function spawn_arrow()
|
||||
local mg = Context.minigame_ddr
|
||||
local target = mg.target_arrows[math.random(1, 4)]
|
||||
@@ -32,6 +39,8 @@ local function spawn_arrow()
|
||||
})
|
||||
end
|
||||
|
||||
--- Spawns an arrow in a specific direction.
|
||||
-- @param direction string The direction of the arrow ("left", "down", "up", "right").
|
||||
local function spawn_arrow_dir(direction)
|
||||
local mg = Context.minigame_ddr
|
||||
for _, target in ipairs(mg.target_arrows) do
|
||||
@@ -46,17 +55,28 @@ local function spawn_arrow_dir(direction)
|
||||
end
|
||||
end
|
||||
|
||||
--- Checks if an arrow is hit.
|
||||
-- @param arrow table The arrow data.
|
||||
-- @return boolean True if the arrow is hit, false otherwise.
|
||||
local function check_hit(arrow)
|
||||
local mg = Context.minigame_ddr
|
||||
local distance = math.abs(arrow.y - mg.target_y)
|
||||
return distance <= mg.hit_threshold
|
||||
end
|
||||
|
||||
--- Checks if an arrow is missed.
|
||||
-- @param arrow table The arrow data.
|
||||
-- @return boolean True if the arrow is missed, false otherwise.
|
||||
local function check_miss(arrow)
|
||||
local mg = Context.minigame_ddr
|
||||
return arrow.y > mg.target_y + mg.hit_threshold
|
||||
end
|
||||
|
||||
--- Draws an arrow.
|
||||
-- @param x number The x-coordinate.
|
||||
-- @param y number The y-coordinate.
|
||||
-- @param direction string The direction of the arrow.
|
||||
-- @param color number The color of the arrow.
|
||||
local function draw_arrow(x, y, direction, color)
|
||||
local size = 12
|
||||
local half = size / 2
|
||||
@@ -75,6 +95,7 @@ local function draw_arrow(x, y, direction, color)
|
||||
end
|
||||
end
|
||||
|
||||
--- Updates DDR minigame logic.
|
||||
function MinigameDDRWindow.update()
|
||||
local mg = Context.minigame_ddr
|
||||
if mg.bar_fill >= mg.max_fill then
|
||||
@@ -167,6 +188,7 @@ function MinigameDDRWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
--- Draws DDR minigame.
|
||||
function MinigameDDRWindow.draw()
|
||||
local mg = Context.minigame_ddr
|
||||
if not mg then
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
--- Initializes button mash minigame state.
|
||||
-- @param params table Optional parameters for configuration.
|
||||
function MinigameButtonMashWindow.init(params)
|
||||
Context.minigame_button_mash = Minigames.configure_button_mash(params)
|
||||
end
|
||||
|
||||
--- Starts the button mash minigame.
|
||||
-- @param return_window number The window ID to return to after the minigame.
|
||||
-- @param[opt] params table Optional parameters for minigame configuration.
|
||||
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
|
||||
|
||||
--- Updates button mash minigame logic.
|
||||
function MinigameButtonMashWindow.update()
|
||||
local mg = Context.minigame_button_mash
|
||||
if Input.select() then
|
||||
@@ -33,6 +39,7 @@ function MinigameButtonMashWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
--- Draws button mash minigame.
|
||||
function MinigameButtonMashWindow.draw()
|
||||
local mg = Context.minigame_button_mash
|
||||
if mg.return_window == WINDOW_GAME then
|
||||
|
||||
@@ -1,13 +1,19 @@
|
||||
--- Initializes rhythm minigame state.
|
||||
-- @param params table Optional parameters for configuration.
|
||||
function MinigameRhythmWindow.init(params)
|
||||
Context.minigame_rhythm = Minigames.configure_rhythm(params)
|
||||
end
|
||||
|
||||
--- Starts the rhythm minigame.
|
||||
-- @param return_window number The window ID to return to after the minigame.
|
||||
-- @param[opt] params table Optional parameters for minigame configuration.
|
||||
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
|
||||
|
||||
--- Updates rhythm minigame logic.
|
||||
function MinigameRhythmWindow.update()
|
||||
local mg = Context.minigame_rhythm
|
||||
mg.line_position = mg.line_position + (mg.line_speed * mg.line_direction)
|
||||
@@ -50,6 +56,7 @@ function MinigameRhythmWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
--- Draws rhythm minigame.
|
||||
function MinigameRhythmWindow.draw()
|
||||
local mg = Context.minigame_rhythm
|
||||
if mg.return_window == WINDOW_GAME then
|
||||
|
||||
@@ -5,14 +5,18 @@ local POPUP_HEIGHT = 80
|
||||
local TEXT_MARGIN_X = POPUP_X + 10
|
||||
local TEXT_MARGIN_Y = POPUP_Y + 10
|
||||
local LINE_HEIGHT = 8
|
||||
--- Displays a popup window.
|
||||
-- @param content_strings table A table of strings to display in the popup.
|
||||
function PopupWindow.show(content_strings)
|
||||
Context.popup.show = true
|
||||
Context.popup.content = content_strings or {} GameWindow.set_state(WINDOW_POPUP) end
|
||||
|
||||
--- Hides the popup window.
|
||||
function PopupWindow.hide()
|
||||
Context.popup.show = false
|
||||
Context.popup.content = {} GameWindow.set_state(WINDOW_GAME) end
|
||||
|
||||
--- Updates popup window logic.
|
||||
function PopupWindow.update()
|
||||
if Context.popup.show then
|
||||
if Input.menu_confirm() or Input.menu_back() then PopupWindow.hide()
|
||||
@@ -20,6 +24,7 @@ function PopupWindow.update()
|
||||
end
|
||||
end
|
||||
|
||||
--- Draws the popup window.
|
||||
function PopupWindow.draw()
|
||||
if Context.popup.show then
|
||||
rect(POPUP_X, POPUP_Y, POPUP_WIDTH, POPUP_HEIGHT, Config.colors.black)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
--- Draws the splash window.
|
||||
function SplashWindow.draw()
|
||||
local txt = "Definitely not an Impostor"
|
||||
local w = #txt * 6
|
||||
@@ -6,6 +7,7 @@ function SplashWindow.draw()
|
||||
print(txt, x, y, 12)
|
||||
end
|
||||
|
||||
--- Updates the splash window logic.
|
||||
function SplashWindow.update()
|
||||
Context.splash_timer = Context.splash_timer - 1
|
||||
if Context.splash_timer <= 0 or Input.menu_confirm() then
|
||||
|
||||
Reference in New Issue
Block a user