bytepath/obj/game/ShootEffect.lua

31 lines
933 B
Lua

---@class ShootEffect:GameObject
---@field player Player|nil
---@field d number
local ShootEffect = GameObject:extend()
function ShootEffect:new(area, x, y, opts)
ShootEffect.super.new(self, area, x, y, opts)
self.w = 8
self.timer:tween(0.4, self, {w = 0}, 'in-out-cubic', function() self:kill() end)
end
---Updates ShootEffect
---@param dt number delta time
function ShootEffect:update(dt)
ShootEffect.super.update(self, dt)
if self.player then
self.x = self.player.x + self.d*math.cos(self.player.r)
self.y = self.player.y + self.d*math.sin(self.player.r)
end
end
---Draws ShootEffect
function ShootEffect:draw()
ShootEffect.super.draw(self)
pushRotateScale(self.x, self.y, self.player.r+math.pi/4)
love.graphics.setColor(COLORS.default)
love.graphics.rectangle('fill', self.x - self.w/2, self.y - self.w/2, self.w, self.w)
love.graphics.pop()
end
return ShootEffect