Fairy lights
This commit is contained in:
parent
2d8b8a23db
commit
ed9873d633
|
@ -14,7 +14,7 @@ Fairy = Entity:New(x,y)
|
||||||
o:getBoundingBox(o.body)
|
o:getBoundingBox(o.body)
|
||||||
|
|
||||||
|
|
||||||
o.lightRange = 55
|
o.lightRange = 0
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
table.insert(LoadedEntities,o)
|
table.insert(LoadedEntities,o)
|
||||||
|
@ -46,7 +46,8 @@ function Fairy:Smart()
|
||||||
local particle_data = {
|
local particle_data = {
|
||||||
animation = animation.particle.fairy,
|
animation = animation.particle.fairy,
|
||||||
direction = angle-math.rad(180),
|
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)
|
Particle:New(self.pos.x,self.pos.y,particle_data)
|
||||||
|
|
|
@ -25,6 +25,11 @@ Particle = Entity:New(x,y)
|
||||||
y = o.speed * math.sin(o.direction)
|
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
|
-- animations
|
||||||
o.body = Animation:New(particle_data.animation)
|
o.body = Animation:New(particle_data.animation)
|
||||||
o:centerOffset(o.body)
|
o:centerOffset(o.body)
|
||||||
|
@ -41,6 +46,9 @@ Particle = Entity:New(x,y)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Particle:Kill()
|
function Particle:Kill()
|
||||||
|
if self.light ~= nil then
|
||||||
|
KillLight(self.light)
|
||||||
|
end
|
||||||
if self.id ~= nil then
|
if self.id ~= nil then
|
||||||
for _, e in pairs(LoadedParticles) do
|
for _, e in pairs(LoadedParticles) do
|
||||||
if e.id > self.id then
|
if e.id > self.id then
|
||||||
|
@ -56,6 +64,9 @@ function Particle:HandleAnimation()
|
||||||
self.body:Animate()
|
self.body:Animate()
|
||||||
self.timer = self.timer + current_dt
|
self.timer = self.timer + current_dt
|
||||||
self.sprite_alpha = (self.time-self.timer)/self.time
|
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
|
if self.sprite_alpha < 0 then self:Kill() end
|
||||||
self:Draw(self.body)
|
self:Draw(self.body)
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,6 +32,9 @@ function Entity:Smart()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:Kill()
|
function Entity:Kill()
|
||||||
|
if self.light ~= nil then
|
||||||
|
KillLight(self.light)
|
||||||
|
end
|
||||||
if self.id ~= nil then
|
if self.id ~= nil then
|
||||||
for _, e in pairs(LoadedEntities) do
|
for _, e in pairs(LoadedEntities) do
|
||||||
if e.id > self.id then
|
if e.id > self.id then
|
||||||
|
|
|
@ -19,10 +19,22 @@ function CreateLight(x,y,range,lum,flicker)
|
||||||
o.flicker_speed = flicker_speed or 60/12
|
o.flicker_speed = flicker_speed or 60/12
|
||||||
o.flicker_time = 0
|
o.flicker_time = 0
|
||||||
table.insert(Lights,o)
|
table.insert(Lights,o)
|
||||||
|
o.id = #Lights
|
||||||
return o
|
return o
|
||||||
end
|
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()
|
function SetDarkness()
|
||||||
love.graphics.setColor(0,0,0,1)
|
love.graphics.setColor(0,0,0,1)
|
||||||
love.graphics.rectangle("fill",0,0,game.width ,game.height)
|
love.graphics.rectangle("fill",0,0,game.width ,game.height)
|
||||||
|
|
Loading…
Reference in New Issue