gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > collition with the background

#47511 - ghost Leinad - Sun Jul 10, 2005 12:00 am

well...i was thinking about make this on my own...but im also like to ask you guys about the collition with the background...

i will look now for some algorithms to make this posibble, but can you help me to find this stuff???

im making a game that i saw in a cel phone and im just missing the collitions, at this point my characther never dies :(

sorry about all the problems, but averytime that i think i got it, new things come out :S...but well you're very kind...thanks in advance
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#47515 - tepples - Sun Jul 10, 2005 3:30 am

Step 1: Your sprite occupies a box. Which tiles does this box overlap?
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#47560 - ghost Leinad - Sun Jul 10, 2005 10:36 pm

:S
:S
:S
:S
:S
:S
:S

well, i do not understand this very well, so, tell me if im wrong...

you're saying that my sprite is a box (but this box can move up and down). i know the numbers of the tiles this sprite is in. oh god i really dont understand you :S jejeje

well let me explain a little more about the game im (trying) to make

im using 256*256 text maps...and this maps are constantly changing, in fact i change the last two columns every 16 frames...because of this i need to check constantly if my sprite collides with the background...

in few words...i need the step two!!!!...(and explain the one if you can, please)
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#47563 - Miked0801 - Sun Jul 10, 2005 10:46 pm

Your Hero (sprite) occupies a square area right? Keep track of this area and every tic see which BG box areas it collides with. There is no hardware acceleration for this - you have to do it yourself. Aligned Box/Box collisions like we're talking about here are very fast to compute though :)

#47575 - yuriks - Sun Jul 10, 2005 11:59 pm

I too want to know this, but, how do know what tiles my player is overlapping? i would have 2000 wall objects to check (80x25 board) wouldn't it be slow?
_________________
---yuriks---

#47577 - sajiimori - Mon Jul 11, 2005 12:07 am

Divide a pixel coordinate by the size of a tile to get the tile coordinate. Use that idea to find the tiles that a rectangle covers, given the pixel coordinates of its corners.

#47579 - yuriks - Mon Jul 11, 2005 12:17 am

Thanks, i never thought of doing a grid based check, i always tried to compare the bounding box of the player with the bounding box of each tile.
_________________
---yuriks---

#47666 - ghost Leinad - Tue Jul 12, 2005 2:54 am

ok, yesterday i tried to make this collision detection algorithm on my own...and guess what...well, i did it!!!

but i think it is a pretty lame algorithm, but is seem to work fine...

well first i made a flag called collide with a value of 0 if there's no collision and 1 if there's a collision

then i made a case function first for the position on the screen (x axis), and then for the sprite position (on the y-axis) and then according to this get the number of the tile this sprite is occuping...

the i just compare if this numbre if tile is diferent of 0, 0 in my tile map is the only tile you can move...so is the tile im comparing is aqual than a value diferent from 0 it is a collition....





well, now works with square sprites and square tiles...
but what about non square tiles...i dont know, circles or triangles...how do i ckeck them????
i habe a briefly idea on non-square sprites so in this moment i just need the algorithm for non-square tiles
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#47668 - ghost Leinad - Tue Jul 12, 2005 4:08 am

and before i forgot...let me tell you that my sprite is a bat, but this bat is an animation and uses 3 different frames...well the problem is that the frames aren not from the same size...(when the bat flutters up occupies more space than when the bat flutters down)

look, a drawing

bat
{
() () ()
}
fr1 fr2 fr3

what do you recommend me should i just take in count the body of my bat, or the wings too???
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#47670 - LOst? - Tue Jul 12, 2005 4:57 am

ghost Leinad wrote:

what do you recommend me should i just take in count the body of my bat, or the wings too???


Use the middle of the body, have some global size of all frames... so that the wings may not collide when they are spread. If you really want every frame to collide depending on the size, you have to save size information with the frames data.
_________________
Exceptions are fun

#47733 - Miked0801 - Tue Jul 12, 2005 10:06 pm

Circle collides are very fast as well - get the square of the distance from the centers and compare against the square of their combined radiuses.

Polygonal collision handling - well don't go there for a while. Get these down first then come back to thsi as it's much more complex.

#47753 - ghost Leinad - Wed Jul 13, 2005 2:23 am

well you can download a beta version right from here

http://www.angelfire.com/ab8/leinadcharm/cavebat.GBA

tell me what do you think???
_________________
All human wisdom is summed up in these two words, - 'Wait and hope"
****************************************
My site www.myth-world.net and www.bmrpg.com :)

#50903 - biubid_boy - Sun Aug 14, 2005 12:24 pm

Nice! First I thought you had to press the A button repeditively. Hard work. LOL. Good job.