If you can't pause the program, perhaps you can spawn a child process and have THAT sleep. Or a thread. But I doubt the real solution is to sleep. The real problem, I would imagine, is that it subtracts more than once for a collision, so change it so it only subtracts once.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
I imagine that how the collision is detected isn't as important as how it's handled. What I imagine you don't want is this...
bool collisionHasOccurred; // set true somewhere when monster and player share the same coordinates, however that is determined
while(true)
{
// code
if(collisionHasOccurred)
{
// subtract a life
}
// code
}
This might be better...
bool collisionHasOccurred
time_t lastCollisionTime;
while(true)
{
// code
if(collisionHasOccurred && (time(0) - lastCollisionTime > 5))
{
// subtract a life
lastCollisionTime = time(0);
}
// code
}
You can now only lose a life at most every 5 seconds. Enough time to get un-collided however you want to do that.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711
>> I'd just like to say that i love you <3. lol that worked so perfectly. The first example was exactly what i was doing too. thanks a ton
I love you too. :* Glad it worked.
VernonDozier
Posting Expert
5,527 posts since Jan 2008
Reputation Points: 2,633
Solved Threads: 711