I want to have my circle to circle collision checker in a seperate class so it can be used by different objects, ig. player to enemy, player to score or player to health. So I made a function checkCol in my class gameClass, which returns true if there is a collision.
The function takes the x and y coordinates of both circles and the corresponding radius and with pythagoras measures if the lenght between the middle of the circles is smaller than both the radius combined, if it is the function returns true.
classes.h:
class gameClass
{
public:
bool checkCol( int x1, int y1, int rad1, int x2, int y2, int rad2);
};
extern gameClass gameObject;
classes.cpp:
bool gameClass::checkCol( int x1, int y1, int rad1, int x2, int y2, int rad2)
{
if ((sqrtf( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1) * ( y2 - y1) )) < ( rad1 + rad2 ))
{
return true;
}
else
{
return false;
}
}
game.cpp:
for ( int i=0 ; i<enemies ; i++ )
{
if ((gameObject.checkCol( player.x, player.y, player.rad, enemy[i].x, enemy[i].y, enemy[i].rad )) == true )
{
//do stuff
}
}
When i run it, it gives me an error in game.cpp: "Function does not take 6 arguments:
But when i hover over both the gameObject.checkCol( //arguments ) in both game.cpp and classes.cpp it shows the correct variables, but when i hover over checkCol( //arguments ) in classes.h it shows checkCol( int x1, int y1, int) it leaves everything else out.
i tried rebuilding/cleaning the solution but that wouldn't work.
Debug output:
1>d:\template\classes.h(79): error C2143: syntax error : missing ')' before 'constant' 1>d:\template\classes.h(79): error C2143: syntax error : missing ';' before 'constant' 1>d:\template\classes.h(79): error C2059: syntax error : ')' 1>d:\template\classes.h(79): error C2238: unexpected token(s) preceding ';' 1>d:\template\game.cpp(67): error C2660: 'gameClass::checkCol' : function does not take 6 arguments
Screenshots mousehovers:
classes.h:

classes.cpp:

game.cpp:















