I am trying to make a simple collision detection class for a soccer game. Here is the code:
int Collision(int x1, int y1, int radius1, int x2, int y2, int radius2)
{
int dx = x2 - x1;
int dy = y2 - y1;
int radii = radius1 + radius2;
if ((dx*dy)+(dy*dy)< radii * radii)
{
return true;
}
else
{
return false;
}
}
The problem is with the code returning true or false. Visual Studio says it cannot implicitly convert bool to int, and I understand that, but how can I fix it?
Thanks for any help.
Define your function like this:
Now you can return
trueorfalse. If you keepintthen you need to return an integer value such as0and1but this doesn’t express the function intent.You could also shorten your code a bit: