To cut to the chase: I'm working on code for pickups.. and whilst I can successfully create pickups and have the player pick them up there's a problem! If I create 4 pickups, and have the player pick up #2, then #3 and #4 will also be picked up simultaneously.
Any pointers on tables, how to number them and remove them properly would be much appreciated!
Code: Select all
pickup = {}
function pickup:create(id, x, y, number)
table.insert(pickup, {id = id, x = x, y = y})
end
function pickup:update()
for i,v in ipairs(pickup) do
if player.x > v.x - 16 and player.x < v.x + 16 and player.y > v.y - 16 and player.y < v.y + 16 then
print("Picked up")
--dostuff
pickup:destroy()
end
end
end
function pickup:draw()
for i,v in ipairs(pickup) do
if v.id == 0 then
love.graphics.draw(pickup0, v.x, v.y)
elseif v.id == 1 then
love.graphics.draw(pickup1, v.x, v.y)
end
end
end
function pickup:destroy()
table.remove(pickup)
end