55 lines
1.3 KiB
Lua
55 lines
1.3 KiB
Lua
SmokeCloud = {}
|
|
class('SmokeCloud').extends(playdate.graphics.sprite)
|
|
|
|
function SmokeCloud:init(x, y)
|
|
SmokeCloud.super.init(self)
|
|
|
|
self.radius = 25
|
|
self.maxLife = 150
|
|
self.life = self.maxLife
|
|
|
|
local size = self.radius * 2 + 4
|
|
self:setSize(size, size)
|
|
self:setCenter(0.5, 0.5)
|
|
self:setZIndex(ZIndex.fx - 1)
|
|
self:moveTo(x, y)
|
|
self:add()
|
|
self:markDirty()
|
|
end
|
|
|
|
function SmokeCloud:update()
|
|
if not BomberScene.instance then
|
|
self:remove()
|
|
return
|
|
end
|
|
|
|
self:moveBy(0, BomberScene.instance.scrollSpeed)
|
|
self.life = self.life - 1
|
|
|
|
if self.life <= 0 or self.y > 280 then
|
|
self:remove()
|
|
return
|
|
end
|
|
|
|
self:markDirty()
|
|
end
|
|
|
|
function SmokeCloud:draw()
|
|
local t = self.life / self.maxLife
|
|
local r = self.radius * t
|
|
local cx = self.width / 2
|
|
local cy = self.height / 2
|
|
|
|
local dither = playdate.graphics.image.kDitherTypeBayer4x4
|
|
if t < 0.3 then
|
|
dither = playdate.graphics.image.kDitherTypeBayer8x8
|
|
elseif t < 0.6 then
|
|
dither = playdate.graphics.image.kDitherTypeBayer4x4
|
|
end
|
|
|
|
playdate.graphics.setColor(playdate.graphics.kColorBlack)
|
|
playdate.graphics.setDitherPattern(1 - t * 0.6, dither)
|
|
playdate.graphics.fillCircleAtPoint(cx, cy, r)
|
|
playdate.graphics.setColor(playdate.graphics.kColorBlack)
|
|
end
|