I'm working on making a Simon game in Allegro. I'm trying to get the pattern to show on the screen in a constant rhythm (I want the color of the button to change for 3 seconds, then change back, then after three seconds change again and so on). To do this I'm trying to implement a sleep function inside the loop that shows the pattern (for test purposes my pattern only consists of 5 elements right now). This pattern showing loop is nested inside my game loop. Here's the code:
#include "base_game_entity.h"
#include <allegro>
int main(){
initialize(); //this contains all the graphics setup and keyboard install
int i = 0; //this will be the while loop counter
while(!key[KEY_ESC]){
i = 5
while(i > 0){
//I'm only using the console to test the sleep function for now
cout << i << endl;
Sleep(3000);
i--;
}
}
}
END_OF_MAIN()
//Here is my sleep function
//I included time.h in base_game_entity.h already which is why it isn't here
void sleep(clock_t wait)
{
clock_t goal;
goal = wait + clock();
while( goal > clock());
}
This code compiles but the console just writes out the 5 numbers instantly instead of waiting. Any suggestions?
Okay that was a mistake I made because I had to type everything in from my memory. I don't have the code on hand (I'm in class and I forgot my laptop at home). I just arrived home from a trip and this was the first chance I had to ask the question, so I figured I'd just ask already that way when I get home I can try to fix the issue.