I am releasing a new major version of my collision detection library, bump!
The code and documentation can be found on github:
https://github.com/kikito/bump.lua
You can also find the code of the two demos. The simple one:
http://github.com/kikito/bump.lua/tree/simpledemo
And the not so simple one:
http://github.com/kikito/bump.lua/tree/demo
I have attached .love files for both on this post for your convenience.
Ok, so what's new?
I've tried to write a ChangeLog with all the details. As you can read there, some methods have changed their names / parameters / inner workings.
The most important change however, is the following:
This is the code needed to solve (simple) collisions in v 2.0.0:
Code: Select all
if dx ~= 0 or dy ~= 0 then
player.l, player.t = player.l + dx, player.t + dy
local cols = world:move(player, player.l, player.t)
-- slide the player on the first collision
if cols[1] then
local tl,tt,_,_,sl,st = cols[1]:getSlide()
player.l, player.t = tl, tt
world:move(player, player.l, player.t, player.w, player.h, {skip_collisions = true})
player.l, player.t = sl, st
cols = world:move(player, player.l, player.t)
end
-- touch on the rest of the collisions
for _,col in ipairs(cols) do
local tl, tt = cols[1]:getTouch()
player.l, player.t = tl, tt
end
world:move(player, player.l, player.t, player.w, player.h, {skip_collisions = true})
end
Code: Select all
if dx ~= 0 or dy ~= 0 then
player.x, player.y = world:move(player, player.x + dx, player.y + dy)
end
I am new to this lib. Where do I begin?
Ok, here's a quick intro:
Code: Select all
-- The first thing you have to do is require the lib
local bump = require 'bump'
-- You then have to create at least 1 world (love.load is a good place to do this at the beginning)
local world = bump.newWorld()
-- You then add as many "items" as you want to the world. Items are represented as "rectangles" inside the world
local player = {x=100, y=100}
world:add(player, player.x, player.y, 32,32) -- x,y,w,h
-- You can do this many times (to add things like blocks etc)
local block = {x=200, y=200}
world:add(block, block.x, block.y, 64,64)
-- When you want to move the player (or any other item), inside love.update,
-- instead of changing player.x and player.y to the "goal", use world:move
local goalX, goalY = 120,100 -- this is where I want the player to go
local actualX, actualY = world:move(player, goalX, goalY)
-- bump.lua takes care of the collision detection for you - if there was a block in the path of player, actualX will be different from goalX.
-- update the player with that instead of goal:
player.x, player.y = actualX, actualY
-- Once an item is no longer needed you can remove it from the world:
world:remove(player)
Update: released 3.0.1 on github & the attached .love files. It fixes one bug on "cross" collisions.
Update: released 3.1.0, the "filter" param in world:move and world:check changes to filter(other) to filter(item, other) - this changes how the filters work, see the bump-demo or the docs for details. I am also including the platforms demo on this branch
Update: released 3.1.2, which includes world:getItems and world:countItems.
Update: released 3.1.3. It fixes a floating point related error, and adds some speed improvements when updating an item
Update: released 3.1.4. It removes one global variable (called '_')