Bump on it!
This is where we'll configure our collision system using the bump.lua
library. bump.lua
is a lightweight library that can be found at http://github.com/kikito/bump.lua. Let's edit our previous code and set up the bump. We'll also set up our player to move within the solid world and collide with it. It's a long chunk, so you need to follow the comments to understand what each chunk does!
First of all we require the bump library within
main.lua
:bump = require "bump"
Next, we define our collision callback function
bump.collision()
, between two objects:function bump.collision(obj1, obj2, dx, dy)
Then we define the conditions for a collision between the two objects:
function bump.shouldCollide(obj1, obj2)
With this, we get an object and return its collision boundary, which is usually a rectangle of parameters
l
,t
,w
, andh
:function bump.getBBox(obj) return obj.l, obj.t, obj.w, obj.h end
We'll come back and fill the blank spaces between these chunks after we have loaded our solid tiles...