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
Submodule
+1
Submodule LoreMuseum added at 38e8c5a4db
+1
View File
@@ -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"
+7
View File
@@ -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)
+4
View File
@@ -19,6 +19,10 @@ Kupo = Entity:New(x,y)
o.bow_frames = 6
o.bow_extraframes = 18
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
+13 -2
View File
@@ -11,6 +11,7 @@
x = 0,
y = 0
}
-- constants
o.acc = 45
o.friction = 20
@@ -20,7 +21,9 @@
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
@@ -31,7 +34,12 @@
-- 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
+65
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
+21 -7
View File
@@ -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
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
+15
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