From bdc8c91078508e0c2d325136ba244d4d43360645 Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Sun, 4 Feb 2024 22:55:13 -0800 Subject: [PATCH] Basic animations --- animator.lua | 26 +++++++++++++++++ board.lua | 59 ++++++++++++++++++++++++++++---------- board_animations.lua | 68 ++++++++++++++++++++++++++++++++++++++++++++ main.lua | 14 +++++---- main.p8 | 2 ++ progression.lua | 4 +-- ruleset.lua | 2 +- 7 files changed, 152 insertions(+), 23 deletions(-) create mode 100644 animator.lua create mode 100644 board_animations.lua diff --git a/animator.lua b/animator.lua new file mode 100644 index 0000000..cf677d3 --- /dev/null +++ b/animator.lua @@ -0,0 +1,26 @@ +animator=klass() +function animator:init() + self.operations={} +end +function animator:update() + while true do + if (#self.operations==0) return + local op=self.operations[1] + if op:update() then + return true + else + deli(self.operations,1) + end + end +end +function animator:idle() + return #self.operations==0 +end +function animator:add(op) + add(self.operations,op) +end +function animator:draw() + for i=#self.operations,1,-1 do + self.operations[i]:draw() + end +end \ No newline at end of file diff --git a/board.lua b/board.lua index 0fbe45b..4090497 100644 --- a/board.lua +++ b/board.lua @@ -3,6 +3,7 @@ board=klass() function board:init(ruleset) self.ruleset=ruleset self.cursor=cursor:new(self) + self.animator=animator:new() self.slots={} self.wells={} @@ -52,7 +53,8 @@ function board:deal() for i=1,#self.ruleset.deck.aces do local well=self.wells[i] local ace=self.ruleset.deck.aces[i] - well:add(ace) + well:add(ace) -- temporarily, so would_accept will work + self:animate_move_ace_to_well(ace,i) available[ace]=false end @@ -69,6 +71,11 @@ function board:deal() if (not skip) add(eligible_bottom_row,card) end + -- let the animation install the aces for real + for w in all(self.wells) do + w:clear() + end + function i_to_slot(i) if (i=1.0) on_end() return false + return true + end + function anim_obj:draw() + local x=start_x+(end_x-start_x)*progress + local y=start_y+(end_y-start_y)*progress + _self.ruleset.deck:draw_card(x,y,card,false) + end + + self.animator:add(anim_obj) +end \ No newline at end of file diff --git a/main.lua b/main.lua index f917970..c72caee 100644 --- a/main.lua +++ b/main.lua @@ -2,15 +2,19 @@ main={} add(modules,main) function main:init() + extcmd("rec") self.board=board:new(progression[1]) end function main:update() - if (btnp(0)) self.board.cursor:move_x(-1) - if (btnp(1)) self.board.cursor:move_x(1) - if (btnp(2)) self.board.cursor:move_y(-1) - if (btnp(3)) self.board.cursor:move_y(1) - if (btnp(4)) self.board.cursor:toggle_grab() + self.board:update() + 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) + if (btnp(2)) self.board.cursor:move_y(-1) + if (btnp(3)) self.board.cursor:move_y(1) + if (btnp(4)) self.board.cursor:toggle_grab() + end end function main:draw() diff --git a/main.p8 b/main.p8 index 7fe85df..be20ccb 100644 --- a/main.p8 +++ b/main.p8 @@ -2,7 +2,9 @@ pico-8 cartridge // http://www.pico-8.com version 41 __lua__ #include engine.lua +#include animator.lua #include board.lua +#include board_animations.lua #include cursor.lua #include layout.lua #include ruleset.lua diff --git a/progression.lua b/progression.lua index df0a447..cb56f6d 100644 --- a/progression.lua +++ b/progression.lua @@ -1,6 +1,6 @@ progression={ -- level 1 - ruleset:new(5,1,9,0), + --ruleset:new(5,1,9,0), -- level 2 -- ruleset:new(5,2,9,0), -- level 3 @@ -10,7 +10,7 @@ progression={ -- level 5 -- ruleset:new(9,3,11,18), -- fortune's foundation - -- ruleset:new(11,4,13,22) + ruleset:new(11,4,13,22) -- harder than fortune's foundation -- ruleset:new(11,5,10,25) } \ No newline at end of file diff --git a/ruleset.lua b/ruleset.lua index 1d063f2..59903ea 100644 --- a/ruleset.lua +++ b/ruleset.lua @@ -84,7 +84,7 @@ function ruleset:generate_deck() local bg,shadowbg if meta.suit=='a' then bg,shadowbg=1,1 - if (shadow) bg,shadowbg=1,0 + if (shadow) bg,shadowbg=1,1 if (is_extreme) bg,shadowbg=8,8 else bg,shadowbg=7,7