In order to store the bullets' data, I created a variable which holds all the bullets and another which records how many bullets are active:
Code: Select all
bullets = {}
bulletNo = 0
Code: Select all
if key == ' ' then
bulletNo = bulletNo + 1
table.insert(bullets, {})
bullets[bulletNo].body = love.physics.newBody(world, player.body:getX()+32*math.cos(player.angle), player.body:getY()+32*math.sin(player.angle), 1, 0)
bullets[bulletNo].shape = love.physics.newCircleShape(bullets[bulletNo].body, 0, 0, 2)
bullets[bulletNo].body:applyImpulse(10*math.cos(player.angle)+3*player.force.x, 10*math.sin(player.angle)+3*player.force.y)
bullets[bulletNo].lifespan = 0
bullets[bulletNo].shape:setCategory(2)
bullets[bulletNo].shape:setData("Bullet")
end
Code: Select all
function add(a, b, collision)
--If a collision is detected between *something* and a bullet, then either a or b would be "Bullet".
end
Code: Select all
bullets[bulletNo].shape:setData("Bullet" .. bulletNo)
Thanks! And happy holidays to everyone!