commit cf1aa522aa2d26b9372a5ec43e0c246e277c5662 Author: Nyeogmi Date: Sun Feb 4 20:55:56 2024 -0800 Initial code diff --git a/board.lua b/board.lua new file mode 100644 index 0000000..da70893 --- /dev/null +++ b/board.lua @@ -0,0 +1,206 @@ +board=klass() + +function board:init() + self.cursor=cursor:new(self) + self.slots={} + self.wells={} + + -- board slots + -- 1,11: normal + for i=1,11 do + add(self.slots,slot:new()) + end + -- 12: special + add(self.slots,slot:new(1)) + assert(#self.slots==12) + + -- wells: + -- 1,2,3,4: wands, cups, swords, pentacles + local function add_suit(_self,suit) + add(_self.wells,well:new(function(lst,new) + assert(lst) -- the ace is always present initially + if (new.suit!=suit) return + return new.suit==suit and new.rank==lst.rank+1 + end)) + end + for suit in all(deck.suits) do + add_suit(self,suit) + end + -- 5: arcana ascending + add(self.wells,well:new(function(lst,new) + if (new.suit!='a') return + if (not lst) return new.rank==0 + return new.rank==lst.rank+1 + end)) + -- 6: arcana descending + add(self.wells,well:new(function(lst,new) + if (new.suit!='a') return + if (not lst) return new.rank==21 + return new.rank==lst.rank-1 + end)) + + self:deal() +end + +function board:deal() + local n_conventional_wells=4 + local n_slots=10 + -- first, pull the aces + assert(#deck.aces==n_conventional_wells) + assert(#self.wells==n_conventional_wells+2) + local available={} + for card=1,#deck.cards do + available[card]=true + end + for i=1,n_conventional_wells do + local well=self.wells[i] + local ace=deck.aces[i] + well:add(ace) + available[ace]=false + end + + local eligible_bottom_row={} + for card=1,#deck.cards do + local skip + if not available[card] then + skip=true + else + for w in all(self.wells) do + if (w:would_accept(card)) skip=true break + end + end + if (not skip) add(eligible_bottom_row,card) + end + + function i_to_slot(i) + if (ix1 then + return stepstep(by,-x0,-x1,function(x) return f(-x) end) + end + + x=x\by*by + + while true do + x+=by + if (x>=x1) f(x1) break + if (not f(x)) break + end +end + +function lerp(x,x0,x1) + return x0+x*(x1-x0) +end + +function csv(s) + local ret=split(s,"\n") + for i,v in ipairs(ret) do + ret[i] = type(v) == "string" and split(v) or {v} end + return ret +end + +function shuf(t) + for i=#t,1,-1 do + local j=flr(rnd(i))+1 + t[i],t[j]=t[j],t[i] + end +end \ No newline at end of file diff --git a/layout.lua b/layout.lua new file mode 100644 index 0000000..f2188bc --- /dev/null +++ b/layout.lua @@ -0,0 +1,31 @@ +layouts={} +function layouts:well(i) + if (i<=4) return layout:new(69+i*10,1,layout_mode.obscured) + if (i==5) return layout:new(9,1,layout_mode.obscured) + if (i==6) return layout:new(19,1,layout_mode.obscured) + assert(false,"shouldn't be > 6") +end +function layouts:slot(i) + if (i<=11) return layout:new(9+(i-1)*10,18,layout_mode.vertical) + if (i==12) return layout:new(94,1,layout_mode.obscured) + assert(false,"shouldn't be > 12") +end + +layout_mode={ + obscured=0, -- for wells + vertical=1, -- for conventional slots + -- todo: sideways +} + +layout=klass() +function layout:init(x,y,mode) + self.x=x + self.y=y + self.mode=mode +end + +function layout:place_card(i) + if (self.mode==layout_mode.obscured) return self.x,self.y + if (self.mode==layout_mode.vertical) return self.x,self.y+(i-1)*6 + assert(false,"unexpected mode") +end \ No newline at end of file diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..647d6be --- /dev/null +++ b/main.lua @@ -0,0 +1,19 @@ +main={} +add(modules,main) + +function main:init() + self.board=board:new() +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() +end + +function main:draw() + cls(13) + self.board:draw() +end diff --git a/main.p8 b/main.p8 new file mode 100644 index 0000000..9c5dd78 --- /dev/null +++ b/main.p8 @@ -0,0 +1,25 @@ +pico-8 cartridge // http://www.pico-8.com +version 41 +__lua__ +#include engine.lua +#include board.lua +#include cursor.lua +#include deck.lua +#include layout.lua +#include main.lua +__gfx__ +00000000070000007770000000700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +70700000070000007770000007000000070707000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +07000000070000007770000007000000007777000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +70700000777000000700000070000000077070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000070000007770000070000000007777700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000070077700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000070000000700000007000000000000000000000000000000000000000000000000000 +00000000000070000000700000700070007000700070007000700070007000700070007000700070070707000707070007070700000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000070000000700000007000007777000077770000777700000000000000000000000000 +00007000000000000000700000000000000070000070007000707070000000000070007000700070077070000770700007707000000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000070000000000000007000007777700077777000777770000000000000000000000000 +00000000000070000000700000700070007000700070007000700070007000700070007000700070070077700700777007007770000000000000000000000000 +00000000000000000000000000000000000000000000000000000000000070000000700000007000000000000000000000000000000000000000000000000000