Made light toggle on/off
This commit is contained in:
@@ -3,7 +3,6 @@ local LoveNode = require 'src.utils.love_node'
|
||||
local light = require 'src.display.shaders.light'
|
||||
require 'src.utils.math'
|
||||
|
||||
|
||||
local Effects = {}
|
||||
Effects.__index = Effects
|
||||
|
||||
@@ -20,45 +19,61 @@ function Effects.new(game)
|
||||
.chain(moonshine.effects.glow)
|
||||
.chain(moonshine.effects.scanlines)
|
||||
|
||||
-- Disable effects
|
||||
-- self.effect.disable(
|
||||
-- 'light',
|
||||
-- 'scanlines'
|
||||
-- -- 'glow',
|
||||
-- -- 'filmgrain',
|
||||
-- -- 'chromasep'
|
||||
-- )
|
||||
|
||||
-- A copy of the effect params need to be stored since
|
||||
-- they can't be retrieved from Moonshine
|
||||
self.effects = {}
|
||||
self.effects.lightRadius = 15
|
||||
self.effects.minLightRadius = 10
|
||||
self.effects.maxLightRadius = 50
|
||||
self.effects.time = 0
|
||||
self.localEffect = {}
|
||||
self.localEffect.light = {}
|
||||
self.localEffect.light.isOn = false
|
||||
self.localEffect.light.radius = 10
|
||||
self.localEffect.light.targetRadius = 10
|
||||
self.localEffect.light.minRadius = 10
|
||||
self.localEffect.light.maxRadius = 50
|
||||
self.localEffect.time = 0
|
||||
|
||||
-- Effect parameters
|
||||
self.effect.filmgrain.size = 1
|
||||
self.effect.chromasep.radius = 1
|
||||
self.effect.scanlines.opacity = 0.95
|
||||
self.effect.glow.strength = 10
|
||||
self.effect.light.lightRadius = self.effects.lightRadius
|
||||
self.effect.light.lightRadius = self.localEffect.light.radius
|
||||
self.effect.light.time = 0
|
||||
|
||||
return self
|
||||
end
|
||||
|
||||
function Effects:update(dt)
|
||||
-- Update player position
|
||||
self.localEffect.time = (dt + self.localEffect.time) % 100 -- Mod 100 to keep the number relatively small
|
||||
|
||||
self.effect.light.playerPos = { self.game.camera:toScreen(self.game.player:getCenter()) }
|
||||
|
||||
-- Update light radius
|
||||
local lightInput = self:_getLightInput()
|
||||
self.effects.lightRadius = math.clamp(
|
||||
self.effects.lightRadius + (lightInput * 30 * dt),
|
||||
self.effects.minLightRadius,
|
||||
self.effects.maxLightRadius
|
||||
)
|
||||
self.effect.light.lightRadius = self.effects.lightRadius
|
||||
self.effects.time = (dt + self.effects.time) % 100
|
||||
self.effect.light.time = self.effects.time
|
||||
self:_updateLightShader()
|
||||
end
|
||||
|
||||
function Effects:_getLightInput()
|
||||
local increaseLight = self.game.input:down 'increaseLight' and 1 or 0
|
||||
local decreaseLight = self.game.input:down 'decreaseLight' and -1 or 0
|
||||
return increaseLight + decreaseLight
|
||||
function Effects:_updateLightShader()
|
||||
-- Toggle light on/off
|
||||
if (self.game.input:pressed 'action') then
|
||||
self.localEffect.light.isOn = not self.localEffect.light.isOn
|
||||
if (self.localEffect.light.isOn) then
|
||||
self.localEffect.light.targetRadius = self.localEffect.light.maxRadius
|
||||
else
|
||||
self.localEffect.light.targetRadius = self.localEffect.light.minRadius
|
||||
end
|
||||
end
|
||||
|
||||
-- Tween current light radius to target radius (based on on/off status)
|
||||
Flux.to(self.localEffect.light, 0.5, { radius = self.localEffect.light.targetRadius })
|
||||
self.effect.light.lightRadius = self.localEffect.light.radius
|
||||
|
||||
self.effect.light.time = self.localEffect.time
|
||||
end
|
||||
|
||||
function Effects:render(fn)
|
||||
|
||||
Reference in New Issue
Block a user