From: arg AT whangomatic DOT freeserve DOT co DOT uk (Andrew R. Gillett) Newsgroups: comp.os.msdos.djgpp Subject: Re: Game Speed Date: Sun, 17 Oct 1999 14:32:08 +0100 Organization: www.release-dates.co.uk Lines: 54 Message-ID: References: NNTP-Posting-Host: modem-131.spotted-trigger.dialup.pol.co.uk X-Trace: news8.svr.pol.co.uk 940167148 18465 62.137.47.131 (17 Oct 1999 13:32:28 GMT) NNTP-Posting-Date: 17 Oct 1999 13:32:28 GMT X-Complaints-To: abuse AT theplanet DOT net X-Newsreader: MicroPlanet Gravity v2.12 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com In comp.os.msdos.djgpp, Snowman wrote: > Hello everybody > > I programmed a simple game in C. > (I used DJGPP and ALLEGRO) > But the game runs on different Computers with > a different speed. > Is it possible, that the game runs on all > Computers with a similar speed ? > Please Help me immidiately . Here is a brief outline of what you need to do: - Create an interrupt which is called every 60th of a second (or whatever you want the frame rate to be). - In the interrupt, increase a value (I call it timer_value) by 1. - Set timer_value to 0 before the main game loop starts. - The main game loop is separated into two parts - one which does the calculations (and input), and ones which draws the graphics. The main game loop should look something like this: while (not_finished) { if (timer_value) { // Calculations go here if (--timer_value <= 0) { timer_value = 0; // Draw the graphics here } } } You can also add an extra value (which I call time_waiting) which prevents the game from locking up on very slow computers. Change the relevant line to this: if ( (--timer_value <= 0) || (++time_waiting == 4) ) and then set time_waiting to 0 inside the loop. This will make it so that it never skips more than four frames at once. -- Andrew Gillett http://argnet.fatal-design.com/ ICQ: See homepage "I hate society, Stew. I'm like Skeletor in that respect." - Richard Herring