This is an older version of bump. Click here to go to the new version
Some of you have been asking how to do collision detection in LÖVE. This might interest you.
But first, do you like eye candy? Me too. Here:
What you see above is the demo of bump 2.0. It is attached at the end of this post. (Go try it, I managed to add some nice music).
bump is a collision detection library. It has changed so much since bump 1.0 that I decided to open a new thread instead of continuing with the old one.
bump only works with axis-aligned bounding boxes (rectangles). If your game needs polygons instead, I recommend giving a look to HardonCollider. If you need complex, realistic physics, then use [wiki]love.physics[/wiki].
In order to use bump 2.0, you first create a world:
Code: Select all
local bump = require 'bump'
local world = bump.newWorld()
Code: Select all
local player, enemy = ... -- create player and enemy
world:add(player, 100,200, 32, 32) -- Add the player in 100,200, as a square of 32x32
world:add(enemy, 0,0, 64,64) --
Code: Select all
world:move(player, 100,300) -- tell the world that the player has moved to 100,300
Code: Select all
local cols, len = world:check(player, 0,0)
if len == 0 then
world:move(player, 0, 0)
else
local tl,tt = cols[1]:getTouch()
print("Collided with " .. tostring(cols[1].other))
world:move(player, tl,tt)
end
That's the basics. The README on the github page has much more information:
https://github.com/kikito/bump.lua
You can see the source code of the demo in the "demo" branch:
https://github.com/kikito/bump.lua/tree/demo
Also, there is a simplified example called "simple demo". Here's the branch:
https://github.com/kikito/bump.lua/tree/simpledemo
I have included a .love for it, too.
Enjoy!