This is the code where I am adding to the table in the love.load function
Code: Select all
for i = 1, numberofDust do
dust = {}
dustSize = 1.5
if next(listofDust) = nil then
dust.x = love.math.random(20, love.graphics.getWidth() - 50)
dust.y = love.math.random(20, love.graphics.getHeight() - 50)
table.insert(listofDust,dust)
else
for a, v in ipairs(listofDust) do
dust.x = love.math.random(20, love.graphics.getWidth() - 50)
dust.y = love.math.random(20, love.graphics.getHeight() - 50)
if not collision(dust.x, dust.y, dustImg:getWidth()*(1/dustSize), dustImg:getHeight()*(1/dustSize), v.x, v.y, henry:getWidth()*0.25, henry:getHeight()*0.25) then
table.insert(listofDust,dust)
end
end
end
end
Code: Select all
for v = #listofDust, 1, -1 do
if collision(posX, posY, henry:getWidth()*0.25/2, henry:getHeight()*0.25/2, listofDust[v].x, listofDust[v].y, dustImg:getWidth()*(1/dustSize), dustImg:getHeight()*(1/dustSize)) then
table.remove(listofDust,v)
increaseScore()
sucka = suck:clone()
sucka:setVolume(0.2)
sucka:play()
end
end
Code: Select all
function collision(x1,y1,w1,h1, x2,y2,w2,h2)
return x1 < x2+w2 and x2 < x1+w1 and y1 < y2+h2 and y2 < y1+h1
end
function increaseScore()
score = score + 100
end