Today I coded in a timed delay thing into the game's main loop. This way things don't go lightning-fast on the player... it's limited to doing stuff once every 500 miliseconds now. I guess you could call each interval the game does stuff in a "frame", yes? I also added a keyboard input function, to check if there was a valid keypress, and return its virtual key identifier (for example, VK_ESCAPE)
Here's my main() function, to show you how the main loop looks so far. I think I just need to work on the actual gameplay now...
int main(){ Init(); // Sets up the HUD details and console title bool quit = false; int timestat = 0; // Because each frame is half a second, I need // a way to know when to increment the HUD's time // field - that is, once every two frames. while (!quit) { unsigned long currtime = GetTickCount(); hud.Draw(0, 0); // The arguments specify the x,y coord of the // top-left corner of the HUD. GameInfo.score += 10; if (timestat == 0) timestat = 1; else if (timestat == 1) { timestat = 0; GameInfo.time += 1; } // During the delay time, when nothing is being done, I watch for // keypresses. I used to have it outside the while, but there was // a visible delay between pressing and exiting when the key was // pressed after the check and during the delay. Placing it in the // loop lets me check as many times as the while iterates per frame, // and because the game doesn't take long to process what I have so // far, there's no visible delay in quitting. while (currtime+500 > GetTickCount()) if (CheckForKeypress() == VK_ESCAPE) { quit = true; break; } } }
EDIT: If you're wondering, and I'm sure you are, the game looks no different now than a month ago. The only differences are internal, except that I'm actually displaying the game's data in the HUD, not just the "static" lines. Nothing new though, just zeroes! (Although I use a line of six zeroes as a static to the right of the Score line, so it looks like we've got a sort of zerofilled score going on when the score is drawn on top of it. I likey.)
Is your goal to achieve a fixed 'frame-rate' simulation? I suspect this is what you're doing (at 2fps) but if you're just trying to change the speed the game runs for your computer then shouldn't you just be basing your updates on the time elapsed?