[Solved] check of coordinates in a tick does not work (opengl) [closed]


There is an floating point precision issue in your code. When 2 floating point values are tested for equality, then an epsilon should be used:

e.g. A == B should be done like

fabs(A-B) < espi

where A and B are floating point numbers and espi is a very small value.

Change your code like this:

void tick(int)
{
   const double epsi = 0.0001;
   if (fabs(coord[0]-fruitcootd[0]) < epsi &&
       fabs(coord[1]-fruitcootd[1]) < epsi &&
       !eat )
    {
        cout<<1<<endl;
        eat = 1;
    }

    .....
}

solved check of coordinates in a tick does not work (opengl) [closed]