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"
|
||||
-- data
|
||||
require "data/scripts/camera"
|
||||
require "data/scripts/lights"
|
||||
require "data/scripts/objects"
|
||||
-- UI functions
|
||||
require "data/scripts/debug"
|
||||
|
|
|
@ -1,4 +1,11 @@
|
|||
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.setColor(1,1,1)
|
||||
|
|
|
@ -15,7 +15,7 @@ Arrow = Entity:New(x,y)
|
|||
|
||||
setmetatable(o, self)
|
||||
self.__index = self
|
||||
table.insert(LoadedEntities,o)
|
||||
table.insert(LoadedEntities,o)
|
||||
return o
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,11 @@ Kupo = Entity:New(x,y)
|
|||
o.bow_speed = 1/10
|
||||
o.bow_frames = 6
|
||||
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)
|
||||
self.__index = self
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
x = 0,
|
||||
y = 0
|
||||
}
|
||||
|
||||
-- constants
|
||||
o.acc = 45
|
||||
o.acc = 45
|
||||
o.friction = 20
|
||||
o.gravity = 9.81
|
||||
o.climbHeight = 4
|
||||
|
@ -20,18 +21,25 @@
|
|||
o.maxSpeed = 600
|
||||
o.jumpMaxSpeed = 9.5
|
||||
o.zeroSpeed = 0.001
|
||||
-- bools
|
||||
o.lightRange = 20
|
||||
|
||||
-- status
|
||||
o.isJumping = false
|
||||
o.isOnGround = 0
|
||||
o.coyoteValue = 5
|
||||
o.coyoteValue = 5
|
||||
o.isOnLadder = false
|
||||
o.canJump = true
|
||||
o.canFall = true
|
||||
o.canFriction = true
|
||||
|
||||
-- sprite
|
||||
-- sprite
|
||||
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)
|
||||
self.__index = self
|
||||
|
||||
|
@ -78,6 +86,9 @@ function Player:Smart()
|
|||
end
|
||||
|
||||
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
|
||||
if self.vel.x ~= 0 then self.sprite_flip.x = math.sign(self.vel.x) end
|
||||
|
@ -186,15 +197,15 @@ function Player:DoPhysics()
|
|||
self.vel.y = 0
|
||||
else
|
||||
self.pos.y = self.pos.y + self.vel.y
|
||||
self.isOnGround = math.max(self.isOnGround - 1, 0)
|
||||
self.isOnGround = math.max(self.isOnGround - 1, 0)
|
||||
end
|
||||
|
||||
-- drop.
|
||||
if self.canFall then
|
||||
-- drop.
|
||||
if self.canFall then
|
||||
self.vel.y = self.vel.y + 2*self.gravity * current_dt
|
||||
end
|
||||
|
||||
-- friction hard in ground, soft in air
|
||||
-- friction hard in ground, soft in air
|
||||
if self.isOnGround > 0 then
|
||||
self.vel.x = self.vel.x * (1 - math.min(current_dt * self.friction, 1))
|
||||
else
|
||||
|
|
|
@ -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
|
36
main.lua
36
main.lua
|
@ -17,13 +17,16 @@ function love.load()
|
|||
paused = false
|
||||
}
|
||||
require "data/scripts"
|
||||
Canvas = {
|
||||
Darkness = CreateDarkness()
|
||||
}
|
||||
Camera.width = game.width
|
||||
Camera.height = game.height
|
||||
levelList = {"level1","2","3","ewae","tileset"}
|
||||
levelNum = 1
|
||||
currLevel = levelList[levelNum]
|
||||
LevelLoadTiles()
|
||||
main_Player = Player:New(1220,220)
|
||||
main_Player = Player:New(0,20)
|
||||
LoadedEntities = {}
|
||||
table.insert(LoadedEntities,main_Player)
|
||||
table.insert(LoadedEntities,Kupo:New(450,100))
|
||||
|
@ -45,10 +48,15 @@ function love.update(dt)
|
|||
current_dt = dt
|
||||
|
||||
-- saveproof to game resize
|
||||
game.width = love.graphics.getWidth()
|
||||
game.height = love.graphics.getHeight()
|
||||
Camera.height = game.height
|
||||
Camera.width = game.width
|
||||
if game.width ~= love.graphics.getWidth() or game.height ~= love.graphics.getHeight() then
|
||||
game.width = love.graphics.getWidth()
|
||||
game.height = love.graphics.getHeight()
|
||||
Camera.height = game.height
|
||||
Camera.width = game.width
|
||||
Canvas.Darkness:release()
|
||||
Canvas.Darkness = CreateDarkness()
|
||||
end
|
||||
|
||||
-- GAME STEP
|
||||
if not do_pause then
|
||||
SetCollisionFlags(main_Player)
|
||||
|
@ -104,6 +112,7 @@ end
|
|||
function love.draw()
|
||||
-- GAME WORLD
|
||||
love.graphics.scale(game.scale,game.scale)
|
||||
love.graphics.setColor(1,1,1,1)
|
||||
LevelDisplayBackground()
|
||||
for _, enty in pairs(LoadedEntities) do
|
||||
enty:HandleAnimation()
|
||||
|
@ -115,14 +124,19 @@ function love.draw()
|
|||
-- Save color
|
||||
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)
|
||||
DrawDarkness()
|
||||
-- HUD
|
||||
-- Scale control
|
||||
if game.height > game.width then
|
||||
textScale = game.height/480/2
|
||||
else
|
||||
textScale = game.width/640/2
|
||||
end
|
||||
textScale = 0.5
|
||||
|
||||
--debug
|
||||
if debug then DebugUI() end
|
||||
|
|
Loading…
Reference in New Issue