diff --git a/data/scripts/entities/fairy.lua b/data/scripts/entities/fairy.lua index 0fb652b..5497a1b 100644 --- a/data/scripts/entities/fairy.lua +++ b/data/scripts/entities/fairy.lua @@ -14,7 +14,7 @@ Fairy = Entity:New(x,y) o:getBoundingBox(o.body) - o.lightRange = 55 + o.lightRange = 0 o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange) table.insert(LoadedEntities,o) @@ -46,7 +46,8 @@ function Fairy:Smart() local particle_data = { animation = animation.particle.fairy, direction = angle-math.rad(180), - speed = self.speed*distance/(16*game.scale) + speed = self.speed*distance/(16*game.scale), + light = 85 } Particle:New(self.pos.x,self.pos.y,particle_data) diff --git a/data/scripts/entities/particle.lua b/data/scripts/entities/particle.lua index fa79f0f..adc8292 100644 --- a/data/scripts/entities/particle.lua +++ b/data/scripts/entities/particle.lua @@ -25,6 +25,11 @@ Particle = Entity:New(x,y) y = o.speed * math.sin(o.direction) } + if particle_data.light ~= nil then + o.lightRange = particle_data.light + o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange) + end + -- animations o.body = Animation:New(particle_data.animation) o:centerOffset(o.body) @@ -41,6 +46,9 @@ Particle = Entity:New(x,y) end function Particle:Kill() + if self.light ~= nil then + KillLight(self.light) + end if self.id ~= nil then for _, e in pairs(LoadedParticles) do if e.id > self.id then @@ -56,6 +64,9 @@ function Particle:HandleAnimation() self.body:Animate() self.timer = self.timer + current_dt self.sprite_alpha = (self.time-self.timer)/self.time + if self.light ~= nil then + self.light.range = self.lightRange * self.sprite_alpha/2 + end if self.sprite_alpha < 0 then self:Kill() end self:Draw(self.body) end diff --git a/data/scripts/entity.lua b/data/scripts/entity.lua index 54f4192..f60ba14 100644 --- a/data/scripts/entity.lua +++ b/data/scripts/entity.lua @@ -32,6 +32,9 @@ function Entity:Smart() end function Entity:Kill() + if self.light ~= nil then + KillLight(self.light) + end if self.id ~= nil then for _, e in pairs(LoadedEntities) do if e.id > self.id then diff --git a/data/scripts/lights.lua b/data/scripts/lights.lua index 0e81773..2c01afd 100644 --- a/data/scripts/lights.lua +++ b/data/scripts/lights.lua @@ -19,10 +19,22 @@ function CreateLight(x,y,range,lum,flicker) o.flicker_speed = flicker_speed or 60/12 o.flicker_time = 0 table.insert(Lights,o) - + o.id = #Lights return o end +function KillLight(light) + if light.id ~= nil then + for _, e in pairs(Lights) do + if e.id > light.id then + e.id = e.id - 1 + end + end + table.remove(Lights,light.id) + end + light = nil +end + function SetDarkness() love.graphics.setColor(0,0,0,1) love.graphics.rectangle("fill",0,0,game.width ,game.height)