debug screen to show loaded objects, fixed particles not getting properly cleaned, canvas cleanup

This commit is contained in:
lustlion 2022-02-23 16:46:03 +01:00
parent a4490bc827
commit 00cec59351
5 changed files with 27 additions and 53 deletions

View File

@ -9,16 +9,16 @@ function Canvas:New(name)
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
Canvas[name] = o return o
end end
function Canvas:Recreate() function Canvas:Recreate()
self.canvas:release() self.canvas:release()
self = Canvas:New(self.name) self = Canvas:New()
end end
function Canvas:Reset() function Canvas:Reset()
love.graphics.setCanvas(Canvas[self.name].canvas) love.graphics.setCanvas(self.canvas)
love.graphics.setBlendMode("replace") love.graphics.setBlendMode("replace")
love.graphics.setColor(0,0,0,0) love.graphics.setColor(0,0,0,0)
love.graphics.rectangle( love.graphics.rectangle(
@ -33,7 +33,7 @@ end
function Canvas:DrawingStart() function Canvas:DrawingStart()
self:Reset() self:Reset()
love.graphics.setCanvas(Canvas[self.name].canvas) love.graphics.setCanvas(self.canvas)
end end
function Canvas:DrawingEnd() function Canvas:DrawingEnd()

View File

@ -1,4 +1,4 @@
Canvas:New("Darkness") Canvas.Darkness = Canvas:New("Darkness")
function Canvas.Darkness:Reset() function Canvas.Darkness:Reset()
love.graphics.setCanvas(Canvas.Darkness.canvas) love.graphics.setCanvas(Canvas.Darkness.canvas)

View File

@ -11,23 +11,14 @@ function DebugUI()
love.graphics.setColor(1,1,1) love.graphics.setColor(1,1,1)
-- lots of variables -- lots of variables
love.graphics.print("[main_Player]",10*textScale,40*textScale, 0, textScale) love.graphics.print("LoadedObjects",10*textScale,40*textScale, 0, textScale)
love.graphics.print("position: {"..main_Player.pos.x..", "..main_Player.pos.y.."}",10*textScale,60*textScale, 0, textScale) local i = 1
love.graphics.print("velocity: {"..main_Player.vel.x..", "..main_Player.vel.y.."}",10*textScale,80*textScale, 0, textScale) for k, v in pairs(LoadedObjects) do
love.graphics.print("scale: {"..main_Player.sprite_scale.x..", "..main_Player.sprite_scale.y.."}",10*textScale,100*textScale, 0, textScale) if type(v) == "table" then
love.graphics.print("states: \"isOnGround\": "..tostring(main_Player.isOnGround),10*textScale,120*textScale, 0, textScale) love.graphics.print("<"..k.."> ".. #v,10*textScale,(40+(10*i))*textScale, 0, textScale)
love.graphics.print("\"coyoteValue\": "..tostring(main_Player.coyoteValue),10*textScale,140*textScale, 0, textScale) i = i + 1
end
love.graphics.print("[Camera]",10*textScale,160*textScale, 0, textScale) end
love.graphics.print("position: {"..Camera.pos.x..", "..Camera.pos.y.."}",10*textScale,180*textScale, 0, textScale)
love.graphics.print("size: {"..Camera.width..", "..Camera.height.."}",10*textScale,200*textScale, 0, textScale)
love.graphics.print("[Cursor]",10*textScale,220*textScale, 0, textScale)
love.graphics.print("position: {"..mouse_x+Camera.pos.x..", "..mouse_y+Camera.pos.y.."}",10*textScale,240*textScale, 0, textScale)
love.graphics.print(textScale,10*textScale,240*textScale, 0, textScale)
love.graphics.print("Level: "..levelNum.." / "..#levelList.." \""..currLevel.."\"",10*textScale,260*textScale, 0, textScale)
-- player isOnGroundCheck -- player isOnGroundCheck
love.graphics.setColor(1,0,0) love.graphics.setColor(1,0,0)
end end

View File

@ -55,18 +55,18 @@ LoadedObjects.Particles = {}
function Particle:Kill() function Particle:Kill()
if self.light ~= nil then if self.light ~= nil then
KillLight(self.light) self.light:Kill()
end end
if self.id ~= nil then if self.id ~= nil then
for _, e in pairs(LoadedParticles) do for _, e in pairs(LoadedObjects.Particles) do
if e.id > self.id then if e.id > self.id then
e.id = e.id - 1 e.id = e.id - 1
end end
end end
table.remove(LoadedParticles,self.id) table.remove(LoadedObjects.Particles,self.id)
end end
self = nil self = nil
end end
function Particle:HandleAnimation() function Particle:HandleAnimation()
self.timer = self.timer + current_dt self.timer = self.timer + current_dt

View File

@ -75,23 +75,6 @@ function Entity:CollisionMove()
return r return r
end end
function Entity:MoveX()
local r = false
if not self:isCollidingAt(self.pos.x + self.vel.x, self.pos.y, LoadedObjects.Collisions) then
self.pos.x = self.pos.x + self.vel.x
else
self.vel.x = 0
r = true
end
if not self:isCollidingAt(self.pos.x, self.pos.y + self.vel.y, LoadedObjects.Collisions) then
self.pos.y = self.pos.y + self.vel.y
else
self.vel.y = 0
r = true
end
return r
end
function Entity:LightAdjust(x,y) function Entity:LightAdjust(x,y)
if self.light ~= nil then if self.light ~= nil then
local x = x or 0 local x = x or 0
@ -103,7 +86,7 @@ end
function Entity:Kill() function Entity:Kill()
if self.light ~= nil then if self.light ~= nil then
KillLight(self.light) self.light:Kill()
end end
if self.id ~= nil then if self.id ~= nil then
for _, e in pairs(LoadedObjects.Entities) do for _, e in pairs(LoadedObjects.Entities) do