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 detection.

#772 - Lord Graga - Fri Jan 10, 2003 3:12 pm

Code:

void CheckCollision (u8* map)
{
   int blo;
   if(map[((self.y/16)*32)+((self.x+15)/16)]==2) blo = 1;
   if(map[((self.y/16)*32)+((self.x+15)/16)]==2) blo = 1;
   if(map[((self.y/16)*32)+((self.x+15)/16)]==2) blo = 1;
   if(map[((self.y+15/16)*32)+((self.x+15)/16)]==2) blo = 1;
   if(blo==1) dir[di]=1;
}


that is the collision code.

Code:

if(dir[0]==1) self.y--;


That is how i check if it colides.
The directions is:
|_0_|UP
|3+1|LEFT,RIGHT
|_2_|DOWN

What is wrong? it is a 16*16 map, it works some places, and some places it doesn't.

#777 - anli - Fri Jan 10, 2003 3:47 pm

Initialize the local variable blo to 0.

int blo=0; instead of just int blo;

/anli