Optimize text boxes, tune difficulty, add brick marching.
This commit is contained in:
parent
ffc44093f4
commit
e3cf1f7b1b
|
@ -19,7 +19,7 @@ function Ball:init(width, height, color, x, y)
|
|||
end
|
||||
|
||||
function Ball:levelUpTimer()
|
||||
playdate.timer.performAfterDelay(5000,
|
||||
playdate.timer.performAfterDelay(25000,
|
||||
function(ball)
|
||||
if ball.direction.x > 0 then
|
||||
ball.direction.x += 1
|
||||
|
|
27
src/main.lua
27
src/main.lua
|
@ -35,11 +35,11 @@ function setup()
|
|||
addWallColliders()
|
||||
setupBricks()
|
||||
|
||||
timeWidget = TextBox(100, 20, 350, 10, 5, kTextAlignment.center)
|
||||
timeWidget = TextBox("", 100, 20, 350, 10, 5, kTextAlignment.center)
|
||||
updateTimeWidget()
|
||||
timeWidget:add()
|
||||
|
||||
speedWidget = TextBox(100, 20, 50, 10, 5, kTextAlignment.center)
|
||||
speedWidget = TextBox("", 100, 20, 50, 10, 5, kTextAlignment.center)
|
||||
updateSpeedWidget()
|
||||
speedWidget:add()
|
||||
|
||||
|
@ -73,9 +73,11 @@ end
|
|||
|
||||
function setupBricks()
|
||||
for i=1,12 do
|
||||
addBrickRow()
|
||||
advanceBricks()
|
||||
addBrickRow()
|
||||
end
|
||||
|
||||
addBrickTimer()
|
||||
end
|
||||
|
||||
function addBrickRow()
|
||||
|
@ -150,15 +152,22 @@ function moveBall()
|
|||
end
|
||||
end
|
||||
|
||||
function addBrickTimer()
|
||||
playdate.timer.performAfterDelay(20000,
|
||||
function()
|
||||
advanceBricks()
|
||||
addBrickRow()
|
||||
addBrickTimer()
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
function endGame()
|
||||
endTime = playdate.getElapsedTime()
|
||||
|
||||
local textBox = TextBox(275, 40, 200, 120, 5, kTextAlignment.center)
|
||||
textBox:setText(
|
||||
"Game Over!\nYou survived for " ..
|
||||
string.format("%.2f", endTime) ..
|
||||
" seconds.\n Press 'A' to play again."
|
||||
)
|
||||
local t = string.format("Game Over!\nYou survived for %.2f seconds.\nPress 'A' to play again.", endTime)
|
||||
local textBox = TextBox(t, 275, 40, 200, 120,
|
||||
5, kTextAlignment.center)
|
||||
textBox:add()
|
||||
end
|
||||
|
||||
|
|
|
@ -8,25 +8,38 @@ local defaultFont = gfx.font.new("fonts/Mini Mono")
|
|||
|
||||
class("TextBox").extends(gfx.sprite)
|
||||
|
||||
function TextBox:init(w, h, x, y, vert, align, font)
|
||||
-- text - the initial text to display
|
||||
-- w, h - width and height of the text box
|
||||
-- x, y - initial position for the text box (center)
|
||||
-- vert - vertical offset for the text (from the top of the box)
|
||||
-- align - text alignment
|
||||
-- font - font (defaults to Mini Mono)
|
||||
function TextBox:init(text, w, h, x, y, vert, align, font)
|
||||
TextBox.super.init(self)
|
||||
|
||||
self.text = text
|
||||
self:setSize(w, h)
|
||||
self:moveTo(x, y)
|
||||
self:setZIndex(999)
|
||||
self.vert = vert or 0
|
||||
self.align = align or kTextAlignment.left
|
||||
self.font = font or defaultFont
|
||||
self.vert = vert
|
||||
self.text = ""
|
||||
|
||||
self:setZIndex(999)
|
||||
self:drawStatic()
|
||||
end
|
||||
|
||||
function TextBox:setText(text)
|
||||
self.text = text
|
||||
self:drawStatic()
|
||||
end
|
||||
|
||||
function TextBox:draw(x, y, w, h)
|
||||
gfx.pushContext()
|
||||
|
||||
function TextBox:drawStatic()
|
||||
local img = gfx.image.new(self:getSize())
|
||||
local x = 0
|
||||
local y = 0
|
||||
local w = self.width
|
||||
local h = self.height
|
||||
gfx.pushContext(img)
|
||||
gfx.setColor(gfx.kColorWhite)
|
||||
gfx.fillRect(x, y, w, h)
|
||||
gfx.setColor(gfx.kColorBlack)
|
||||
|
@ -37,7 +50,21 @@ function TextBox:draw(x, y, w, h)
|
|||
self.text,
|
||||
x, y+self.vert, w, h, nil, nil, self.align
|
||||
)
|
||||
|
||||
gfx.popContext()
|
||||
self:setImage(img)
|
||||
end
|
||||
|
||||
-- draw the textbox. This is in a sub-function so we can change the context
|
||||
-- depending on static-ness
|
||||
function TextBox:subDraw(x, y, w, h)
|
||||
gfx.setColor(gfx.kColorWhite)
|
||||
gfx.fillRect(x, y, w, h)
|
||||
gfx.setColor(gfx.kColorBlack)
|
||||
gfx.drawRoundRect(x, y, w, h, 2)
|
||||
|
||||
gfx.setFont(self.font)
|
||||
gfx.drawTextInRect(
|
||||
self.text,
|
||||
x, y+self.vert, w, h, nil, nil, self.align
|
||||
)
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user