Created Particles, added fairy particle, added more entity methods like kill() and entity id

This commit is contained in:
lustlion
2022-01-19 23:29:02 +01:00
parent 15e8142c4c
commit 50f126fa7b
77 changed files with 106 additions and 26 deletions

View File

@@ -0,0 +1,48 @@
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