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 > platform game collision test with map

#77727 - aik6980 - Sun Apr 02, 2006 6:04 pm

Hi guys,

Now, I'm doing my game project. It's a platform game like mario. Here's a question

Code:


u8 collisionTest_PVMy(){
   s16 tx=0,ty=0;
   tx=alien.px/8;
   ty=alien.py/8+3;
   if(bgCollision[(tx+(++ty)*32)]==0x0004){
      return HITDOWN;
   }
   else
      return OK;

   return 0;
}
u8 collisionTest_PVMx(){
   s16 tx=0,ty=0;
   tx=alien.px/8+1;
   ty=alien.py/8;
   if(bgCollision[((++tx)+(ty)*32)]==0x0004){
      return HITRIGHT;
   }
   return OK;
 



There are my Collision test code, it's work but is it better to use vector concept rather than check it directly to array?
The problem is, it will grow bigger later when my whole stgabe is full of character and monster.

I use MapEd building map and collision map
any good idea?

Thank alot[/code]

#77740 - sajiimori - Sun Apr 02, 2006 8:36 pm

Tile collision still works well when you have lots of moving characters.

If you mean that the function will get long because you plan on making another copy of the collision code for every object in the level, the solution is to reuse the same code by making the object a parameter instead of assuming it's 'alien'.

If you find yourself writing repetitive code, there is probably something wrong.

Also: Use ints instead of smaller types normally, initialize your variables once if you can, and factor out the duplicated tile check code into a function like tileIsSolid(x, y).