Collision

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>

using namespace std;

class Box
{
   public:
      double Position;   // Length of a box
      double Size;// Breadth of a box
};

Box box;
Box box2;


bool CheckCollision(Box &box, Box &box2) // AABB - AABB collision
{
    // Collision x-axis?
    bool collisionX = box.Position.x + box.Size.x >= box2.Position.x &&
        box2.Position.x + box2.Size.x >= box.Position.x;
    // Collision y-axis?
    bool collisionY = one.Position.y + one.Size.y >= two.Position.y &&
        two.Position.y + two.Size.y >= one.Position.y;
    // Collision only if on both axes
    return collisionX && collisionY;
}

int main()
{

    box.x = 1;
    box.y = 1;
    box2.x = 2;
    box2.y = 2;
    if(CheckCollision(box,box2) == true)
    {
        cout << "Collision" << endl;
    }
    return 0;
}


I need help i get error
Last edited on
Last edited on
Please don't create duplicate threads for the same question. It wastes peoples' time.

http://www.cplusplus.com/forum/general/196201/
Topic archived. No new replies allowed.