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.

Coding > Collision in wraparound BG

#7760 - maniac - Tue Jun 24, 2003 8:53 am

I scroll a 1024x1024 map on a 256x256 wraparound bg and check a 32x32 sprite for collisions with the bg.

The problem occurs only when the bg is wrapping, then the collision check checks one row below the row it is supposed to check (when the bg doesn't wrap it works as it's supposed to). The code I use is this:

x = (bkg.x+player.x) >> 3;
y = (bkg.y+player.y) >> 3;
b = (x&31) + ((y-1&31) << 5);

if(collision[b] == 1)
return 1;

Anyone who can see a prob with this code or have some suggestions to solve the wraparound issue?

#7763 - Lord Graga - Tue Jun 24, 2003 9:54 am

ehh... what about doing a if(player.x > BGSIZE) player.x = 0;

#7767 - maniac - Tue Jun 24, 2003 10:41 am

well, thanks for the answer but i solved it anyway .. (but not by using a crappy if() :)