0 Members and 1 Guest are viewing this topic.
cell = class()cellTable = {}timer.start(0.01)function cell:init(x,y,radius) self.xPos = x self.yPos = y self.radius = radius self.xMov = math.random(-1,1) self.yMov = math.random(-1,1)endfunction on.create() text = "no collision"endtable.insert(cellTable, cell(10,10,10))table.insert(cellTable, cell(100,90,20))table.insert(cellTable, cell(69,200,10))table.insert(cellTable, cell(180,50,10))table.insert(cellTable, cell(150,150,10))function on.timer() for k,v in pairs(cellTable) do v:move() end removeCells() platform.window:invalidate()endfunction on.paint(gc) for k,v in pairs(cellTable) do v:paint(gc) end checkCollision(cellTable)endfunction removeCells() --here's the part that should remove items out of the listendfunction checkCollision() --This function check for collisions (you don't say) and decreases or increases the radius when neededend
function removeEmpty(tbl) for k, v in ipairs(tbl) do if v.radius == 0 then table.remove(tbl, k) end endend
function removeEmpty(tbl) for k, v in ipairs(tbl) do if v.radius == 0 then table.remove(tbl, k) removeEmpty(tbl) break end endend
function removeEmpty(tbl) local n = 1 local rep = true while rep do rep = false for k = n, #tbl do if tbl[k].radius == 0 then table.remove(tbl, k) rep = true n = k break end end endend