pico-8 cartridge // http://www.pico-8.com version 38 __lua__ -- main function _init() -- constants grid_size=4 spr_select=1 spr_back=3 -- variables state="wait" slc={r=0,c=0} score=0 setup_cards() end function _update() -- select a card if btnp(⬅️) then slc.c = (slc.c-1)%4 end -- todo: if! -- il faut ajouter les trois -- autres boutons pour -- deplacer le curseur -- choose a card if btnp(❎) and state != "hold" then local card = card_grid[slc.r][slc.c] -- if card not flipped if not card.flp then card.flp = true -- this is the first card if state == "wait" then card_hold=card state="pair" -- this is the second card elseif state == "pair" then -- the two are the same if card_hold.spr == card.spr then state="wait" score+=1 -- the two are not the same else card_hold_2=card state="hold" hold_timer=30 end end end end -- wait for a bit before flip if state == "hold" then hold_timer -= 1 if hold_timer == 0 then -- todo: sequence! -- il faut retourner au state -- wait, puis retourner les -- carte cote verso end end -- if all cards are ok if score == 8 then state = "win" end -- if win, can restart the game if state == "win" and btnp(🅾️) then _init() end end function _draw() -- reset screen cls() -- background colour rectfill(0,0,128,128,3) -- draw the card selector draw_select() -- draw the cards on top draw_cards() -- if win, say it! if state == 'win' then print('you win!',50,15,0) print('press 🅾️ to play again',21,110,0) end end -->8 -- functions function setup_cards() -- init list of cards local cards={} for i=0,grid_size*grid_size/2-1 do -- each card should be a pair add(cards,i) add(cards,i) end -- init card grid card_grid={} for i=0,grid_size-1 do card_grid[i]={} end -- for each row for r=0,grid_size-1 do -- for each col for c=0,grid_size-1 do local card={} -- we select a card at random -- and we remove it from list card.spr=2*deli(cards,flr(rnd(#cards))+1)+32 -- card is not flipped card.flp=false -- we add to the card grid card_grid[r][c]=card end end end function draw_select() spr(1,30+slc.c*20,30+slc.r*20,2,2) end function draw_cards() -- todo: loop! -- il faut afficher les cartes -- qui sont dans le tableau -- avec le bon cote -- (recto ou verso) end __gfx__ 00000000000aaaaaaaaaa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000aa55555555aa0000005555555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0070070000a5567777655a0000055d1111d550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0007700000a5677777765a000005d111111d50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0007700000a5777777775a0000051111111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0070070000a5777777775a0000051111d1d150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5777777775a00000511111d1150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5777777775a0000051111111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5777777775a0000051111111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5777777775a00000511d1111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5777777775a0000051d1d111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5777777775a0000051111111150000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5677777765a000005d111111d50000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000a5567777655a0000055d1111d550000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000000000aa55555555aa0000005555555500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000aaaaaaaaaa00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00005555555500000000555555550000000055555555000000005555555500000000555555550000000055555555000000005555555500000000555555550000 00055677776550000005567777655000000556777765500000055677776550000005567777655000000556777765500000055677776550000005567777655000 00056777777650000005677777765000000567777776500000056777777650000005677777765000000567777776500000056777777650000005677777765000 00057772277750000005777777775000000573bb7737500000057a77797750000005747777475000000577666677500000057777777750000005d666666d5000 0005772ff277500000057ee77ee7500000053777b77350000005777997775000000574777747500000057c7777c7500000057777d77750000005611111165000 00057772277750000005e88ee88e50000005773bb37b500000057799779750000005742442475000000567cccc76500000057777dd7750000005614444165000 000577e77e7750000005e888888e500000057bb33b7b50000005779997775000000574777747500000056cccc6c6500000057dd9ddd750000005614444165000 00057f7777f7500000057e8888e750000005b7b33bb750000005777aa9775000000574244247500000056c6cccc6500000057dd9ddd750000005614444165000 00057f7777f75000000577e88e7750000005b73bb3775000000579aaaa97500000057477774750000005c6cccc6c500000057777dd7750000005614444165000 000577f77f7750000005777ee77750000005377b77735000000579aaaa975000000574244247500000057c6666c7500000057777d77750000005611111165000 0005777ff7775000000577777777500000057377bb375000000577aaaa7750000005747777475000000577cccc77500000057777777750000005d666666d5000 00056777777650000005677777765000000567777776500000056777777650000005677777765000000567777776500000056777777650000005677777765000 00055677776550000005567777655000000556777765500000055677776550000005567777655000000556777765500000055677776550000005567777655000 00005555555500000000555555550000000055555555000000005555555500000000555555550000000055555555000000005555555500000000555555550000