fork download
  1. bool check_collision(SDL_Rect A, SDL_Rect B )
  2. {
  3. //The sides of the rectangles
  4. int leftA, leftB;
  5. int rightA, rightB;
  6. int topA, topB;
  7. int bottomA, bottomB;
  8.  
  9.  
  10. //Calculate the sides of rect A
  11. leftA = A.x;
  12. rightA = A.x + A.w;
  13. topA = A.y;
  14. bottomA = A.y + A.h;
  15.  
  16.  
  17. //Calculate the sides of rect B
  18. leftB = B.x;
  19. rightB = B.x + B.w;
  20. topB = B.y;
  21. bottomB = B.y + B.h;
  22.  
  23.  
  24. //If any of the sides from A are outside of B
  25.  
  26. if( bottomA <= topB )
  27. {
  28. Left_Collision = 0;
  29. Right_Collision = 0;
  30. Top_Collision = 0;
  31. Bottom_Collision = 1;
  32. return false;
  33. }
  34.  
  35. if( topA >= bottomB )
  36. {
  37. Left_Collision = 0;
  38. Right_Collision = 0;
  39. Top_Collision = 1;
  40. Bottom_Collision = 0;
  41. return false;
  42. }
  43.  
  44.  
  45. if( rightA <= leftB )
  46. {
  47. Left_Collision = 0;
  48. Right_Collision = 1;
  49. Top_Collision = 0;
  50. Bottom_Collision = 0;
  51. return false;
  52. }
  53.  
  54. if( leftA >= rightB )
  55. {
  56. Left_Collision = 1;
  57. Right_Collision = 0;
  58. Top_Collision = 0;
  59. Bottom_Collision = 0;
  60. return false;
  61. }
  62.  
  63. //If none of the sides from A are outside B
  64. return true;
  65. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:1:22: error: ‘SDL_Rect’ was not declared in this scope
prog.cpp:1:34: error: ‘SDL_Rect’ was not declared in this scope
prog.cpp:1:45: error: expression list treated as compound expression in initializer [-fpermissive]
prog.cpp:2:1: error: expected ‘,’ or ‘;’ before ‘{’ token
stdout
Standard output is empty