bump.lua - minimal collision detection lib

Showcase your libraries, tools and other projects that help your fellow love users.
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 »

bartbes wrote: 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.
Sorry, you're totally right about the err, if item doesn't have a getBBox function.
The correct version will be:

Code: Select all

-- (Overridable) Given an item, return its bounding box (l,t,w,h)
function bump.getBBox(item)
  return item.getBBox and (item:getBBox()) or item.l, item.t, item.w, item.h
end
Actually it will work - I tried it - because everywhere in bump's code where getBBox is invoked (line 183), it is supposed to return 4 args. :

Code: Select all

  -- if the new bounding box is different from the stored one
  local l,t,w,h = bump.getBBox(item)
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 »

Roland_Yonaba wrote:The correct version will be:

Code: Select all

-- (Overridable) Given an item, return its bounding box (l,t,w,h)
function bump.getBBox(item)
  return item.getBBox and (item:getBBox()) or item.l, item.t, item.w, item.h
end
Ah, thanks a lot! Kikito, you should consider putting something like that in the master copy. :D
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 »

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 and (item:getBBox()) or item.l, item.t, item.w, item.h
end
You don't need item:getBBox(). That was just an example implementation. If your items don't have a :getBBox method, it is fine to do this (adapt to however your items return a bounding box):

Code: Select all

function bump.getBBox(item)
  return item.l, item.t, item.w, item.h
end
Last edited by kikito on Tue Aug 21, 2012 1:34 pm, edited 1 time in total.
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: You don't need item:getBBox(). That was just an example implementation. If your items don't have a :getBBox method, it is fine to do this (adapt to however your items return a bounding box:

Code: Select all

function bump.getBBox(item)
  return item.l, item.t, item.w, item.h
end
Oh, alright then. Even better.

I feel that the majority of my comments on this library have been negative, so I'll take this opportunity to say that I do appreciate your work on it and as soon as I get it working I'm sure it'll become very useful in the future!
I LÖVE, therefore I am.
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 and (item:getBBox()) or item.l, item.t, item.w, item.h
end
Nope, still won't work, the ternary doesn't work quite right with multiple return values, in this case it returns
((item:getBBox()) or item.l), item.t, item.w, item.h

Actually, your parentheses only make it worse (not that it will work without them), because they force only the first return value to be used.
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 »

@bartbes:
Let's say, that I have, for instance :

Code: Select all

obj  = { a = 1, b = 2, c = 3, d  =4 }
function obj:out() return self.a,self.b,self.c,self.d end

function out(i)
	return i.out and (i:out()) or i.a, i.b, i.c, i.d
end

local a,b,c,d = out(obj)
print(a,b,c,d) --> 1, 2, 3, 4
obj.out = nil
a,b,c,d = out(obj)
print(a,b,c,d) --> 1, 2, 3, 4
So, what did I missed ? :huh:

@kikito: sorry for being off-topic, but I needed to understand bartbes' point.
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: So, what did I missed ? :huh:
That your code only works because the names happen to be the same:

Code: Select all

Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> obj = { w = 1, x = 2, y = 3, z = 4 }
> function obj:out() return self.w, self.x, self.y, self.z end
> function out(i)
>> return i.out and (i:out()) or i.a, i.b, i.c, i.d
>> end
> print(out(obj))
1	nil	nil	nil
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 »

bartbes wrote:That your code only works because the names happen to be the same
And yes, I got your point.
Actually, an if-return-else-return-end works fine. Thanks pointing that out.
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 »

Hi,

I am back from my holidays. I did the "simplified demo" that Puzzlem00n was requesting some time ago. It has its own branch on github now:

https://github.com/kikito/bump.lua/tree/simpledemo

I'm also attaching the .love file here:
bump-simpledemo.love
(7.36 KiB) Downloaded 207 times
This is probably not needed any more, but it was a good exercise after 3 weeks not touching any code :)
When I write def I mean function.
tilmah
Prole
Posts: 3
Joined: Sun Jun 02, 2013 11:53 pm

Re: bump.lua - minimal collision detection lib

Post by tilmah »

Hi Kikito,
To remove all static objects in Bump, can you simply make a huge selection. For example the width and height of the screen (perhaps 800 by 600)?

Anyway... I am trying to hack a one way platform system using ATL and Bump.

I found a way of getting the information of a layer of tiles and adding static objects in bump in their place when the character jumps/reaches a certain height on screen, but I can't seem to do the reverse in removing them when the character goes below that height.

It worked when used a 'static' table into Bump. So it seems plausible.

Any suggestions would be appreciated.

Again thanks for your libraries.
p.s. Why do you have 't' and 'l' in Bump instead of 'x' and 'y'? What do they stand for?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest