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

View File

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

View File

@ -11,23 +11,14 @@ function DebugUI()
love.graphics.setColor(1,1,1)
-- lots of variables
love.graphics.print("[main_Player]",10*textScale,40*textScale, 0, textScale)
love.graphics.print("position: {"..main_Player.pos.x..", "..main_Player.pos.y.."}",10*textScale,60*textScale, 0, textScale)
love.graphics.print("velocity: {"..main_Player.vel.x..", "..main_Player.vel.y.."}",10*textScale,80*textScale, 0, textScale)
love.graphics.print("scale: {"..main_Player.sprite_scale.x..", "..main_Player.sprite_scale.y.."}",10*textScale,100*textScale, 0, textScale)
love.graphics.print("states: \"isOnGround\": "..tostring(main_Player.isOnGround),10*textScale,120*textScale, 0, textScale)
love.graphics.print("\"coyoteValue\": "..tostring(main_Player.coyoteValue),10*textScale,140*textScale, 0, textScale)
love.graphics.print("[Camera]",10*textScale,160*textScale, 0, textScale)
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)
love.graphics.print("LoadedObjects",10*textScale,40*textScale, 0, textScale)
local i = 1
for k, v in pairs(LoadedObjects) do
if type(v) == "table" then
love.graphics.print("<"..k.."> ".. #v,10*textScale,(40+(10*i))*textScale, 0, textScale)
i = i + 1
end
end
-- player isOnGroundCheck
love.graphics.setColor(1,0,0)
end

View File

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

View File

@ -75,23 +75,6 @@ function Entity:CollisionMove()
return r
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)
if self.light ~= nil then
local x = x or 0
@ -103,7 +86,7 @@ end
function Entity:Kill()
if self.light ~= nil then
KillLight(self.light)
self.light:Kill()
end
if self.id ~= nil then
for _, e in pairs(LoadedObjects.Entities) do