hi. i am working on a 2D sidescroller. I am using a switch type deal:
void NoTouchy();
int Collision;
void NoTouchy()
{
if ( FloorlvlY < mY && FloorlvlX == mX )//Floor is 35px below main sprite?
{
Collision = 1;
}
switch ( Collision )
{
case 1: //Under: //*****************************************************************
dbText ( 300, 300, "Floor is Under mX :D" );
mY = FloorlvlY;
break;
//if (!=not mX is in corner touching two boundaries) break;
case 2: //Above:
if ( FloorlvlY >= mY )
{
mY = ( FloorlvlY - 35 );
mX;
}
break;
case 3: //RightOf:
if ( FloorlvlX >= mX )
mY = ( FloorlvlX + 11 );
break;
case 4: //LeftOf:
if ( FloorlvlX <= mX );
mY = ( FloorlvlX - 11 );
break;
default:
FreeFall();
}
}
First off, when the statement detects whether the main sprite's mX matches FloorlvlX belonging to the floor under the main sprite, I would like the detection to extend the entire length of the floor - not just the the one pixel at the top right of the image.
Secondly, is this an ideal implementation for a collision? Will it bog down my memory? Is there a better way? Please note that the switch statement will find its way into the main game loop (LoopGDK()) through a set of functions it presides in.
Don't Clap, Just Throw Money!