From d1946315e9f98049ca486618d2e8b6d34e11280f Mon Sep 17 00:00:00 2001 From: Simon Cambier Date: Mon, 30 May 2022 22:44:22 +0200 Subject: [PATCH] Blinking rules --- 0hh1.p8 | 21 ++++++++------ main.lua | 14 ++++++--- states/rules.lua | 74 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 87 insertions(+), 22 deletions(-) diff --git a/0hh1.p8 b/0hh1.p8 index cff9c53..0f48779 100644 --- a/0hh1.p8 +++ b/0hh1.p8 @@ -1,6 +1,11 @@ pico-8 cartridge // http://www.pico-8.com version 36 __lua__ +-- Font M3X6 by daniel linssen +poke(0x5600, 4, 4, 7) +poke4(0x5700,unpack(split"0x0000.0000,0x0000.0000,0x0202.0202,0x0000.0200,0x0000.0505,0x0000.0000,0x0505.0705,0x0000.0507,0x0407.0106,0x0000.0203,0x0204.0100,0x0000.0401,0x0102.0502,0x0000.0305,0x0000.0102,0x0000.0000,0x0101.0102,0x0000.0201,0x0202.0201,0x0000.0102,0x0205.0000,0x0000.0005,0x0702.0000,0x0000.0002,0x0000.0000,0x0000.0102,0x0700.0000,0x0000.0000,0x0000.0000,0x0000.0200,0x0202.0404,0x0000.0101,0x0505.0506,0x0000.0305,0x0202.0302,0x0000.0702,0x0204.0403,0x0000.0701,0x0403.0403,0x0000.0304,0x0406.0505,0x0000.0404,0x0403.0107,0x0000.0304,0x0503.0106,0x0000.0605,0x0204.0407,0x0000.0202,0x0502.0506,0x0000.0305,0x0605.0503,0x0000.0304,0x0002.0000,0x0000.0002,0x0002.0000,0x0000.0102,0x0102.0400,0x0000.0402,0x0007.0000,0x0000.0007,0x0402.0100,0x0000.0102,0x0204.0403,0x0000.0200,0x0505.0506,0x0000.0601,0x0604.0300,0x0000.0705,0x0505.0301,0x0000.0705,0x0101.0600,0x0000.0701,0x0505.0604,0x0000.0705,0x0705.0600,0x0000.0601,0x0702.0204,0x0000.0202,0x0705.0600,0x0000.0304,0x0505.0301,0x0000.0505,0x0202.0002,0x0000.0202,0x0202.0002,0x0000.0102,0x0305.0101,0x0000.0505,0x0202.0202,0x0000.0402,0x0707.0300,0x0000.0507,0x0505.0300,0x0000.0505,0x0505.0600,0x0000.0305,0x0305.0700,0x0000.0101,0x0705.0600,0x0000.0404,0x0101.0600,0x0000.0101,0x0701.0600,0x0000.0304,0x0207.0202,0x0000.0202,0x0505.0500,0x0000.0705,0x0505.0500,0x0000.0205,0x0705.0500,0x0000.0507,0x0205.0500,0x0000.0505,0x0605.0500,0x0000.0304,0x0204.0700,0x0000.0701,0x0101.0103,0x0000.0301,0x0202.0101,0x0000.0404,0x0202.0203,0x0000.0302,0x0000.0502,0x0000.0000,0x0000.0000,0x0000.0403,0x0000.0201,0x0000.0000,0x0507.0506,0x0000.0505,0x0507.0503,0x0000.0705,0x0101.0106,0x0000.0701,0x0505.0503,0x0000.0305,0x0103.0107,0x0000.0701,0x0301.0106,0x0000.0101,0x0501.0106,0x0000.0705,0x0507.0505,0x0000.0505,0x0202.0207,0x0000.0702,0x0404.0407,0x0000.0304,0x0503.0505,0x0000.0505,0x0101.0101,0x0000.0701,0x0507.0705,0x0000.0505,0x0505.0503,0x0000.0505,0x0505.0506,0x0000.0305,0x0103.0507,0x0000.0101,0x0505.0506,0x0000.0403,0x0503.0507,0x0000.0505,0x0407.0106,0x0000.0304,0x0202.0207,0x0000.0202,0x0505.0505,0x0000.0705,0x0505.0505,0x0000.0205,0x0705.0505,0x0000.0507,0x0202.0505,0x0000.0505,0x0205.0505,0x0000.0202,0x0202.0407,0x0000.0701,0x0302.0204,0x0000.0402,0x0202.0202,0x0000.0202,0x0602.0201,0x0000.0102,0x0704.0000,0x0000.0001,0x0205.0200,0x0000.0000")) +poke(0x5f58,0x81) + #include main.lua #include board.lua #include states/menu.lua @@ -40,14 +45,14 @@ __gfx__ 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -11011011011001101101101100110110110110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -11011011011001101101101100110110110110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +cc0cc01101100cc0cc088011001101101101100110110110110011011011011008801101101100880880cc01100880880cc01100000000000000000000000000 +cc0cc01101100cc0cc088011001101101101100110110110110011011011011008801101101100880880cc01100880880cc01100000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -cc0cc01101100cc0cc08801100cc0cc0880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -cc0cc01101100cc0cc08801100cc0cc0880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +1101101101100110110110110011011088011001101108801100880880cc01100880880cc0cc00cc0880cc08800cc0880cc08800000000000000000000000000 +1101101101100110110110110011011088011001101108801100880880cc01100880880cc0cc00cc0880cc08800cc0880cc08800000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -11011011011001101101101100110110cc0110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -11011011011001101101101100110110cc0110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +110110110110011011011011001101101101100110110cc01100cc01101101100cc01101101100110cc08801100cc0cc08808800000000000000000000000000 +110110110110011011011011001101101101100110110cc01100cc01101101100cc01101101100110cc08801100cc0cc08808800000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -11011088011001101108801100110110880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 -11011088011001101108801100110110880110000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 +110cc0cc01100880cc0cc0880011011088011001101108801100cc01101101100cc01101101100110cc0880cc00880cc0880cc00000000000000000000000000 +110cc0cc01100880cc0cc0880011011088011001101108801100cc01101101100cc01101101100110cc0880cc00880cc0880cc00000000000000000000000000 diff --git a/main.lua b/main.lua index 0950b03..a9af573 100644 --- a/main.lua +++ b/main.lua @@ -52,9 +52,12 @@ function slice(tbl, first, last, step) return sliced end -local _rectfill = rectfill -function rectfill(x, y, w, h, col) - _rectfill(x, y, x+w, y+h, col) +function rectfill2(x, y, w, h, col) + rectfill(x, y, x+w, y+h, col) +end + +function rect2(x, y, w, h, col) + rect(x, y, x+w, y+h, col) end -- @@ -120,7 +123,7 @@ function makeButton(x, y, w, h, text, onClick, onHover) onHover = onHover, draw=function(self, selected) - -- rectfill(self.x, self.y, self.w, self.h, 8) + -- rectfillw(self.x, self.y, self.w, self.h, 8) local color = selected and 7 or 5 print(self.text, self.x+1, self.y+1, color) end, @@ -164,6 +167,8 @@ function _init() mouse_x = 0 mouse_y = 0 + frameCount = 0 + states = { rules = stateRules(), menu = stateMenu(), @@ -175,6 +180,7 @@ function _init() end function _update60() + frameCount += 1 gs._update() -- if not create then -- board:solveStep() diff --git a/states/rules.lua b/states/rules.lua index 57abda5..4563c62 100644 --- a/states/rules.lua +++ b/states/rules.lua @@ -1,12 +1,66 @@ function stateRules() -return { - _update=function() - end, - _draw=function() - print("1) you can't have more than\n 2 tiles of the same color\n in a row.", 2,2, 7) - sspr(0,32, 12,12, 8,24) - spr(2, 23, 25) - sspr(12,32, 12,12, 34,24) - end, -} + + local fade = split"0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,4,9,10,9,4,2" + local color = 1 + + function blink(x,y,w,h) + rect2(x,y,w,h,fade[color]) + end + + + return { + _update=function() + if frameCount%8==0 then + color += 1 + end + if color>#fade then + color = 1 + end + end, + + _draw=function() + print("1) yOU CAN'T HAVE MORE THAN\n TWO (2) CONSECUTIVE TILES\n OF THE SAME COLOR", 2,2, 7) + local x = 14 + local y = 28 + sspr(0,32, 12,12, x,y) + spr(2, x+14, y+1) + sspr(13,32, 12,12, x+26,y) + blink(x-1, y-1, 9, 3) + blink(x+25, y-1, 9, 3) + blink(x-1, y+8, 12, 3) + blink(x+25, y+8, 12, 3) + + x = 75 + sspr(26,32, 12,12, x,y) + spr(2, x+14, y+1) + sspr(39,32, 12,12, x+26,y) + blink(x+5, y+2, 3, 9) + blink(x+31, y+2, 3, 9) + + + -------------- + + x = 44 + y = 50 + print("2) eACH LINE CONTAINS AN EQUAL\n NUMBER OF EACH COLOR", 2, y, 7) + sspr(52,32, 12,12, x,y+20) + spr(2, x+14, y+21) + sspr(65,32, 12,12, x+26,y+20) + blink(x+5, y+22, 6, 3) + blink(x+31, y+22, 6, 3) + blink(x-1, y+19, 3, 6) + blink(x+25, y+19, 3, 6) + + -------------- + + x = 44 + y = 90 + print("3) aLL ROWS AND COLUMNS\n ARE DIFFERENT", 2, y, 7) + sspr(78,32, 12,12, x,y+20) + spr(2, x+14, y+21) + sspr(91,32, 12,12, x+26,y+20) + blink(x-1, y+25, 12, 6) + blink(x+25, y+25, 12, 6) + end, + } end \ No newline at end of file