Beginner to HardonCollider
Posted: Sun Aug 04, 2013 4:52 am
Hi everyone!
I'm starting to use HardonCollider and it seems great! I took an attempt to make a basic moving box with walls on the map but I can't figure out how to stop the player from moving through the wall. On the collision callback I have no idea how to stop it from colliding. Can someone please help?
Code:
I'm starting to use HardonCollider and it seems great! I took an attempt to make a basic moving box with walls on the map but I can't figure out how to stop the player from moving through the wall. On the collision callback I have no idea how to stop it from colliding. Can someone please help?
Code:
Code: Select all
function love.load()
HC = require("hardoncollider")
msg = ""
function onCollide(dt, shapeA, shapeB)
msg = "Colliding!"
end
Collider = HC(100, onCollide)
px = 100
py = 100
player = Collider:addRectangle(px, py, 50, 50)
box = Collider:addRectangle(200, 200, 50, 50)
love.graphics.setBackgroundColor(200, 200, 200)
end
function love.update(dt)
player:moveTo(px, py)
Collider:update(dt)
if love.keyboard.isDown("w") then
py = py - 1 * 200 * dt
elseif love.keyboard.isDown("s") then
py = py + 1 * 200 * dt
end
if love.keyboard.isDown("a") then
px = px - 1 * 200 * dt
elseif love.keyboard.isDown("d") then
px = px + 1 * 200 * dt
end
end
function love.draw()
love.graphics.setColor(51, 51, 51)
player:draw("fill")
box:draw("fill")
love.graphics.setColor(0, 0, 0)
love.graphics.print(px .. ", " .. py, 5, 10)
love.graphics.print(msg, 5, 30)
msg = ""
end
function love.keypressed(key)
end