The problem: it doesn't work, at all. The bullets seem to teleport
main.lua:
Code: Select all
HC = require 'hardoncollider'
function on_collide(dt, shape_a, shape_b)
end
function love.load()
Collider = HC(100, on_collide)
bullets = {}
pData = {x = 400, y = 300}
player = Collider:addRectangle(pData.x, pData.y, 32, 32)
bullet = {}
bullet.radius = 5
bullet.x = pData.x
bullet.y = pData.y
bullet.xspeed = 0
bullet.yspeed = 0
bullet.speed = 500
bullet.bul = Collider:addCircle(bullet.x, bullet.y, bullet.radius)
table.insert(bullets, bullet)
end
function love.update(dt)
Collider:update(dt)
for i,v in ipairs(bullets) do
v.x = v.x + v.xspeed * dt
v.y = v.y + v.yspeed * dt
end
end
function love.draw()
for i,v in ipairs(bullets) do
v.bul:draw('line')
end
player:draw("line")
end
function love.keypressed(key)
if key == "left" then
bullet.bul = Collider:addCircle(bullet.x, bullet.y, bullet.radius)
bullet.xspeed = -bullet.speed
table.insert(bullets, bullet)
elseif key == "right" then
bullet.bul = Collider:addCircle(bullet.x, bullet.y, bullet.radius)
bullet.xspeed = bullet.speed
table.insert(bullets, bullet)
end
end