Compare commits

...

6 Commits

Author SHA1 Message Date
7e1dd28808 screen init, update, optional decision condition
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful
2026-02-21 23:35:00 +01:00
0b25ecc793 set window objects to global
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-02-21 23:18:42 +01:00
f08e4ad1d4 Merge pull request 'sprite handling' (#10) from feature/sprite-handling into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #10
2026-02-21 22:13:31 +00:00
9ae6c12582 sprite handling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/pr/woodpecker Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker Pipeline was successful
2026-02-21 23:12:46 +01:00
4e35cd4bd3 Merge pull request 'situation handling' (#9) from feature/situation-handling into master
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Reviewed-on: #9
2026-02-21 21:34:10 +00:00
7854dc8a9f situation handling
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2026-02-21 22:33:01 +01:00
19 changed files with 146 additions and 21 deletions

View File

@@ -6,6 +6,7 @@ globals = {
"Decision",
"Situation",
"Screen",
"Sprite",
"UI",
"Print",
"Input",
@@ -13,12 +14,23 @@ globals = {
"Context",
"Meters",
"Minigames",
"SplashWindow",
"IntroWindow",
"MenuWindow",
"GameWindow",
"PopupWindow",
"ConfigurationWindow",
"AudioTestWindow",
"MinigameButtonMashWindow",
"MinigameRhythmWindow",
"MinigameDDRWindow",
"mset",
"mget",
"btnp",
"keyp",
"music",
"sfx",
"spr",
"rect",
"rectb",
"circ",

View File

@@ -5,6 +5,8 @@ init/init.minigames.lua
init/init.meters.lua
system/system.util.lua
init/init.windows.lua
sprite/sprite.manager.lua
sprite/sprite.norman.lua
situation/situation.manager.lua
situation/situation.drink_coffee.lua
decision/decision.manager.lua

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function()
Util.go_to_screen_by_id("home")
end,
condition = function() return true end
})

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function()
Util.go_to_screen_by_id("office")
end,
condition = function() return true end
})

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function()
Util.go_to_screen_by_id("toilet")
end,
condition = function() return true end
})

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function()
Util.go_to_screen_by_id("walking_to_home")
end,
condition = function() return true end
})

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function()
Util.go_to_screen_by_id("walking_to_office")
end,
condition = function() return true end
})

View File

@@ -4,5 +4,4 @@ Decision.register({
handle = function()
Situation.apply("drink_coffee")
end,
condition = function() return true end
})

View File

@@ -2,5 +2,4 @@ Decision.register({
id = "play_button_mash",
label = "Play Button Mash",
handle = function() Meters.hide() MinigameButtonMashWindow.start(WINDOW_GAME) end,
condition = function() return true end
})

View File

@@ -2,5 +2,4 @@ Decision.register({
id = "play_ddr",
label = "Play DDR (Random)",
handle = function() Meters.hide() MinigameDDRWindow.start(WINDOW_GAME, nil) end,
condition = function() return true end
})

View File

@@ -2,5 +2,4 @@ Decision.register({
id = "play_rhythm",
label = "Play Rhythm Game",
handle = function() Meters.hide() MinigameRhythmWindow.start(WINDOW_GAME) end,
condition = function() return true end
})

View File

@@ -45,7 +45,9 @@ on than meets the eye.]]
minigame_ddr = Minigames.get_default_ddr(),
minigame_button_mash = Minigames.get_default_button_mash(),
minigame_rhythm = Minigames.get_default_rhythm(),
meters = Meters.get_initial()
meters = Meters.get_initial(),
sprites = {},
current_situation = nil,
}
end
@@ -83,6 +85,7 @@ function Context.new_game()
reset_context_to_initial_state()
Context.game_in_progress = true
MenuWindow.refresh_menu_items()
Context.screens[Context.current_screen].init()
end
function Context.save_game()
@@ -103,4 +106,5 @@ function Context.load_game()
Context.game_in_progress = true
MenuWindow.refresh_menu_items()
Context.screens[Context.current_screen].init()
end

View File

@@ -1,13 +1,13 @@
local SplashWindow = {}
local IntroWindow = {}
local MenuWindow = {}
local GameWindow = {}
local PopupWindow = {}
local ConfigurationWindow = {}
local AudioTestWindow = {}
local MinigameButtonMashWindow = {}
local MinigameRhythmWindow = {}
local MinigameDDRWindow = {}
SplashWindow = {}
IntroWindow = {}
MenuWindow = {}
GameWindow = {}
PopupWindow = {}
ConfigurationWindow = {}
AudioTestWindow = {}
MinigameButtonMashWindow = {}
MinigameRhythmWindow = {}
MinigameDDRWindow = {}
Util = {}
Meters = {}
Minigames = {}
@@ -18,5 +18,5 @@ Map = {}
UI = {}
Print = {}
Input = {}
Sprite = {}
Audio = {}

View File

@@ -7,6 +7,12 @@ function Screen.register(screen_data)
if not screen_data.situations then
screen_data.situations = {}
end
if not screen_data.init then
screen_data.init = function() end
end
if not screen_data.update then
screen_data.update = function() end
end
_screens[screen_data.id] = screen_data
end

View File

@@ -2,5 +2,6 @@ Situation.register({
id = "drink_coffee",
handle = function()
Audio.sfx_select()
Sprite.show("norman", 100, 100)
end,
})

View File

@@ -8,6 +8,9 @@ function Situation.register(situation)
if not situation.handle then
situation.handle = function() end
end
if not situation.update then
situation.update = function() end
end
if _situations[situation.id] then
trace("Warning: Overwriting situation with id: " .. situation.id)
end
@@ -31,6 +34,7 @@ function Situation.apply(id)
return
end
Context.current_situation = id
situation.handle()
end

View File

@@ -0,0 +1,72 @@
local _sprites = {}
function Sprite.register(sprite_data)
if not sprite_data or not sprite_data.id then
trace("Error: Invalid sprite object registered (missing id)!")
return
end
if _sprites[sprite_data.id] then
trace("Warning: Overwriting sprite with id: " .. sprite_data.id)
end
_sprites[sprite_data.id] = sprite_data
end
function Sprite.show(id, x, y, colorkey, scale, flip_x, flip_y, rot)
-- Ensure the sprite exists before attempting to show it
if not _sprites[id] then
trace("Error: Attempted to show non-registered sprite with id: " .. id)
return
end
Context.sprites[id] = {
id = id,
x = x,
y = y,
colorkey = colorkey,
scale = scale,
flip_x = flip_x,
flip_y = flip_y,
rot = rot,
}
end
function Sprite.hide(id)
Context.sprites[id] = nil
end
function Sprite.draw()
for id, params in pairs(Context.sprites) do
local sprite_data = _sprites[id]
if not sprite_data then
trace("Error: Sprite id " .. id .. " in Context.sprites is not registered.")
Context.sprites[id] = nil -- Clean up invalid entry
-- We should probably continue to the next sprite instead of returning
-- so that other valid sprites can still be drawn.
end
-- Use parameters from Context.sprites, or fall back to sprite_data, then to defaults
local colorkey = params.colorkey or sprite_data.colorkey or 0
local scale = params.scale or sprite_data.scale or 1
local flip_x = params.flip_x or sprite_data.flip_x or 0
local flip_y = params.flip_y or sprite_data.flip_y or 0
local rot = params.rot or sprite_data.rot or 0
if sprite_data.sprites then -- Complex sprite
for i = 1, #sprite_data.sprites do
local sub_sprite = sprite_data.sprites[i]
spr(
sub_sprite.s,
params.x + (sub_sprite.x_offset or 0),
params.y + (sub_sprite.y_offset or 0),
sub_sprite.colorkey or colorkey,
sub_sprite.scale or scale,
sub_sprite.flip_x or flip_x,
sub_sprite.flip_y or flip_y,
sub_sprite.rot or rot
)
end
else -- Simple sprite
spr(sprite_data.s, params.x, params.y, colorkey, scale, flip_x, flip_y, rot)
end
end
end

View File

@@ -0,0 +1,17 @@
Sprite.register({
id = "norman",
sprites = {
-- Body
{ s = 0, x_offset = 0, y_offset = 0 },
-- Head
{ s = 1, x_offset = 0, y_offset = -8 },
-- Left Arm
{ s = 2, x_offset = -4, y_offset = 4 },
-- Right Arm
{ s = 3, x_offset = 4, y_offset = 4, flip_x = 1 }, -- Flipped arm
-- Left Leg
{ s = 4, x_offset = -2, y_offset = 8 },
-- Right Leg
{ s = 5, x_offset = 2, y_offset = 8, flip_x = 1 } -- Flipped leg
}
})

View File

@@ -14,9 +14,12 @@ function GameWindow.draw()
UI.draw_decision_selector(available_decisions, Context.selected_decision_index)
end
end
Sprite.draw()
end
function GameWindow.update()
local previous_screen_index = Context.current_screen
if Input.menu_back() then
Context.active_window = WINDOW_MENU
MenuWindow.refresh_menu_items()
@@ -36,6 +39,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