   2D Collision detection
  Hi.I ve got a terribly headache with collision detection in my game.The problem is that any, ANY code made by me or by anyone doesn t work. Im programing it in SDL and i m using bmps por my sprites, and my Transparent color is black. I use SDL_SetKeyColorIve tried this:int SDL_Collide( SDL_Surface *SA , int Ax1 , int Ay1 , SDL_Surface *SB , int Bx1 , int By1){int Ax2 = Ax1 + SA->w;int Ay2 = Ay1 + SA->h;int Bx2 = Bx1 + SB->w;int By2 = By1 + SB->h;if( Bx2 < Ax1 )return 0;if( Bx1 > Ax2 )return 0;if( By2 < Ay1 )return 0;if( By1 > Ay2 )return 0;int bx1 = ( Ax1 > Bx1 ) ? Ax1 : Bx1;int bx2 = ( Ax2 < Bx2 ) ? Ax2 : Bx2;int by1 = ( Ay1 > By1 ) ? Ay1 : By1;int by2 = ( Ay2 < By2 ) ? Ay2 : By2;Uint32 pxlA;Uint32 pxlB;Uint8 rA , gA , bA;Uint8 rB , gB , bB;for( int y = by1 ; y <= by2 ; y++ ){for( int x = bx1 ; x <= bx2 ; x++ ){  if(( SDL_GetPixel( SA , x - Ax1 , y - Ay1 ) != TRANS )  && ( SDL_GetPixel( SB , x - Bx1 , y - By1 ) != TRANS ))return 1;}}return 0;}also, ive tried this:int colicion(NAVE ship, ENEMY enemigo){double d1, d2;double i1, i2;double a1, a2;double b1, b2;i1=ship.x + (ship.w-(ship.w*0.80))/2;i2=enemigo.x + (enemigo.w-(enemigo.w*0.80))/2;d1=i1 + (ship.w*0.80);d2=i2 + (enemigo.w*0.80);a1=ship.y + (ship.h-(ship.h*0.80))/2;a2=enemigo.y + (enemigo.h-(enemigo.h*0.80))/2;b1=a1 + (ship.h*0.80);b2=a2 + (enemigo.h*0.80);/*i1=ship.x;i2=enemigo.x;d1=i1+ship.w;d2=i2+enemigo.w;a1=ship.y;a2=enemigo.y;b1=a1+ship.h;b2=a2+enemigo.h;if (b1 < a2) return 0;    if (a1 > b2) return 0; if (d1 < i2) return 0;    if (i1 > i2) return 0;    return 1;}the collision always is detected anywhere except in the object, and almost all the time gives me error messages.I have tried to debug it and it says the collision isnt ok.What should i do. This terrible!!!HELP!!!!!!!!!!!!!!!!!!! 
  Really, that''s a mess of a code posting. I don''t know how you know what it does, and the lack of commenting doesn''t help. This is what I think you should do. Decide now whether you need a per pixel solution, or if a solution using bounding regions would suffice.In my code, the original collision code was done per pixel, but I found it to be too slow. That''s when I rewrote that part of the game and produced this demo here.If you decide to go with the ellipse method like I use, and you have any troubles, e-mail me and I''d be glad to help you out in any way I can.PS: Is this for a sidescroller? ;  Oh, sorry about the undocumenting. Its a bounding box colition and a pixel collision.The game is an R-Type type game or Galaxian game, but with more movement.Please i need help. Why the collisions never occur in the right moment.I need help!!!!!!!!!!! ;  debug/debug/debug. Hit F5, put a couple of breakpoints....did you try bounding-box only? Have you checked with two simple SDL surfaces? Without any kind of transparency? With transparency? Did you try to visualise the result (like paint the colliding pixels in bright red)? Are you getting the right colors from the pixels with the GetPixel function? What''s the bitdepth of the pixels? ect... We can''t help you if you don''t provide us with more stuff anyway, like a basic sample application.  