I havent used any physics engines for love2d so this is more like a guess, but from quick glance you aren't removing the collider from the world.
Code: Select all
function BRICK:Destroy()
self.xPos = nil
self.yPos = nil
self.width = nil
self.height = nil
self.bColor = nil
Collider:remove( self.Collider ) -- <-- added this line, it removes the collision from the world at least I think it does
self.Collider = nil
self.drawnBrick = nil
self = nil
end
Another problem/potential problem in future that I noticed in your code is inside the removing from table. You have inside gamestate, oncollide following thing:
Code: Select all
for a, brick in ipairs (self.gObjBrick) do
...
brick:Destroy()
self.gObjBrick[a] = nil
table.remove(self.gObjBrick,a)
...
end
Now this doesn't probably do exactly what you are hoping it does in case you have collision with 2 bricks at the same time. It skips objects, because when you remove object from an array with table.remove(), the size of table also gets substracted. Now lets say for example:
Code: Select all
local t = {
1,2,3,4,5
}
for i,v in ipairs( t ) do
if i == 3 or i == 4 then
table.remove(t,i)
print( i, v )
end
end
Now you would think that this actually removes numbers 3 and 4, but it actually removes values 3 and 5, because the table is being changed while it is being iterated. If you index the table from max to min you can avoid this problem where you actually skip the indexes when removed (this is common problem with linked lists). For example once i hits 3, the table looks like { 1,2,4,5 }, and then 4th index is actually 5.
Edit:
I went outside for a walk and thought about this, and I came to conclusion that you are most likely, without really knowing how hardoncollider works, checking all the collisions against each other collisions. This means that essentially you are doing 99% of unneccessary collision checks, bricks vs brick collision. This leads to n*n amount of collision checks. The way how this is generally solved is by assigning collision groups, and with groups you only check each group against each group. Basically if using something like table logic what I am suspecting you are doing for collision check is something like:
Code: Select all
| Ball | Brick1 | Brick2 | Brick3 | Brick4 | ... | Paddle |
------+------+----------+--------+--------+--------+-----+--------+
Ball | | x | x | x | O | ... | x |
Brick1| x | | x | x | X | ... | x |
Brick2| x | x | | x | X | ... | x |
Brick3| x | x | x | | X | ... | x |
Brick4| x | x | x | x | | ... | x |
...
Paddle| x | x | x | x | X | ... | |
Well that is just my educated guess, someone with better knowledge about hardoncollider can correct me if I am wrong. Also I wouldn't be surprised if this doesn't make things any clearer.