Restart menu

This commit is contained in:
Pyrex 2024-02-10 22:01:05 -08:00
parent 8b23695945
commit d7d91dd3a7
8 changed files with 67 additions and 21 deletions

View File

@ -2,7 +2,6 @@
modules={} modules={}
function _init() function _init()
-- printh("restarting")
_doall("init") _doall("init")
end end

View File

@ -13,4 +13,5 @@ end
function main:draw() function main:draw()
self.state_manager:draw() self.state_manager:draw()
apply_palette()
end end

View File

@ -2,6 +2,7 @@ pico-8 cartridge // http://www.pico-8.com
version 41 version 41
__lua__ __lua__
#include engine.lua #include engine.lua
#include palette.lua
#include animator.lua #include animator.lua
#include board.lua #include board.lua
#include board_animations.lua #include board_animations.lua
@ -12,12 +13,14 @@ __lua__
#include layout.lua #include layout.lua
#include layout_hint.lua #include layout_hint.lua
#include ruleset.lua #include ruleset.lua
#include palette.lua
#include progression.lua #include progression.lua
#include seed_constants.lua #include seed_constants.lua
#include seeds.lua #include seeds.lua
#include state_manager.lua #include state_manager.lua
#include state_gameround.lua #include state_gameround.lua
#include state_ironman.lua #include state_ironman.lua
#include state_restartmenu.lua
#include tutorial.lua #include tutorial.lua
#include text.lua #include text.lua
#include watcher.lua #include watcher.lua

17
palette.lua Normal file
View File

@ -0,0 +1,17 @@
function apply_palette()
-- bg
pal(13,-3,1)
-- arcana
-- pal(1,0,1)
pal(15,-9,1)
-- suits
pal(4,-11,1) -- first suit
pal(12,12,1)
pal(2,-8,1)
pal(3,-5,1)
-- pal(8,-9,1)
-- pal(14,8,1)
end

View File

@ -1,6 +1,7 @@
state_gameround=klass() state_gameround=klass()
function state_gameround:init(watcher,ruleset) function state_gameround:init(watcher,ruleset)
self.board=board:new(watcher,ruleset) self.board=board:new(watcher,ruleset)
self.outcome=nil
self.restart_frames=0 self.restart_frames=0
end end
function state_gameround:enter() end function state_gameround:enter() end
@ -18,6 +19,12 @@ function state_gameround:update()
end end
local restart_progress=self.restart_frames/60 local restart_progress=self.restart_frames/60
self.board:set_restart_progress(restart_progress) self.board:set_restart_progress(restart_progress)
if restart_progress>=1.0 then
main.state_manager:push(state_restartmenu:new())
return
end
if self.board:can_take_input() then if self.board:can_take_input() then
if (btnp(0)) self.board.cursor:move_x(-1) if (btnp(0)) self.board.cursor:move_x(-1)
if (btnp(1)) self.board.cursor:move_x(1) if (btnp(1)) self.board.cursor:move_x(1)
@ -26,25 +33,10 @@ function state_gameround:update()
if (btnp(4)) self.board.cursor:toggle_grab() if (btnp(4)) self.board.cursor:toggle_grab()
if (btnp(5)) self.board:undo() if (btnp(5)) self.board:undo()
end end
if (self.board:is_won()) self.done=true if (self.board:is_won()) self.outcome="win" self.done=true
end end
function state_gameround:draw() function state_gameround:draw()
cls(13) cls(13)
self.board:draw() self.board:draw()
-- bg
pal(13,-3,1)
-- arcana
-- pal(1,0,1)
pal(15,-9,1)
-- suits
pal(4,-11,1) -- first suit
pal(12,12,1)
pal(2,-8,1)
pal(3,-5,1)
-- pal(8,-9,1)
-- pal(14,8,1)
end end

View File

@ -7,16 +7,29 @@ end
function state_ironman:enter() self:on_enter() end function state_ironman:enter() self:on_enter() end
function state_ironman:exit() end function state_ironman:exit() end
function state_ironman:reenter() self:on_enter() end function state_ironman:reenter(round)
printh("reenter "..round.outcome)
if round.outcome=="win" then
self.level+=1
elseif round.outcome=="menu" then
self.done=true
elseif round.outcome=="restart" then
else
assert(false,"unrecognized outcome: "..round.outcome)
end
self:on_enter()
end
function state_ironman:suspend() end function state_ironman:suspend() end
function state_ironman:on_enter() function state_ironman:on_enter()
self.done=true
local level=self.level local level=self.level
self.level+=1 if (self.done) return
if level <= #self.sequence then if level <= #self.sequence then
local w=self.sequence[level]() local w=self.sequence[level]()
main.state_manager:push(state_gameround:new(w)) main.state_manager:push(state_gameround:new(w))
else
self.done=true
end end
end end

21
state_restartmenu.lua Normal file
View File

@ -0,0 +1,21 @@
state_restartmenu=klass()
function state_restartmenu:init()
end
function state_restartmenu:enter() end
function state_restartmenu:exit(new_top)
new_top.outcome=self.outcome
new_top.done=true
end
function state_restartmenu:reenter() end
function state_restartmenu:suspend() end
function state_restartmenu:update()
if (btnp(0)) self.outcome="menu" self.done=true
if (btnp(4)) self.outcome="restart" self.done=true
end
function state_restartmenu:draw()
cls(13)
print("⬅️ back to menu",1,58,7)
print("🅾️ restart",1,64,7)
end

View File

@ -1,5 +1,5 @@
tutorial={ tutorial={
function() return watcher:new(progression[6]) end, -- function() return watcher:new(progression[6]) end,
function() function()
return watcher:new(progression[1], 10,{ return watcher:new(progression[1], 10,{
tutorial_grab:new(1,4), tutorial_grab:new(1,4),