From 8b23695945232f7c96be57905ed0a71e6bfc692e Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Sat, 10 Feb 2024 21:41:48 -0800 Subject: [PATCH] Restart level animation --- board.lua | 7 +++++++ democrap.lua | 35 +++++++++++++++++++++++++++++++++++ main.p8 | 1 + state_gameround.lua | 8 ++++++++ tutorial.lua | 1 + 5 files changed, 52 insertions(+) create mode 100644 democrap.lua diff --git a/board.lua b/board.lua index e52b7bf..ee6300d 100644 --- a/board.lua +++ b/board.lua @@ -9,6 +9,7 @@ function board:init(w) self.checkpoint=nil self.slots={} self.wells={} + self.restart_progress=0 -- board slots -- ...n_slots: normal @@ -68,6 +69,10 @@ function board:deal(seed) end end +function board:set_restart_progress(progress) + self.restart_progress=progress +end + function board:undo() if (not self.watcher:intercept("undo")) return if (self.checkpoint) self.checkpoint:apply(self) @@ -177,6 +182,8 @@ function board:draw() end end) end + + democrap:distort_screen(self.restart_progress) end slot=klass() diff --git a/democrap.lua b/democrap.lua new file mode 100644 index 0000000..0d43ef3 --- /dev/null +++ b/democrap.lua @@ -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 \ No newline at end of file diff --git a/main.p8 b/main.p8 index 1064254..b440b24 100644 --- a/main.p8 +++ b/main.p8 @@ -7,6 +7,7 @@ __lua__ #include board_animations.lua #include checkpoint.lua #include dealer.lua +#include democrap.lua #include cursor.lua #include layout.lua #include layout_hint.lua diff --git a/state_gameround.lua b/state_gameround.lua index 077d85e..c1fb3ed 100644 --- a/state_gameround.lua +++ b/state_gameround.lua @@ -1,6 +1,7 @@ state_gameround=klass() function state_gameround:init(watcher,ruleset) self.board=board:new(watcher,ruleset) + self.restart_frames=0 end function state_gameround:enter() end function state_gameround:exit() end @@ -10,6 +11,13 @@ function state_gameround:suspend() end function state_gameround: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 self.board:can_take_input() then if (btnp(0)) self.board.cursor:move_x(-1) if (btnp(1)) self.board.cursor:move_x(1) diff --git a/tutorial.lua b/tutorial.lua index 1bf2f1d..93f3ebb 100644 --- a/tutorial.lua +++ b/tutorial.lua @@ -1,4 +1,5 @@ tutorial={ + function() return watcher:new(progression[6]) end, function() return watcher:new(progression[1], 10,{ tutorial_grab:new(1,4),