Arch Game Engine  0.2
collision.cpp
1 #include "collision.h"
2 #include "object.h"
3 
4 Collision::Collision() {}
5 Collision::~Collision() {}
6 
8  if(!outOfBoundsOf(a, b)) {
9  return true;
10  } else {
11  return false;
12  }
13 }
14 
15 bool Collision::overlaps(Object a, Object b) {
16  //if (RectA.Left < RectB.Right && RectA.Right > RectB.Left && RectA.Top < RectB.Bottom && RectA.Bottom > RectB.Top )
17  if ((a.getDestX() < (b.getDestX() + b.getDestW())) && ((a.getDestX() + a.getDestW()) > b.getDestX()) &&
18  (a.getDestY() < (b.getDestY() + b.getDestH())) && ((a.getDestY() + a.getDestH()) > b.getDestY())) {
19  return true;
20  }
21  else {
22  return false;
23  }
24 }
25 
27 {
28  if (((b.getDestX() + b.getDestW()) < (a.getDestX() + a.getDestW())) && (b.getDestX() > a.getDestX()) &&
29  (b.getDestY() > a.getDestY()) && ((b.getDestY() + b.getDestH()) < (a.getDestY()+a.getDestH()))) {
30  return true;
31  }
32  else {
33  return false;
34  }
35 }
36 
38  if(isAbove(a, b) || isBelow(a, b)) {
39  return true;
40  } else if(isRightOf(a, b) || isLeftOf(a, b)) {
41  return true;
42  } else {
43  return false;
44  }
45 }
46 
48  if((a.getPosY() + a.getPosH()) < b.getPosY()) {
49  return true;
50  } else {
51  return false;
52  }
53 }
54 
56  if(a.getPosY() > (b.getPosY() + b.getPosH())) {
57  return true;
58  } else {
59  return false;
60  }
61 }
62 
64  if(a.getPosX() > (b.getPosX() + b.getPosW())) {
65  return true;
66  } else {
67  return false;
68  }
69 }
70 
72  if((a.getPosX() + a.getPosW()) < b.getPosX()) {
73  return true;
74  } else {
75  return false;
76  }
77 }
This class stores information for an Object in the game.
Definition: object.h:12
bool isAbove(Object a, Object b)
Check if the first object is above the second object.
Definition: collision.cpp:47
bool isRightOf(Object a, Object b)
Check if the first object is to the right of the second object.
Definition: collision.cpp:63
bool outOfBoundsOf(Object a, Object b)
Check if two object are not touching.
Definition: collision.cpp:37
bool contains(Object a, Object b)
Check if an object contains another object.
Definition: collision.cpp:26
bool isBelow(Object a, Object b)
Check if the first object is below the second object.
Definition: collision.cpp:55
bool isLeftOf(Object a, Object b)
Check if the first object is to the left of the second object.
Definition: collision.cpp:71
bool isTouching(Object a, Object b)
Check if two objects are touching.
Definition: collision.cpp:7