Rehandled Darkness and Lights. Refactored lots of stuff. Rewritten shaders.
This commit is contained in:
parent
192b1e6ca0
commit
a944192f67
|
@ -1,4 +1,10 @@
|
||||||
Collision = {}
|
Collision = {}
|
||||||
|
|
||||||
|
LoadedObjects.Collisions = {}
|
||||||
|
LoadedObjects.Platforms = {}
|
||||||
|
LoadedObjects.Ladders = {}
|
||||||
|
LoadedObjects.Hazards = {}
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Collision
|
Collision
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,44 @@
|
||||||
|
Darkness = {}
|
||||||
|
Canvas = {}
|
||||||
|
|
||||||
|
function Darkness.Create()
|
||||||
|
Darkness.width = game.width/game.scale
|
||||||
|
Darkness.height = game.height/game.scale
|
||||||
|
Canvas.Darkness = love.graphics.newCanvas(
|
||||||
|
Darkness.width,
|
||||||
|
Darkness.height
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Darkness.Recreate()
|
||||||
|
Canvas.Darkness:release()
|
||||||
|
Darkness.Create()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Darkness.Reset()
|
||||||
|
love.graphics.setCanvas(Canvas.Darkness)
|
||||||
|
love.graphics.setBlendMode("replace")
|
||||||
|
love.graphics.setColor(0.1,0.1,0.1,1)
|
||||||
|
love.graphics.rectangle(
|
||||||
|
"fill",
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
Darkness.width,
|
||||||
|
Darkness.height
|
||||||
|
)
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Darkness.DrawStart()
|
||||||
|
Darkness.Reset()
|
||||||
|
love.graphics.setCanvas(Canvas.Darkness)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Darkness.DrawEnd()
|
||||||
|
love.graphics.setCanvas()
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
love.graphics.setColor(1,1,1,1)
|
||||||
|
love.graphics.draw(Canvas.Darkness)
|
||||||
|
end
|
||||||
|
|
||||||
|
Darkness.Create()
|
|
@ -1,6 +1,6 @@
|
||||||
function DebugUI()
|
function DebugUI()
|
||||||
local mouse_x, mouse_y = love.mouse.getPosition()
|
local mouse_x, mouse_y = love.mouse.getPosition()
|
||||||
for _, light in pairs(Lights) do
|
for _, light in pairs(LoadedObjects.Lights) do
|
||||||
love.graphics.print(light.pos.x,light.pos.x,light.pos.y)
|
love.graphics.print(light.pos.x,light.pos.x,light.pos.y)
|
||||||
love.graphics.print(light.pos.y,light.pos.x,light.pos.y+20)
|
love.graphics.print(light.pos.y,light.pos.x,light.pos.y+20)
|
||||||
love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40)
|
love.graphics.print(light.pos.x,light.pos.x,light.pos.y+40)
|
||||||
|
|
|
@ -27,7 +27,7 @@ CursedBook = Entity:New(x,y)
|
||||||
|
|
||||||
-- light
|
-- light
|
||||||
o.light_range = 500
|
o.light_range = 500
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
|
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,2,HEX2RGB("#fe00d1"))
|
||||||
|
|
||||||
table.insert(LoadedObjects.Entities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedObjects.Entities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
|
@ -14,7 +14,7 @@ function Decoration:New(x,y,animation,lightRange)
|
||||||
|
|
||||||
if lightRange ~= nil then
|
if lightRange ~= nil then
|
||||||
o.lightRange = lightRange
|
o.lightRange = lightRange
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(LoadedObjects.Entities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
|
|
|
@ -20,7 +20,7 @@ Fairy = Entity:New(x,y)
|
||||||
|
|
||||||
-- light
|
-- light
|
||||||
o.light_range = 80
|
o.light_range = 80
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
|
o.light = Light:New(o.pos.x,o.pos.y,o.light_range,nil,HEX2RGB("#fed100"))
|
||||||
|
|
||||||
-- timer
|
-- timer
|
||||||
o.particle_timer = 0
|
o.particle_timer = 0
|
||||||
|
|
|
@ -27,6 +27,8 @@ function HookAnchor:HandleAnimation()
|
||||||
end
|
end
|
||||||
|
|
||||||
function HookAnchor:DrawBackground()
|
function HookAnchor:DrawBackground()
|
||||||
|
Entity.DrawBackground(self)
|
||||||
|
love.graphics.setColor(1,1,1,1)
|
||||||
love.graphics.circle(
|
love.graphics.circle(
|
||||||
"line",
|
"line",
|
||||||
-Camera.pos.x + self.pos.x,
|
-Camera.pos.x + self.pos.x,
|
||||||
|
|
|
@ -28,7 +28,7 @@ Kupo = Entity:New(x,y)
|
||||||
o.hostile = true
|
o.hostile = true
|
||||||
|
|
||||||
o.lightRange = o.range/2
|
o.lightRange = o.range/2
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
table.insert(LoadedObjects.Entities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedObjects.Entities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Particle = Entity:New(x,y)
|
Particle = Entity:New(x,y)
|
||||||
|
LoadedObjects.Particles = {}
|
||||||
|
|
||||||
function Particle:New(x,y,particle_data)
|
function Particle:New(x,y,particle_data)
|
||||||
local o = Entity:New(x,y)
|
local o = Entity:New(x,y)
|
||||||
|
@ -31,7 +32,7 @@ Particle = Entity:New(x,y)
|
||||||
o.lightRange = particle_data.light
|
o.lightRange = particle_data.light
|
||||||
local flicker = particle_data.light_flicker or nil
|
local flicker = particle_data.light_flicker or nil
|
||||||
local color = particle_data.light_color or nil
|
local color = particle_data.light_color or nil
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange,flicker,color)
|
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange,flicker,color)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- animations
|
-- animations
|
||||||
|
@ -44,8 +45,8 @@ Particle = Entity:New(x,y)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(LoadedParticles,o)
|
table.insert(LoadedObjects.Particles,o)
|
||||||
o.id = #LoadedParticles
|
o.id = #LoadedObjects.Particles
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
to = {x = 8, y = 0} -- gameworld pixels
|
to = {x = 8, y = 0} -- gameworld pixels
|
||||||
}
|
}
|
||||||
|
|
||||||
o.lightRange = 10 -- screen pixels
|
o.lightRange = 40 -- screen pixels
|
||||||
|
|
||||||
-- status
|
-- status
|
||||||
o.isDashing = false
|
o.isDashing = false
|
||||||
|
@ -66,7 +66,7 @@
|
||||||
o:getBoundingBox(o.body,0,3,-1,-3)
|
o:getBoundingBox(o.body,0,3,-1,-3)
|
||||||
|
|
||||||
-- lights
|
-- lights
|
||||||
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
o.light = Light:New(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
table.insert(LoadedObjects.Entities,o)
|
table.insert(LoadedObjects.Entities,o)
|
||||||
o.id = #LoadedObjects.Entities
|
o.id = #LoadedObjects.Entities
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
Entity = {class = "Entity"}
|
Entity = {class = "Entity"}
|
||||||
|
LoadedObjects.Entities = {}
|
||||||
|
|
||||||
function Entity:New(x,y)
|
function Entity:New(x,y)
|
||||||
o = {}
|
o = {}
|
||||||
|
@ -250,7 +251,9 @@ function Entity:Debug()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Entity:DrawBackground()
|
function Entity:DrawBackground()
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
require "code/entities/kupo"
|
require "code/entities/kupo"
|
||||||
require "code/entities/arrow"
|
require "code/entities/arrow"
|
||||||
require "code/entities/decoration"
|
require "code/entities/decoration"
|
||||||
|
|
|
@ -9,7 +9,7 @@ function GameStep()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, particle in pairs(LoadedParticles) do
|
for _, particle in pairs(LoadedObjects.Particles) do
|
||||||
particle:DoPhysics()
|
particle:DoPhysics()
|
||||||
end
|
end
|
||||||
for _, enty in pairs(LoadedObjects.Entities) do
|
for _, enty in pairs(LoadedObjects.Entities) do
|
||||||
|
@ -68,19 +68,21 @@ function GameDraw()
|
||||||
|
|
||||||
-- prepare
|
-- prepare
|
||||||
GameworldDrawPrepare()
|
GameworldDrawPrepare()
|
||||||
|
GameWorldUpdateLights()
|
||||||
|
|
||||||
-- background
|
-- background
|
||||||
GameworldDrawBackground()
|
GameworldDrawBackground()
|
||||||
|
GameworldDrawLights()
|
||||||
GameworldDrawEntitiesBackground()
|
GameworldDrawEntitiesBackground()
|
||||||
|
|
||||||
-- foreground
|
-- foreground
|
||||||
GameworldDrawForeground()
|
GameworldDrawForeground()
|
||||||
if LevelData.properties.darkness then
|
|
||||||
GameworldDrawLighting()
|
|
||||||
end
|
|
||||||
GameworldDrawParticles()
|
GameworldDrawParticles()
|
||||||
GameworldDrawEntities()
|
GameworldDrawEntities()
|
||||||
|
|
||||||
|
if LevelData.properties.darkness then
|
||||||
|
GameworldDrawDarkness()
|
||||||
|
end
|
||||||
-- end
|
-- end
|
||||||
GameworldDrawEnd()
|
GameworldDrawEnd()
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ function GameworldDrawPrepare()
|
||||||
if game_resize then
|
if game_resize then
|
||||||
Camera.height = game.height
|
Camera.height = game.height
|
||||||
Camera.width = game.width
|
Camera.width = game.width
|
||||||
|
Darkness.Recreate()
|
||||||
end
|
end
|
||||||
pcr, pcg, pcb, pca = love.graphics.getColor()
|
pcr, pcg, pcb, pca = love.graphics.getColor()
|
||||||
love.graphics.scale(game.scale,game.scale)
|
love.graphics.scale(game.scale,game.scale)
|
||||||
|
@ -72,24 +73,53 @@ function GameworldDrawForeground()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameworldDrawLighting()
|
function GameworldDrawDarkness()
|
||||||
if game_resize then
|
Darkness.Reset()
|
||||||
Canvas.Darkness:release()
|
Darkness.DrawStart()
|
||||||
Canvas.Darkness = CreateDarkness()
|
love.graphics.setBlendMode("replace")
|
||||||
love.graphics.setCanvas(Canvas.Darkness)
|
love.graphics.setColor(0,0,0,0)
|
||||||
SetDarkness()
|
for _, light in pairs(LoadedObjects.Lights) do
|
||||||
love.graphics.setCanvas()
|
if light.range ~= 0 then
|
||||||
|
local position = {
|
||||||
|
x = (light.pos.x - Camera.pos.x) / game.scale,
|
||||||
|
y = (light.pos.y - Camera.pos.y) / game.scale
|
||||||
|
}
|
||||||
|
local range = (light.range + light.flicker) / game.scale
|
||||||
|
love.graphics.circle(
|
||||||
|
"fill",
|
||||||
|
position.x,
|
||||||
|
position.y,
|
||||||
|
range
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
Darkness.DrawEnd()
|
||||||
|
end
|
||||||
|
|
||||||
|
function GameworldDrawLights()
|
||||||
|
for _, light in pairs(LoadedObjects.Lights) do
|
||||||
|
if light.range ~= 0 then
|
||||||
|
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
|
||||||
|
|
||||||
|
Shader.RadiusGradient:send("pos_x",- Camera.pos.x + light.pos.x)
|
||||||
|
Shader.RadiusGradient:send("pos_y",- Camera.pos.y + light.pos.y)
|
||||||
|
Shader.RadiusGradient:send("range",light.range)
|
||||||
|
Shader.RadiusGradient:send("scale",game.scale)
|
||||||
|
|
||||||
|
love.graphics.setShader(Shader.RadiusGradient)
|
||||||
|
love.graphics.circle(
|
||||||
|
"fill",
|
||||||
|
- Camera.pos.x + light.pos.x,
|
||||||
|
- Camera.pos.y + light.pos.y,
|
||||||
|
light.range
|
||||||
|
)
|
||||||
|
love.graphics.setShader()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function GameWorldUpdateLights()
|
||||||
|
for _, light in pairs(LoadedObjects.Lights) do
|
||||||
|
light:Flicker()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- work on lighting canvas
|
|
||||||
love.graphics.setCanvas(Canvas.Darkness)
|
|
||||||
SetDarkness()
|
|
||||||
DoLights()
|
|
||||||
DoBorder()
|
|
||||||
-- apply to game canvas
|
|
||||||
love.graphics.setColor(1,1,1,1)
|
|
||||||
love.graphics.scale(game.scale,game.scale)
|
|
||||||
love.graphics.setCanvas()
|
|
||||||
DrawDarkness()
|
|
||||||
love.graphics.scale(1/game.scale,1/game.scale)
|
|
||||||
end
|
end
|
||||||
|
|
132
code/lights.lua
132
code/lights.lua
|
@ -1,11 +1,7 @@
|
||||||
Lights = {}
|
Light = {}
|
||||||
LightTimer = 0
|
LoadedObjects.Lights = {}
|
||||||
|
|
||||||
function CreateDarkness()
|
function Light:New(x,y,range,flicker,color,lum)
|
||||||
return love.graphics.newCanvas(game.width/game.scale, game.height/game.scale)
|
|
||||||
end
|
|
||||||
|
|
||||||
function CreateLight(x,y,range,flicker,color,lum)
|
|
||||||
local o = {}
|
local o = {}
|
||||||
o.pos = {
|
o.pos = {
|
||||||
x = x,
|
x = x,
|
||||||
|
@ -17,117 +13,35 @@ function CreateLight(x,y,range,flicker,color,lum)
|
||||||
o.flicker_value = flicker or 2
|
o.flicker_value = flicker or 2
|
||||||
o.flicker = 0
|
o.flicker = 0
|
||||||
o.dim = 0
|
o.dim = 0
|
||||||
o.flicker_speed = flicker_speed or 60/12
|
o.flicker_time = 60/12
|
||||||
o.flicker_time = 0
|
o.flicker_timer = 0
|
||||||
|
|
||||||
table.insert(Lights,o)
|
table.insert(LoadedObjects.Lights,o)
|
||||||
o.id = #Lights
|
o.id = #LoadedObjects.Lights
|
||||||
|
|
||||||
|
setmetatable(o, self)
|
||||||
|
self.__index = self
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
function KillLight(light)
|
function Light:Kill()
|
||||||
if light.id ~= nil then
|
if self.id ~= nil then
|
||||||
for _, e in pairs(Lights) do
|
for _, e in pairs(LoadedObjects.Lights) do
|
||||||
if e.id > light.id then
|
if e.id > self.id then
|
||||||
e.id = e.id - 1
|
e.id = e.id - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
table.remove(Lights,light.id)
|
table.remove(LoadedObjects.Lights,self.id)
|
||||||
end
|
end
|
||||||
light = nil
|
self = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function SetDarkness()
|
function Light:Flicker()
|
||||||
love.graphics.setCanvas(Canvas.Darkness)
|
self.flicker_timer = self.flicker_timer + 1
|
||||||
|
|
||||||
love.graphics.setColor(0,0,0,1)
|
if self.flicker_timer >= self.flicker_time then
|
||||||
love.graphics.rectangle("fill",0,0,game.width ,game.height)
|
self.flicker_timer = self.flicker_timer - self.flicker_time
|
||||||
|
self.flicker = math.random(0,1)
|
||||||
love.graphics.setCanvas()
|
self.flicker = math.min(math.max(self.flicker, -self.flicker_value), self.flicker_value)
|
||||||
end
|
end
|
||||||
|
|
||||||
function DoLights()
|
|
||||||
|
|
||||||
love.graphics.setCanvas(Canvas.Darkness)
|
|
||||||
|
|
||||||
for _, light in pairs(Lights) do
|
|
||||||
light.flicker_time = light.flicker_time + 1
|
|
||||||
|
|
||||||
if light.flicker_time >= light.flicker_speed then
|
|
||||||
light.flicker_time = light.flicker_time - light.flicker_speed
|
|
||||||
light.flicker = 0 + math.random(0,1)
|
|
||||||
light.flicker = math.min(math.max(light.flicker, -light.flicker_value),light.flicker_value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
love.graphics.setBlendMode("replace")
|
|
||||||
for _, light in pairs(Lights) do
|
|
||||||
if light.range ~= 0 then
|
|
||||||
love.graphics.setColor(light.color[1],light.color[2],light.color[3],1)
|
|
||||||
local position = {
|
|
||||||
x = (light.pos.x - Camera.pos.x) / game.scale,
|
|
||||||
y = (light.pos.y - Camera.pos.y) / game.scale
|
|
||||||
}
|
|
||||||
local range = (1 + light.range + light.flicker) / game.scale
|
|
||||||
love.graphics.circle(
|
|
||||||
"fill",
|
|
||||||
position.x,
|
|
||||||
position.y,
|
|
||||||
range
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
love.graphics.setColor(0,0,0,0)
|
|
||||||
for _, light in pairs(Lights) do
|
|
||||||
if light.range ~= 0 then
|
|
||||||
local position = {
|
|
||||||
x = (light.pos.x - Camera.pos.x) / game.scale,
|
|
||||||
y = (light.pos.y - Camera.pos.y) / game.scale
|
|
||||||
}
|
|
||||||
local range = (light.range + light.flicker) / game.scale
|
|
||||||
love.graphics.circle(
|
|
||||||
"fill",
|
|
||||||
position.x,
|
|
||||||
position.y,
|
|
||||||
range
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
love.graphics.setBlendMode("alpha")
|
|
||||||
love.graphics.setColor(0,0,0,1)
|
|
||||||
Shaders.InsideLight:send("game_scale", game.scale)
|
|
||||||
|
|
||||||
for _, light in pairs(Lights) do
|
|
||||||
if light.range ~= 0 then
|
|
||||||
local position = {
|
|
||||||
x = (light.pos.x - Camera.pos.x) / game.scale,
|
|
||||||
y = (light.pos.y - Camera.pos.y) / game.scale
|
|
||||||
}
|
|
||||||
local range = (light.range + light.flicker) / game.scale
|
|
||||||
Shaders.InsideLight:send("light_color", light.color)
|
|
||||||
Shaders.InsideLight:send("light_pos", {position.x*game.scale, position.y*game.scale})
|
|
||||||
Shaders.InsideLight:send("range", range)
|
|
||||||
love.graphics.setShader(Shaders.InsideLight)
|
|
||||||
love.graphics.circle(
|
|
||||||
"fill",
|
|
||||||
position.x,
|
|
||||||
position.y,
|
|
||||||
range
|
|
||||||
)
|
|
||||||
love.graphics.setShader()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
love.graphics.setCanvas()
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
function DoBorder()
|
|
||||||
love.graphics.setCanvas(Canvas.Darkness)
|
|
||||||
love.graphics.setCanvas()
|
|
||||||
end
|
|
||||||
|
|
||||||
function DrawDarkness()
|
|
||||||
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 1/game.scale)
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,4 @@
|
||||||
LoadedObjects = {
|
LoadedObjects = {}
|
||||||
Entities = {},
|
|
||||||
|
|
||||||
Collisions = {},
|
|
||||||
Platforms = {},
|
|
||||||
Ladders = {},
|
|
||||||
Hazards = {}
|
|
||||||
}
|
|
||||||
|
|
||||||
-- level functions
|
-- level functions
|
||||||
function LoadedObjects.DrawCollisions()
|
function LoadedObjects.DrawCollisions()
|
||||||
|
|
|
@ -12,16 +12,19 @@ require "code/hex"
|
||||||
require "code/in_out"
|
require "code/in_out"
|
||||||
|
|
||||||
-- classes
|
-- classes
|
||||||
require "code/audio"
|
require "code/objects"
|
||||||
require "code/entity"
|
|
||||||
require "code/animation"
|
|
||||||
require "code/collision"
|
|
||||||
require "code/level"
|
require "code/level"
|
||||||
require "code/camera"
|
require "code/camera"
|
||||||
|
require "code/animation"
|
||||||
|
require "code/audio"
|
||||||
|
|
||||||
|
-- objects
|
||||||
|
require "code/entity"
|
||||||
|
require "code/collision"
|
||||||
require "code/lights"
|
require "code/lights"
|
||||||
require "code/objects"
|
|
||||||
|
|
||||||
-- functions
|
-- functions
|
||||||
|
require "code/darkness"
|
||||||
require "code/debug"
|
require "code/debug"
|
||||||
require "code/demo"
|
require "code/demo"
|
||||||
require "code/keybind"
|
require "code/keybind"
|
||||||
|
|
|
@ -2,7 +2,7 @@ return {
|
||||||
name = "test",
|
name = "test",
|
||||||
tileset = tileset.library,
|
tileset = tileset.library,
|
||||||
properties = {
|
properties = {
|
||||||
darkness = false
|
darkness = true
|
||||||
},
|
},
|
||||||
tiles = {
|
tiles = {
|
||||||
{ 1, 4, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
{ 1, 4, 0, 0, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||||
|
|
|
@ -1,52 +1,23 @@
|
||||||
Shaders = {}
|
Shader = {}
|
||||||
Shaders.InsideLight = love.graphics.newShader[[
|
Shader.RadiusGradient = love.graphics.newShader[[
|
||||||
uniform vec2 light_pos;
|
uniform float pos_x;
|
||||||
uniform vec3 light_color;
|
uniform float pos_y;
|
||||||
uniform float range;
|
uniform float range;
|
||||||
uniform float game_scale;
|
uniform float scale;
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
|
||||||
|
|
||||||
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
|
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
|
||||||
|
|
||||||
float distance_x = light_pos.x - screen_coords.x;
|
float distance_x = pos_x - screen_coords.x / scale;
|
||||||
float distance_y = light_pos.y - screen_coords.y;
|
float distance_y = pos_y - screen_coords.y / scale;
|
||||||
float distance = sqrt( pow(distance_x,2) + pow(distance_y,2) ) / game_scale;
|
float distance = sqrt( pow(distance_x,2) + pow(distance_y,2) ) ;
|
||||||
if (distance < range){
|
if (distance < range){
|
||||||
float alpha = 1-(distance/10);
|
float alpha = 1-(2*distance/range);
|
||||||
pixel.a = alpha;
|
|
||||||
if (color.r<light_color.r){
|
|
||||||
color.r = light_color.r;
|
|
||||||
}
|
|
||||||
if (color.g<light_color.g){
|
|
||||||
color.g = light_color.g;
|
|
||||||
}
|
|
||||||
if (color.b<light_color.b){
|
|
||||||
color.b = light_color.b;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return pixel * color;
|
|
||||||
}
|
|
||||||
]]
|
|
||||||
|
|
||||||
Shaders.OutsideDark = love.graphics.newShader[[
|
|
||||||
uniform vec2 light_pos;
|
|
||||||
uniform float range;
|
|
||||||
uniform float game_scale;
|
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
|
|
||||||
|
|
||||||
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
|
|
||||||
|
|
||||||
float distance_x = light_pos.x - screen_coords.x;
|
|
||||||
float distance_y = light_pos.y - screen_coords.y;
|
|
||||||
float distance = sqrt( pow(distance_x,2) + pow(distance_y,2) ) / game_scale;
|
|
||||||
if (distance < range){
|
|
||||||
float alpha = (distance/range);
|
|
||||||
if (pixel.a > alpha){
|
if (pixel.a > alpha){
|
||||||
pixel.a = alpha;
|
pixel.a = alpha;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pixel * color;
|
return pixel * color * color;
|
||||||
}
|
}
|
||||||
]]
|
]]
|
||||||
|
|
11
main.lua
11
main.lua
|
@ -22,20 +22,15 @@ function love.load()
|
||||||
game = {
|
game = {
|
||||||
scale = 2,
|
scale = 2,
|
||||||
width = love.graphics.getWidth(),
|
width = love.graphics.getWidth(),
|
||||||
height = love.graphics.getHeight(),
|
height = love.graphics.getHeight()
|
||||||
paused = false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
require "code/require"
|
require "code/require"
|
||||||
|
|
||||||
logPrint(loveInitLog)
|
logPrint(loveInitLog)
|
||||||
loveInitLog = nil
|
loveInitLog = nil
|
||||||
Canvas = {
|
Canvas = {}
|
||||||
Darkness = CreateDarkness()
|
Darkness.Create()
|
||||||
}
|
|
||||||
love.graphics.setCanvas(Canvas.Darkness)
|
|
||||||
SetDarkness()
|
|
||||||
love.graphics.setCanvas()
|
|
||||||
|
|
||||||
Camera.width = game.width
|
Camera.width = game.width
|
||||||
Camera.height = game.height
|
Camera.height = game.height
|
||||||
|
|
Loading…
Reference in New Issue