Decoration now acts as parent for specific decorations better.

added candelabra decoration.
This commit is contained in:
lustlion 2022-03-17 00:39:47 +01:00
parent d359afaf97
commit d20e5392f8
2 changed files with 68 additions and 12 deletions

View File

@ -1,20 +1,22 @@
Decoration = Entity:new()
Decoration = {}
Decoration.type = "Decoration"
Decoration.display = nil
Decoration.supertype = Entity.type
Decoration.display = Animation:new(animation.particle.simple)
setmetatable(Decoration, Entity)
function Decoration:new(x,y,animation,light_radius)
function Decoration:new(x,y,animation,light_data)
local o = Entity:new(x,y)
o.pos = {x = x, y = y}
-- animations
o.body = Animation:new(animation)
o:centerOffset(o.body)
o:createBox(o.body)
if animation then
o.body = Animation:new(animation)
o:centerOffset(o.body)
o:createBox(o.body)
end
if light_radius ~= nil then
o.light_radius = light_radius
o.light = Light:new(o.pos.x,o.pos.y,o.light_radius)
if light_data then
o.light = Light:new(o.pos.x,o.pos.y,light_data)
end
o:id()
@ -29,5 +31,4 @@ function Decoration:handleAnimation()
self:draw(self.body)
end
function Decoration:doPhysics()
end
require "code/entities/decorations/candelabra"

View File

@ -0,0 +1,55 @@
Candelabra = {}
Candelabra.type = "Candelabra"
Candelabra.supertype = Decoration.type
Candelabra.display = Animation:new(animation.decoration.candelabra)
setmetatable(Candelabra, Decoration)
function Candelabra:new(x,y)
local light_data = {}
light_data.radius = 100
light_data.color = hex2rgb("#fed100")
local o = Decoration:new(x,y,animation.decoration.candelabra,light_data)
o.particle_rate = 5
o.particle_count = 0
setmetatable(o, self)
self.__index = self
return o
end
function Candelabra:handleAnimation()
if self.body.was_updated then
self.particle_count = self.particle_count + 1
while self.particle_count >= self.particle_rate do
local pos = math.floor(math.random(1,3))-2
local particle_data = {}
particle_data.animation = animation.particle.simple
particle_data.sprite_tint = hex2rgb("#ffffff")
particle_data.sprite_alpha_fade = true
particle_data.direction = -math.rad(90)
particle_data.speed = 0.5 + math.random(2)*0.005
particle_data.time = 0.5+math.random(0.5)
particle_data.animation_speed = 1/particle_data.time
particle_data.func = function(self)
--COSINE WAVE FUNCTION
--init variables and constants
self.t = self.t or 0
self.phase = self.phase or math.random(2*math.pi)
local dt = 0.5
local amplitude = 0.5
local frequency = 0.5/game.framerate
--calc
self.t = self.t + dt
self:moveX(amplitude*math.cos(2*math.pi*frequency*self.t+self.phase))
end
Particle:new(self.pos.x+pos*5,self.pos.y-3,particle_data)
self.particle_count = self.particle_count - self.particle_rate
end
end
Decoration.handleAnimation(self)
end