From 00cec59351e1586a2f3847c7cfb9f727f52da592 Mon Sep 17 00:00:00 2001 From: lustlion Date: Wed, 23 Feb 2022 16:46:03 +0100 Subject: [PATCH] debug screen to show loaded objects, fixed particles not getting properly cleaned, canvas cleanup --- code/canvas.lua | 8 ++++---- code/canvasses/darkness.lua | 2 +- code/debug.lua | 25 ++++++++----------------- code/entities/particle.lua | 26 +++++++++++++------------- code/entity.lua | 19 +------------------ 5 files changed, 27 insertions(+), 53 deletions(-) diff --git a/code/canvas.lua b/code/canvas.lua index d42df47..e75d64b 100644 --- a/code/canvas.lua +++ b/code/canvas.lua @@ -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() diff --git a/code/canvasses/darkness.lua b/code/canvasses/darkness.lua index f28652c..cf47d94 100644 --- a/code/canvasses/darkness.lua +++ b/code/canvasses/darkness.lua @@ -1,4 +1,4 @@ -Canvas:New("Darkness") +Canvas.Darkness = Canvas:New("Darkness") function Canvas.Darkness:Reset() love.graphics.setCanvas(Canvas.Darkness.canvas) diff --git a/code/debug.lua b/code/debug.lua index 0c66154..f2951d4 100644 --- a/code/debug.lua +++ b/code/debug.lua @@ -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 diff --git a/code/entities/particle.lua b/code/entities/particle.lua index f7b53b9..6031982 100644 --- a/code/entities/particle.lua +++ b/code/entities/particle.lua @@ -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 diff --git a/code/entity.lua b/code/entity.lua index e1b90cf..28ca199 100644 --- a/code/entity.lua +++ b/code/entity.lua @@ -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