I am trying to get a timer to count two times but I have been having trouble with it it will perform its task once but not again, I have no idea where I am going wrong and I can find anything on the internet that helps as I am running my code in a game loop that runs at 1000FPS.
This is the header code.
clock_t endBoost = clock() + 3.0f * CLOCKS_PER_SEC;
clock_t slow = clock() + 5.0f * CLOCKS_PER_SEC;
This is the main code.
bool overheat = false;
if(overheat == false)
{
if(myEngine->KeyHeld(Key_Space))
{
timer = clock();
if(timer < endBoost)
{
stringstream outBoost;
outBoost << "!BOOST!";
myFont->Draw(outBoost.str(), 300, 200);
outBoost.str("");
carSpeedIncrement = 0.1f;
}
}
}
if(timer > endBoost)
{
overheat = true;
}
if(timer < slow && overheat == true)
{
overheat = false;
carSpeedIncrement = 0.1f;
}
Any Help is Appreciated.
It looks like you’re initializing
endBoostandslowand never changing their values. But these are initialized based on theclock()value and never changed. The current value oftimerwill very quickly be greater than bothendBoostandslowand will forever remain so.