307307
308308local inputHandlers = {
309309 upButtonDown = function ()
310- if not lost then
310+ if not lost and not menuOpen then
311311 local dist = 0
312312 while canPieceMove (piece .x , piece .y + 1 , piece .rotation ) do
313313 piece .y += 1
@@ -367,7 +367,11 @@ local function drawBlock(block, x, y, size)
367367 size - 1
368368 )
369369
370- if grid then gfx [(block ~= " " and " fillRect" or " drawRect" )](rect )
370+ if grid then
371+ gfx .setColor (darkMode and gfx .kColorBlack or gfx .kColorWhite )
372+ gfx .fillRect (rect )
373+ gfx .setColor (darkMode and gfx .kColorWhite or gfx .kColorBlack )
374+ gfx [(block ~= " " and " fillRect" or " drawRect" )](rect )
371375 elseif block ~= " " then gfx .fillRect (rect ) end
372376end
373377
391395
392396reset ()
393397
398+ local function lose ()
399+ timer = 0
400+ lost = true
401+ UITimer = time .new (500 , 8 , - 4 , easings .outCubic )
402+ playdate .inputHandlers .pop ()
403+ end
404+
394405local function updateGame ()
395406 if not lost then
396407 local crankTicks = playdate .getCrankTicks (4 )
@@ -522,12 +533,7 @@ local function updateGame()
522533 newPiece (table.remove (sequence ))
523534 hasHeldPiece = false
524535
525- if not canPieceMove (piece .x , piece .y , piece .rotation ) then
526- timer = 0
527- lost = true
528- UITimer = time .new (500 , 8 , - 4 , easings .outCubic )
529- playdate .inputHandlers .pop ()
530- end -- check if lost
536+ if not canPieceMove (piece .x , piece .y , piece .rotation ) then lose () end
531537 end -- complete a row
532538 end -- timer is over timerLimit
533539 else
@@ -548,7 +554,6 @@ local function updateGame()
548554 end -- state machine
549555end
550556
551-
552557local function drawScores ()
553558 local bold = gfx .getSystemFont (" bold" )
554559 gfx .drawTextAligned (" *Score*" , (UITimer .value - 2 )* uiBlockSize , 9 * uiBlockSize , kTextAlignment .center )
@@ -618,15 +623,28 @@ local function drawGame()
618623 end
619624 end
620625
626+ if # sashes > 0 then updateEffect (sashes , # sashes , sashes [# sashes ]) end
627+
628+ if not grid then
629+ gfx .setColor (darkMode and gfx .kColorBlack or gfx .kColorWhite )
630+ gfx .fillRect (
631+ offsetX * blockSize , offsetY * blockSize ,
632+ gridXCount * blockSize , gridYCount * blockSize
633+ )
634+ end
635+
621636 for i ,l in ipairs (lines ) do updateEffect (lines ,i ,l ) end
622637
623638 if not grid then
639+ gfx .setColor (darkMode and gfx .kColorWhite or gfx .kColorBlack )
624640 gfx .drawRect (
625641 offsetX * blockSize , offsetY * blockSize ,
626642 gridXCount * blockSize , gridYCount * blockSize
627643 )
628644 end
629645
646+ for i , l in ipairs (clearLines ) do updateEffect (clearLines ,i ,l ) end
647+
630648 for y = 1 , gridYCount do
631649 for x = 1 , gridXCount do
632650 drawBlock (inert [y ][x ], x + offsetX , y + offsetY , blockSize )
@@ -651,17 +669,13 @@ local function drawGame()
651669 end
652670 end )
653671
654- for i , l in ipairs (clearLines ) do updateEffect (clearLines ,i ,l ) end
655-
656672 gfx .setDrawOffset (0 ,0 )
657673
658674 drawHeldPiece ()
659675 drawNextPiece ()
660676 drawScores ()
661677 drawLevelInfo ()
662678
663- if # sashes > 0 then updateEffect (sashes , # sashes , sashes [# sashes ]) end
664-
665679 gfx .fillRect (0 , 0 , 400 , introRectT .value )
666680
667681 gfx .popContext ()
@@ -803,8 +817,8 @@ function updateMenu()
803817 menuScrollSound :play ()
804818 menuCursor += 1
805819 elseif btnp (" up" ) then
806- menuCursor -= 1
807820 menuScrollSound :play ()
821+ menuCursor -= 1
808822 end
809823 menuCursor %= # menu
810824
@@ -903,36 +917,47 @@ end
903917-- Playdate-related stuff --
904918---- ------------------------
905919
906- playdate .getSystemMenu ():addMenuItem (" options" , function ()
907- menuOpen = not menuOpen
908- if not menuOpen then closeMenu ()
909- else
910- bold = gfx .getSystemFont (" bold" )
911- menuYTimer = time .new (250 , 0 , dheight / 2 , easings .outBack )
912- menuHeight = # menu * bold :getHeight ()
913- local longestString = " "
914- for k , v in pairs (menu ) do
915- if # v .name > # longestString then
916- longestString = v .name
920+ local sysmenu = playdate .getSystemMenu ()
921+ sysmenu :addMenuItem (" options" , function ()
922+ if not lost then
923+ menuOpen = not menuOpen
924+ if not menuOpen then closeMenu ()
925+ else
926+ bold = gfx .getSystemFont (" bold" )
927+ menuYTimer = time .new (250 , 0 , dheight / 2 , easings .outBack )
928+ menuHeight = # menu * bold :getHeight ()
929+ local longestString = " "
930+ for k , v in pairs (menu ) do
931+ if # v .name > # longestString then
932+ longestString = v .name
933+ end
917934 end
918- end
919935
920- -- playdate.graphics.image:getSize() returns two values. By using it like this,
921- -- I am taking the first value and discarding the rest,
922- -- the first value being the width, which is what i need.
923- menuWidth = bold :getTextWidth (longestString ) + crossmarkFieldImage :getSize ()
924- menuCursor = 1
936+ -- playdate.graphics.image:getSize() returns two values. By using it like this,
937+ -- I am taking the first value and discarding the rest,
938+ -- the first value being the width, which is what i need.
939+ menuWidth = bold :getTextWidth (longestString ) + crossmarkFieldImage :getSize ()
940+ menuCursor = 1
941+
942+ backgroundImage = gfx .image .new (dwidth , dheight )
943+ gfx .pushContext (backgroundImage )
944+ drawGame ()
945+ gfx .popContext ()
925946
926- backgroundImage = gfx .image .new (dwidth , dheight )
927- gfx .pushContext (backgroundImage )
928- drawGame ()
929- gfx .popContext ()
947+ playdate .inputHandlers .pop ()
948+ patternTimer = time .new (250 , 1 , # patterns , easings .outBack )
949+ end
950+ _update = updateMenu
951+ _draw = drawMenu
952+ end
953+ end )
930954
931- playdate .inputHandlers .pop ()
932- patternTimer = time .new (250 , 1 , # patterns , easings .outBack )
955+ sysmenu :addMenuItem (" restart" , function ()
956+ if not lost and UITimer .timeLeft == 0 then
957+ addPieceToInertGrid ()
958+ lose ()
959+ commitSaveData ()
933960 end
934- _update = updateMenu
935- _draw = drawMenu
936961end )
937962
938963bgmIntro :play ()
0 commit comments