Compare commits

..

2 Commits

Author SHA1 Message Date
d7d91dd3a7 Restart menu 2024-02-10 22:01:05 -08:00
8b23695945 Restart level animation 2024-02-10 21:41:48 -08:00
10 changed files with 118 additions and 20 deletions

View File

@ -9,6 +9,7 @@ function board:init(w)
self.checkpoint=nil self.checkpoint=nil
self.slots={} self.slots={}
self.wells={} self.wells={}
self.restart_progress=0
-- board slots -- board slots
-- ...n_slots: normal -- ...n_slots: normal
@ -68,6 +69,10 @@ function board:deal(seed)
end end
end end
function board:set_restart_progress(progress)
self.restart_progress=progress
end
function board:undo() function board:undo()
if (not self.watcher:intercept("undo")) return if (not self.watcher:intercept("undo")) return
if (self.checkpoint) self.checkpoint:apply(self) if (self.checkpoint) self.checkpoint:apply(self)
@ -177,6 +182,8 @@ function board:draw()
end end
end) end)
end end
democrap:distort_screen(self.restart_progress)
end end
slot=klass() slot=klass()

35
democrap.lua Normal file
View File

@ -0,0 +1,35 @@
democrap={
patterns={
0b1111111111111111,
0b1111111111111111,
0b1111111111111111,
0b1111111111111111,
0b1111111111111111,
0b1111111111111111,
0b1111111111111111,
0b1111111111111100,
0b1111111111110000,
0b1111110011110000,
0b1111000011110000,
0b1111000011000000,
0b1111000000000000,
0b1100000000000000,
0b0000000000000000
}
}
function democrap:distort_screen(progress)
if (progress <= 0) return
progress=min(progress,1)
for src=0x6002,0x7fc2,64 do
dst=src+sin(t()+src/0x800)*(4*progress)+0.5
memcpy(dst,src,60)
end
local ps=democrap.patterns
local p=ps[1+flr(progress*#ps)] or ps[#ps]
fillp(p)
local old=@0x5333
poke(0x5f33,1)
rectfill(0,0,127,127,13)
poke(0x5f33,old)
fillp()
end

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,21 +2,25 @@ 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
#include checkpoint.lua #include checkpoint.lua
#include dealer.lua #include dealer.lua
#include democrap.lua
#include cursor.lua #include cursor.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,8 @@
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
end end
function state_gameround:enter() end function state_gameround:enter() end
function state_gameround:exit() end function state_gameround:exit() end
@ -10,6 +12,19 @@ function state_gameround:suspend() end
function state_gameround:update() function state_gameround:update()
self.board:update() self.board:update()
if btn(5) then
self.restart_frames+=1
else
self.restart_frames=0
end
local restart_progress=self.restart_frames/60
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)
@ -18,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,4 +1,5 @@
tutorial={ tutorial={
-- 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),