Skip to content

Commit 55a7214

Browse files
authored
Rest of 1.5.1
1 parent b076fd9 commit 55a7214

File tree

2 files changed

+74
-49
lines changed

2 files changed

+74
-49
lines changed

effects/sash.lua

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ function Sash:init(text)
2525
self.text = text
2626

2727
-- haha bad code go brr
28-
self.heightTimer = Timer(125, 0, 40, ease.outBack)
29-
self.heightTimer.discardOnCompletion = false
28+
self.yTimer = Timer(125, 0, 40, ease.outBack)
29+
self.yTimer.discardOnCompletion = false
3030
local textWidth = gfx.getSystemFont("bold"):getTextWidth(text)
31-
setTimerEndCallback(self.heightTimer, function()
32-
self.textPosTimer = Timer(250, -textWidth, dwidth/2-textWidth/2, ease.outCubic)
31+
setTimerEndCallback(self.yTimer, function()
32+
self.textPosTimer = Timer(250, -textWidth, 10+textWidth/2, ease.outCubic)
3333
setTimerEndCallback(self.textPosTimer, function()
3434
timer.performAfterDelay(500, function()
35-
self.textPosTimer = Timer(250, dwidth/2-textWidth/2, dwidth, ease.inCubic)
35+
self.textPosTimer = Timer(250, 10+textWidth/2, dwidth, ease.inCubic)
3636
setTimerEndCallback(self.textPosTimer, function()
37-
self.heightTimer = Timer(250, 40, 0, ease.inBack)
38-
setTimerEndCallback(self.heightTimer, function() self.dead = true end)
37+
self.yTimer = Timer(250, 40, 0, ease.inBack)
38+
setTimerEndCallback(self.yTimer, function() self.dead = true end)
3939
end)
4040
end)
4141
end)
@@ -46,12 +46,12 @@ function Sash:update() end
4646

4747
function Sash:draw()
4848
gfx.pushContext()
49-
if self.heightTimer then
50-
gfx.fillRect(0, 0, dwidth, self.heightTimer.value)
49+
if self.yTimer then
50+
gfx.fillRect(0, (dheight-self.yTimer.value)-5, dwidth, gfx.getSystemFont("bold"):getHeight()*2)
5151
end
5252
if self.textPosTimer then
5353
gfx.setImageDrawMode(darkMode and "fillBlack" or "fillWhite")
54-
gfx.drawText("*"..self.text.."*", self.textPosTimer.value, gfx.getSystemFont("bold"):getHeight()/2)
54+
gfx.drawText("*"..self.text.."*", self.textPosTimer.value, (dheight-gfx.getSystemFont("bold"):getHeight()*1.5)-5)
5555
end
5656
gfx.popContext()
5757
end

main.lua

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ end
307307

308308
local 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
372376
end
373377

@@ -391,6 +395,13 @@ end
391395

392396
reset()
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+
394405
local 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
549555
end
550556

551-
552557
local 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
936961
end)
937962

938963
bgmIntro:play()

0 commit comments

Comments
 (0)