-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.lua
33 lines (27 loc) · 869 Bytes
/
score.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import "CoreLibs/sprites.lua"
import "CoreLibs/graphics.lua"
local gfx = playdate.graphics
class('Score').extends(playdate.graphics.sprite)
function Score:init()
Score.super.init(self)
self.scoreFont = gfx.font.new('ditheredScore.pft')
self:setCenter(0.5,0)
self:setSize(57,32)
self:setScore(0)
self:addSprite()
end
function Score:setScore(newNumber)
self.score = newNumber
gfx.setFont(self.scoreFont)
self:markDirty()
end
function Score:draw(x, y, width, height)
gfx.setColor(gfx.kColorWhite)
gfx.setBackgroundColor(gfx.kColorBlack)
gfx.setFont(self.scoreFont)
gfx.setImageDrawMode(gfx.kDrawModeFillWhite)
local scoreText = self.score
if type(scoreText) == "number" and scoreText < 10 then scoreText = " "..scoreText end
gfx.drawText(scoreText, 0,0)
gfx.setBackgroundColor(gfx.kColorBlack)
end