From d20e5392f8595b5e084d914edfe7c35478462a0e Mon Sep 17 00:00:00 2001 From: lustlion Date: Thu, 17 Mar 2022 00:39:47 +0100 Subject: [PATCH] Decoration now acts as parent for specific decorations better. added candelabra decoration. --- code/entities/decoration.lua | 25 +++++------ code/entities/decorations/candelabra.lua | 55 ++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 12 deletions(-) create mode 100644 code/entities/decorations/candelabra.lua diff --git a/code/entities/decoration.lua b/code/entities/decoration.lua index 8f6bb53..9d42f93 100644 --- a/code/entities/decoration.lua +++ b/code/entities/decoration.lua @@ -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" diff --git a/code/entities/decorations/candelabra.lua b/code/entities/decorations/candelabra.lua new file mode 100644 index 0000000..80eb95f --- /dev/null +++ b/code/entities/decorations/candelabra.lua @@ -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