24 lines
484 B
C++
24 lines
484 B
C++
//Collision checker class body
|
|
|
|
#include"collisions.h"
|
|
|
|
char check(SDL_Rect rectA, SDL_Rect rect2){
|
|
|
|
int collision;
|
|
|
|
int aX = rectA.x;
|
|
int aY = rectA.y;
|
|
int a2X = rectA.x + rectA.w;
|
|
int a2Y = rectA.y + rectA.h;
|
|
|
|
int bX = rectB.x;
|
|
int bY = rectB.y;
|
|
int b2X = rectB.x + rectB.w;
|
|
int b2Y = rectB.y + rectB.h;
|
|
|
|
if(aX >= bX and aX <= b2X or a2X >= bX and a2X <= b2X) collision += 1;
|
|
if(aY >= bY and aY <= b2Y or a2Y >= bY and a2Y <= b2Y) collision += 2;
|
|
|
|
return collision;
|
|
};
|