Mail Archives: djgpp/1998/02/17/15:12:51
Do you have Allegro? I recommend it. It already has timer, keyboard, screen,
sound and othter things (made for games, but completely free). Then in your
code, have something like this (excuse my mess of comments, but I don't know how
my newsgroup reader will allign messages and word wrap them):
#include <allegro.h>
volatile int minutes;
volatile int seconds;
volatile char time_is_up = 0;
void count_down_timer()
{
if (!doit)
return; // code is not needed right now
if (seconds == 0) // take away a minute
{
seconds = 59;
if (minutes == 0)
{
time_is_up = 1;
remove_int(count_down_timer); // disables on list
}
minutes--;
}
else
seconds--; // just take 1 away from seconds
}
END_OF_FUNCTION(count_down_timer) // IMPORTANT!
int main()
{
allegro_init();
install_timer();
LOCK_VARIABLE(minutes);
LOCK_VARIABLE(seconds);
LOCK_VARIABLE(doit);
LOCK_FUNCTION(count_down_timer);
// 1000 is the millisecond delay between executions
/* your code here. when you want to start the clock, set the times in minutes
and seconds and just put this in. */
install_timer_ex(count_down_timer, 1000);
/* make sure you adjust time_is_up as necessary. The function automaticly takes
itself off the timer list when it reaches 0 */
return 0;
}
/* You can get allegro at http://www.talula.demon.co.uk/allegro/ if you don't
already have it.
--
"DeHackEd"
EMail address not given out due to low-life spammers.
*/
- Raw text -