bump.lua - minimal collision detection lib

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: bump.lua - minimal collision detection lib

Post by Puzzlem00n »

Hey, I love the concept of this library, but I'm currently having trouble figuring out how to use it. Personally, I think the demo is bloated with a lot of stuff that just gets in the way of learning how to use it. I'm not trying to learn how to make an entities system, I'm trying to figure out how to use bump. Sorry, I'm just very annoyed by it. Wouldn't it be easier to drop all the coins and GravityEntity junk? :huh:

I sort of feel like the above makes me sound like more of a lua newbie than I really am. I mean, I could try and go through all that code and learn it eventually, but I just wish I didn't have to.

Again, sorry, it's just a thought I had to let out. I've been really frustrated with going through this demo and trying to isolate the basics.
I LÖVE, therefore I am.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: bump.lua - minimal collision detection lib

Post by kikito »

Puzzlem00n wrote: I sort of feel like the above makes me sound like more of a lua newbie than I really am. I mean, I could try and go through all that code and learn it eventually, but I just wish I didn't have to.
Hi,

I'm sorry to hear that. The truth is that I not only used the demo as a "demonstration" of what bump.lua could do, I also used it as a "testbed" (to test the edge cases - pun intented). I also think that people want to see a platformer, and platformers have some complexity (all that jumping, gravity and friction) that is better handled in an object-oriented way.

Maybe it would be possible to implement a simpler game with no gravity, no coins, no scrolling, no debugging, and no random levels (just one very simple level). This should reduce the needed concepts to 3: player, map, and block(s). It might even be possible to put it in 2 files: main.lua and bump.lua.

Unfortunately, I am not able to do so now. I'm on holidays, and I only have about 15 minutes per day on the computer.

Is there any volunteer to do so? Bonus points: You could even send me a pull request for bonus points (Send it for the master branch, I will create a simple-demo branch and merge it there)

Regards!
When I write def I mean function.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: bump.lua - minimal collision detection lib

Post by Puzzlem00n »

kikito wrote: Maybe it would be possible to implement a simpler game with no gravity, no coins, no scrolling, no debugging, and no random levels (just one very simple level). This should reduce the needed concepts to 3: player, map, and block(s). It might even be possible to put it in 2 files: main.lua and bump.lua.
That would be great! It would make it much easier to file through. I'd be grateful to anyone that could do this.

EDIT: I think I've found a glitch in the most recent version of bump. It appears that the callback "getBBox" is in fact mandatory. Is this intentional? Because, without defining it as you do in the example on bump.lua's github page, I get the error:

Code: Select all

bump.lua:322: attempt to call method "getBBox" (a nil value)
I LÖVE, therefore I am.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: bump.lua - minimal collision detection lib

Post by Roland_Yonaba »

From what I can see, bump.collision, bump.endCollision, bump.shouldCollide and bump.getBBox were all defined for the purposes of the demonstration test. They are just shortcuts to some objects/entities methods.
If they appear to be called in some parts of bump's code, that's because they are overridable methods, that you can implement for specific needs.
Flexibility, I guess...

Code: Select all

-- (Overridable). Called when two objects start colliding
-- dx, dy is how much you have to move item1 so it doesn't
-- collide any more
function bump.collision(item1, item2, dx, dy)
end

-- (Overridable) Called when two objects stop colliding
function bump.endCollision(item1, item2)
end

-- (Overridable) Returns true if two objects can collide, false otherwise
-- Useful for making categories, and groups of objects that don't collide
-- Between each other
function bump.shouldCollide(item1, item2)
  return true
end

-- (Overridable) Given an item, return its bounding box (l,t,w,h)
function bump.getBBox(item)
  return item:getBBox()
end
Last edited by Roland_Yonaba on Mon Aug 20, 2012 5:21 pm, edited 1 time in total.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: bump.lua - minimal collision detection lib

Post by Puzzlem00n »

Perhaps, although it says in bump's documentation that none of the callbacks are mandatory. But without adding

Code: Select all

function bump.getBBox(item)
  return item.l, item.t, item.w, item.h
end
nothing works, indicating that writing this is mandatory.
I LÖVE, therefore I am.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: bump.lua - minimal collision detection lib

Post by Roland_Yonaba »

Puzzlem00n wrote:Perhaps, although it says in bump's documentation that none of the callbacks are mandatory. But without adding

Code: Select all

function bump.getBBox(item)
  return item.l, item.t, item.w, item.h
end
nothing works, indicating that writing this is mandatory.
Got you, now. Yes, you'right.
The argument you are passing to bump.getBBox, meaning in fact, all the itemps you add to bump have to implement a sort of getBBox() method.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: bump.lua - minimal collision detection lib

Post by Puzzlem00n »

Oh, so it isn't mandatory to override it, but it is mandatory to give all the items their own getBBox method if you don't? Because that's what I'm getting here.

Man, this lib is way more complicated than I thought it would be.
I LÖVE, therefore I am.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: bump.lua - minimal collision detection lib

Post by Roland_Yonaba »

I guess yes.
But I won't say bump is complicated. Cause actually, the way bump works seems pretty clear, to me.
Reading the intructions given in the README.
After all, it tends to be a minimalistic tool for AABB collision handling. .. I can't be way too complex at the same time. :awesome:

Well, if you're just going to be working with rectangular shapes, you can mod bump.getBBox function this way (line 316 in bump.lua)

Code: Select all

-- (Overridable) Given an item, return its bounding box (l,t,w,h)
function bump.getBBox(item)
  return (item:getBBox()) or item.l, item.t, item.w, item.h
end
You won't need anymore to implement bump.getBBox.
Therefore, collidable items you will pass to bump.add should have the required l,t,w,h keys.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: bump.lua - minimal collision detection lib

Post by bartbes »

Roland_Yonaba wrote:

Code: Select all

-- (Overridable) Given an item, return its bounding box (l,t,w,h)
function bump.getBBox(item)
  return (item:getBBox()) or item.l, item.t, item.w, item.h
end
Well that won't work. Let's see, if an item doesn't have a getBBox function, it will error, not just that, if it does, only the first return value will get used, and the rest will be item.t, w and h.
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: bump.lua - minimal collision detection lib

Post by Puzzlem00n »

bartbes wrote:
Roland_Yonaba wrote:

Code: Select all

-- (Overridable) Given an item, return its bounding box (l,t,w,h)
function bump.getBBox(item)
  return (item:getBBox()) or item.l, item.t, item.w, item.h
end
Well that won't work. Let's see, if an item doesn't have a getBBox function, it will error, not just that, if it does, only the first return value will get used, and the rest will be item.t, w and h.
Darn. Before I read this, I thought that seemed like exactly what I was looking for.


Oh, and to Roland, I'm not saying it's complicated, I'm just saying it's more complicated than I thought. I have a tendency to overestimate myself. I've been having a ton of bugs in the test game I'm working on to prepare for the coming Ludum Dare, and they all pretty much relate to bump. It's just been kinda frustrating, you know?
I LÖVE, therefore I am.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest