My error is as follows:
Code: Select all
hardoncollider/polygon.lua:265: attempt to index local 'dx' (a nil value)
Traceback
hardoncollider/polygon.lua:265:in function 'move'
hardoncollider/shapes.lua:327: in function 'old_func'
hardoncollider/init.lua:104: in function 'move'
main.lua:8: in function 'on_collide'
hardoncollider/init.lua:196: in function 'update'
main.lua:36: in function 'update'
[C]: in function 'xpcall'
Code: Select all
function love.load()
HC = require 'hardoncollider'
g = love.graphics
g.setBackgroundColor (0, 0, 0)
function onCollide(dt, shapeA, shapeB)
if shapeA == p then
shapeA:move(x, y)
else
shapeB:move(x, y)
end
msg = "Colliding!"
end
Collider = HC(100, onCollide)
px = 100
py = 100
p = Collider:addRectangle(px, py, 50, 50)
box = Collider:addRectangle(400, 200, 20, 200)
g.setBackgroundColor(200, 200, 200)
end
function love.update(dt)
if love.keyboard.isDown("w") then
p:move(0,-200 * dt)
elseif love.keyboard.isDown("s") then
p:move(0,200 * dt)
end
if love.keyboard.isDown("a") then
p:move(-200 * dt,0)
elseif love.keyboard.isDown("d") then
p:move(200 * dt,0)
end
Collider:update(dt)
end
function love.draw()
local x,y = p:center()
g.setColor(51, 51, 51)
p:draw("fill")
box:draw("fill")
g.setColor(0, 0, 0)
end