Lighting system

This commit is contained in:
lustlion 2021-10-26 01:19:22 +02:00
parent 531555a1d0
commit f926723194
11 changed files with 946 additions and 828 deletions

1
LoreMuseum Submodule

@ -0,0 +1 @@
Subproject commit 38e8c5a4db22269d5d63d39c733b3802452b4c0b

View File

@ -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"

View File

@ -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)

View File

@ -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

View File

@ -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

65
data/scripts/lights.lua Normal file
View File

@ -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

View File

@ -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

15
to_do.txt Normal file
View File

@ -0,0 +1,15 @@
MAKE LIGHTING SYSTEM
Updates:
LOVE HAS CANVASES!!!
MAKE ARROW CANVAS SO THAT ARROWS WHEN STUCK CAN BE STORED AS IMAGE AND ARE NOT LAGGY!!!
DRAW GIANT ANIMALS AS POWER SOURCE
DO FAIRY
DO FLIES
DO DAMAGE TO PLAYER
DO UI