51 lines
1.4 KiB
Lua
51 lines
1.4 KiB
Lua
---@class ExplodeParticle:GameObject
|
|
---@field color table
|
|
---@field r number
|
|
---@field s number
|
|
---@field v number
|
|
---@field lw number
|
|
local ExplodeParticle = GameObject:extend()
|
|
|
|
function ExplodeParticle:new(area, x, y, opts)
|
|
ExplodeParticle.super.new(self, area, x, y, opts)
|
|
-- particle effect's color
|
|
self.color = opts.color or COLORS.default
|
|
-- particle angle
|
|
self.r = random(0, 2*math.pi)
|
|
-- scale
|
|
self.s = opts.s or random(2,3)
|
|
-- velocity
|
|
self.v = opts.v or random(75, 150)
|
|
-- line width
|
|
self.lw = opts.lw or 2
|
|
|
|
self.timer:tween(
|
|
opts.d or random(.3,.5),
|
|
self, {s = 0, v = 0, lw = 0},
|
|
'linear',
|
|
function() self:kill() end
|
|
)
|
|
end
|
|
|
|
---Updates ExplodeParticle
|
|
---@param dt number delta time
|
|
function ExplodeParticle:update(dt)
|
|
ExplodeParticle.super.update(self, dt)
|
|
self.x = self.x + self.v*math.cos(self.r)*dt
|
|
self.y = self.y + self.v*math.sin(self.r)*dt
|
|
--self.r = self.r + self.v*dt
|
|
end
|
|
|
|
---Draws ExplodeParticle
|
|
function ExplodeParticle:draw()
|
|
ExplodeParticle.super.draw(self)
|
|
pushRotateScale(self.x, self.y, self.r)
|
|
love.graphics.setColor(self.color)
|
|
love.graphics.setLineWidth(self.lw)
|
|
love.graphics.line(self.x - self.s, self.y, self.x + self.s, self.y)
|
|
love.graphics.setLineWidth(1)
|
|
love.graphics.setColor(COLORS.default)
|
|
love.graphics.pop()
|
|
end
|
|
|
|
return ExplodeParticle
|