Lighting system
This commit is contained in:
parent
531555a1d0
commit
f926723194
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 38e8c5a4db22269d5d63d39c733b3802452b4c0b
|
|
@ -11,6 +11,7 @@ require "data/scripts/collision"
|
||||||
require "data/scripts/level"
|
require "data/scripts/level"
|
||||||
-- data
|
-- data
|
||||||
require "data/scripts/camera"
|
require "data/scripts/camera"
|
||||||
|
require "data/scripts/lights"
|
||||||
require "data/scripts/objects"
|
require "data/scripts/objects"
|
||||||
-- UI functions
|
-- UI functions
|
||||||
require "data/scripts/debug"
|
require "data/scripts/debug"
|
||||||
|
|
|
@ -1,4 +1,11 @@
|
||||||
function DebugUI()
|
function DebugUI()
|
||||||
|
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
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.x,light.pos.x,light.pos.y+40)
|
||||||
|
end
|
||||||
|
|
||||||
love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale)
|
love.graphics.print("time: "..fps_total..", fps: "..fps_draw..", frametime: "..math.floor(current_dt* 1000).."ms", 10*textScale, 0*textScale, 0, textScale)
|
||||||
|
|
||||||
love.graphics.setColor(1,1,1)
|
love.graphics.setColor(1,1,1)
|
||||||
|
|
|
@ -19,6 +19,10 @@ Kupo = Entity:New(x,y)
|
||||||
o.bow_frames = 6
|
o.bow_frames = 6
|
||||||
o.bow_extraframes = 18
|
o.bow_extraframes = 18
|
||||||
o.bow_aim_frames = 8
|
o.bow_aim_frames = 8
|
||||||
|
|
||||||
|
o.lightRange = o.range
|
||||||
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
x = 0,
|
x = 0,
|
||||||
y = 0
|
y = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
-- constants
|
-- constants
|
||||||
o.acc = 45
|
o.acc = 45
|
||||||
o.friction = 20
|
o.friction = 20
|
||||||
|
@ -20,7 +21,9 @@
|
||||||
o.maxSpeed = 600
|
o.maxSpeed = 600
|
||||||
o.jumpMaxSpeed = 9.5
|
o.jumpMaxSpeed = 9.5
|
||||||
o.zeroSpeed = 0.001
|
o.zeroSpeed = 0.001
|
||||||
-- bools
|
o.lightRange = 20
|
||||||
|
|
||||||
|
-- status
|
||||||
o.isJumping = false
|
o.isJumping = false
|
||||||
o.isOnGround = 0
|
o.isOnGround = 0
|
||||||
o.coyoteValue = 5
|
o.coyoteValue = 5
|
||||||
|
@ -31,7 +34,12 @@
|
||||||
|
|
||||||
-- sprite
|
-- sprite
|
||||||
o.sprite_offset = {x = 8, y = 16}
|
o.sprite_offset = {x = 8, y = 16}
|
||||||
o.target_offset = {x = 4, y = 12}
|
o.target_offset = {x = 0, y = 12}
|
||||||
|
|
||||||
|
-- lights
|
||||||
|
o.light = CreateLight(o.pos.x,o.pos.y,o.lightRange)
|
||||||
|
|
||||||
|
|
||||||
setmetatable(o, self)
|
setmetatable(o, self)
|
||||||
self.__index = self
|
self.__index = self
|
||||||
|
|
||||||
|
@ -78,6 +86,9 @@ function Player:Smart()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Player:HandleAnimation()
|
function Player:HandleAnimation()
|
||||||
|
-- move light to position, :D
|
||||||
|
self.light.pos.x = self.pos.x - self.target_offset.x
|
||||||
|
self.light.pos.y = self.pos.y - self.target_offset.y
|
||||||
|
|
||||||
-- flip sprite to look in the direction is moving
|
-- flip sprite to look in the direction is moving
|
||||||
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
|
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
Lights = {}
|
||||||
|
LightTimer = 0
|
||||||
|
|
||||||
|
function CreateDarkness()
|
||||||
|
return love.graphics.newCanvas(game.width/2, game.height/2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function CreateLight(x,y,range)
|
||||||
|
local o = {}
|
||||||
|
o.pos = {
|
||||||
|
x = x,
|
||||||
|
y = y
|
||||||
|
}
|
||||||
|
o.range = range
|
||||||
|
o.flicker = 0
|
||||||
|
table.insert(Lights,o)
|
||||||
|
return o
|
||||||
|
end
|
||||||
|
|
||||||
|
function DoDarkness()
|
||||||
|
love.graphics.setColor(0,0,0)
|
||||||
|
love.graphics.rectangle("fill",0,0,game.width,game.height)
|
||||||
|
end
|
||||||
|
|
||||||
|
function DoLights()
|
||||||
|
LightTimer = LightTimer + 1
|
||||||
|
|
||||||
|
if LightTimer >= 3 then
|
||||||
|
LightTimer = LightTimer - 3
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
light.flicker = math.random(-1,1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
love.graphics.setBlendMode("replace")
|
||||||
|
-- first, border
|
||||||
|
love.graphics.setColor(1,1,1)
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
|
||||||
|
love.graphics.circle(
|
||||||
|
"fill",
|
||||||
|
light.pos.x - Camera.pos.x,
|
||||||
|
light.pos.y - Camera.pos.y,
|
||||||
|
light.range + light.flicker + 1
|
||||||
|
)
|
||||||
|
end
|
||||||
|
love.graphics.setColor(0,0,0,0)
|
||||||
|
-- then, light
|
||||||
|
for _, light in pairs(Lights) do
|
||||||
|
love.graphics.circle(
|
||||||
|
"fill",
|
||||||
|
light.pos.x - Camera.pos.x,
|
||||||
|
light.pos.y - Camera.pos.y,
|
||||||
|
light.range + light.flicker
|
||||||
|
)
|
||||||
|
end
|
||||||
|
love.graphics.setBlendMode("alpha")
|
||||||
|
end
|
||||||
|
|
||||||
|
function DoBorder()
|
||||||
|
end
|
||||||
|
|
||||||
|
function DrawDarkness()
|
||||||
|
love.graphics.draw(Canvas.Darkness, 0, 0, 0, 1, 1)
|
||||||
|
end
|
28
main.lua
28
main.lua
|
@ -17,13 +17,16 @@ function love.load()
|
||||||
paused = false
|
paused = false
|
||||||
}
|
}
|
||||||
require "data/scripts"
|
require "data/scripts"
|
||||||
|
Canvas = {
|
||||||
|
Darkness = CreateDarkness()
|
||||||
|
}
|
||||||
Camera.width = game.width
|
Camera.width = game.width
|
||||||
Camera.height = game.height
|
Camera.height = game.height
|
||||||
levelList = {"level1","2","3","ewae","tileset"}
|
levelList = {"level1","2","3","ewae","tileset"}
|
||||||
levelNum = 1
|
levelNum = 1
|
||||||
currLevel = levelList[levelNum]
|
currLevel = levelList[levelNum]
|
||||||
LevelLoadTiles()
|
LevelLoadTiles()
|
||||||
main_Player = Player:New(1220,220)
|
main_Player = Player:New(0,20)
|
||||||
LoadedEntities = {}
|
LoadedEntities = {}
|
||||||
table.insert(LoadedEntities,main_Player)
|
table.insert(LoadedEntities,main_Player)
|
||||||
table.insert(LoadedEntities,Kupo:New(450,100))
|
table.insert(LoadedEntities,Kupo:New(450,100))
|
||||||
|
@ -45,10 +48,15 @@ function love.update(dt)
|
||||||
current_dt = dt
|
current_dt = dt
|
||||||
|
|
||||||
-- saveproof to game resize
|
-- saveproof to game resize
|
||||||
|
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
|
||||||
game.width = love.graphics.getWidth()
|
game.width = love.graphics.getWidth()
|
||||||
game.height = love.graphics.getHeight()
|
game.height = love.graphics.getHeight()
|
||||||
Camera.height = game.height
|
Camera.height = game.height
|
||||||
Camera.width = game.width
|
Camera.width = game.width
|
||||||
|
Canvas.Darkness:release()
|
||||||
|
Canvas.Darkness = CreateDarkness()
|
||||||
|
end
|
||||||
|
|
||||||
-- GAME STEP
|
-- GAME STEP
|
||||||
if not do_pause then
|
if not do_pause then
|
||||||
SetCollisionFlags(main_Player)
|
SetCollisionFlags(main_Player)
|
||||||
|
@ -104,6 +112,7 @@ end
|
||||||
function love.draw()
|
function love.draw()
|
||||||
-- GAME WORLD
|
-- GAME WORLD
|
||||||
love.graphics.scale(game.scale,game.scale)
|
love.graphics.scale(game.scale,game.scale)
|
||||||
|
love.graphics.setColor(1,1,1,1)
|
||||||
LevelDisplayBackground()
|
LevelDisplayBackground()
|
||||||
for _, enty in pairs(LoadedEntities) do
|
for _, enty in pairs(LoadedEntities) do
|
||||||
enty:HandleAnimation()
|
enty:HandleAnimation()
|
||||||
|
@ -115,14 +124,19 @@ function love.draw()
|
||||||
-- Save color
|
-- Save color
|
||||||
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
local pcr, pcg, pcb, pca = love.graphics.getColor()
|
||||||
|
|
||||||
-- HUD
|
love.graphics.setCanvas(Canvas.Darkness)
|
||||||
|
DoDarkness()
|
||||||
|
DoLights()
|
||||||
|
DoBorder()
|
||||||
|
|
||||||
|
-- reset to screen
|
||||||
|
love.graphics.setColor(1,1,1,1)
|
||||||
|
love.graphics.setCanvas()
|
||||||
love.graphics.scale(1,1)
|
love.graphics.scale(1,1)
|
||||||
|
DrawDarkness()
|
||||||
|
-- HUD
|
||||||
-- Scale control
|
-- Scale control
|
||||||
if game.height > game.width then
|
textScale = 0.5
|
||||||
textScale = game.height/480/2
|
|
||||||
else
|
|
||||||
textScale = game.width/640/2
|
|
||||||
end
|
|
||||||
|
|
||||||
--debug
|
--debug
|
||||||
if debug then DebugUI() end
|
if debug then DebugUI() end
|
||||||
|
|
Loading…
Reference in New Issue