I am working on a AABB collision detection function. I am getting a “expression must have class type” on my “one” variable in my checkCollision function. I have googled this error and have looked at other sites but with no luck on finding an answer. I am learning about pointers and passing by reference. here is my short piece of code.
#include<iostream>
using namespace std;
bool CheckCollision(GameObject &one, GameObject &two); // AABB - AABB collision
class GameObject
{
public:
int Position;
int Size;
int x;
int y;
};
int main()
{
GameObject one,two;
one.x = 0;
one.y = 0;
one.Position = 0;
one.Size = 0;
two.x = 0;
two.y = 0;
two.Position = 0;
two.Size = 0;
cout << CheckCollision(one, two) << endl;
system("pause");
return 0;
}
bool CheckCollision(GameObject &one, GameObject &two) // AABB - AABB collision
{
// collision x-axis?
bool collisionX = one.Position.x + one.Size.x >= two.Position.x &&
two.Position.x + two.Size.x >= one.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;
}