Mothback/data/scripts/entities/particle.lua

49 lines
1.1 KiB
Lua

Particle = Entity:New(x,y)
function Particle:New(x,y,animation,rotation,speed)
local o = Entity:New(x,y)
o.pos = {x = x, y = y}
o.speed = speed or 0
o.sprite_rotation = rotation or 0
o.time = 0.5
o.timer = 0
o.vel = {
x = o.speed * math.cos(o.sprite_rotation),
y = o.speed * math.sin(o.sprite_rotation)
}
-- animations
o.body = Animation:New(animation)
table.insert(LoadedEntities,o)
o.id = #LoadedEntities
setmetatable(o, self)
self.__index = self
return o
end
function Particle:Smart()
end
function Particle:HandleAnimation()
self.body:Animate()
self.timer = self.timer + current_dt
self.sprite_alpha = (self.time-self.timer)/self.time
if self.sprite_alpha < 0 then self:Kill() end
self:Draw(self.body)
end
function Particle:DoPhysics()
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, objects.collisions) then
self.pos.x = self.pos.x + self.vel.x
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, objects.collisions) then
self.pos.y = self.pos.y + self.vel.y
end
end