Page 6 of 8

Re: bump.lua - minimal collision detection lib

Posted: Mon Aug 20, 2012 9:43 pm
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)

Re: bump.lua - minimal collision detection lib

Posted: Mon Aug 20, 2012 9:48 pm
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

Re: bump.lua - minimal collision detection lib

Posted: Mon Aug 20, 2012 9:50 pm
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

Re: bump.lua - minimal collision detection lib

Posted: Mon Aug 20, 2012 9:58 pm
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!

Re: bump.lua - minimal collision detection lib

Posted: Mon Aug 20, 2012 10:02 pm
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.

Re: bump.lua - minimal collision detection lib

Posted: Tue Aug 21, 2012 12:22 am
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.

Re: bump.lua - minimal collision detection lib

Posted: Tue Aug 21, 2012 9:55 am
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

Re: bump.lua - minimal collision detection lib

Posted: Tue Aug 21, 2012 3:46 pm
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.

Re: bump.lua - minimal collision detection lib

Posted: Sun Sep 09, 2012 3:41 pm
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 :)

Re: bump.lua - minimal collision detection lib

Posted: Sun Aug 11, 2013 1:35 am
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?