make a timer
-
Hello I want to make a timer in maze.The timer should countdown to reach 0 and if the player doesn't reach to end he/she lose the game. I want to denote that if player reach to end timer should stopped working. How can I do it? Thanks anyone help me.
-
Hello I want to make a timer in maze.The timer should countdown to reach 0 and if the player doesn't reach to end he/she lose the game. I want to denote that if player reach to end timer should stopped working. How can I do it? Thanks anyone help me.
I hope that you have the code for your "maze". What kind of application is it? Assuming your main thread has a message pump, you could run a timer on a separate thread, and have it post a message to the main thread after the time is over. There may be other messages to be processed in the queue, but then again, Windows isn't an RTOS...
Workout progress:
Current arm size: 14.4in
Desired arm size: 18in
Next Target: 15.4in by Dec 2010Current training method: HIT
-
I hope that you have the code for your "maze". What kind of application is it? Assuming your main thread has a message pump, you could run a timer on a separate thread, and have it post a message to the main thread after the time is over. There may be other messages to be processed in the queue, but then again, Windows isn't an RTOS...
Workout progress:
Current arm size: 14.4in
Desired arm size: 18in
Next Target: 15.4in by Dec 2010Current training method: HIT
Rajesh R Subramanian wrote:
but then again, Windows isn't an RTOS...
Too bad, sir: I need to kick out the player with the nanosecond precision... :-D :laugh: :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hello I want to make a timer in maze.The timer should countdown to reach 0 and if the player doesn't reach to end he/she lose the game. I want to denote that if player reach to end timer should stopped working. How can I do it? Thanks anyone help me.
Create a secondary thread with a CTimer and a countdown counter; I don't think this is much difficult. At each "pulse" (either compare delay or Sleep), send a message to the main application thread to display the time left and when the countdown is finished, send a message to the main application to display "You FAIL". Max.
Watched code never compiles.
-
Create a secondary thread with a CTimer and a countdown counter; I don't think this is much difficult. At each "pulse" (either compare delay or Sleep), send a message to the main application thread to display the time left and when the countdown is finished, send a message to the main application to display "You FAIL". Max.
Watched code never compiles.
-
Hello I want to make a timer in maze.The timer should countdown to reach 0 and if the player doesn't reach to end he/she lose the game. I want to denote that if player reach to end timer should stopped working. How can I do it? Thanks anyone help me.
a plain overview from a pro: http://www.mvps.org/directx/articles/selecting_timer_functions.htm[^] this should interest you http://msdn.microsoft.com/en-us/magazine/cc163996.aspx[^]
Press F1 for help or google it. Greetings from Germany
-
Hello I want to make a timer in maze.The timer should countdown to reach 0 and if the player doesn't reach to end he/she lose the game. I want to denote that if player reach to end timer should stopped working. How can I do it? Thanks anyone help me.
Sir, Here is your timer hasani2007. Its in 'dirty c code', clean it up. set the variable
count_down_time_in_secs
in seconds for desired count down time. The Code is self explanatory. 1 minute = 60 secs 5 minutes = 60x5 secs 30 minutes =60x30 secs 1 hour = 60x60 secs#include <stdio.h>
#include <time.h>int main ()
{unsigned int x\_hours=0; unsigned int x\_minutes=0; unsigned int x\_seconds=0; unsigned int x\_milliseconds=0; unsigned int totaltime=0,count\_down\_time\_in\_secs=0,time\_left=0; clock\_t x\_startTime,x\_countTime; count\_down\_time\_in\_secs=10; // 1 minute is 60, 1 hour is 3600 x\_startTime=clock(); // start clock time\_left=count\_down\_time\_in\_secs-x\_seconds; // update timer while (time\_left>0) { x\_countTime=clock(); // update timer difference x\_milliseconds=x\_countTime-x\_startTime; x\_seconds=(x\_milliseconds/(CLOCKS\_PER\_SEC))-(x\_minutes\*60); x\_minutes=(x\_milliseconds/(CLOCKS\_PER\_SEC))/60; x\_hours=x\_minutes/60; time\_left=count\_down\_time\_in\_secs-x\_seconds; // subtract to get difference printf( "\\nYou have %d seconds left ( %d ) count down timer by TopCoder
",time_left,count_down_time_in_secs);
}printf( "\\n\\n\\nTime's out\\n\\n\\n");
return 0;
}. . . TopCoder
-
Sir, Here is your timer hasani2007. Its in 'dirty c code', clean it up. set the variable
count_down_time_in_secs
in seconds for desired count down time. The Code is self explanatory. 1 minute = 60 secs 5 minutes = 60x5 secs 30 minutes =60x30 secs 1 hour = 60x60 secs#include <stdio.h>
#include <time.h>int main ()
{unsigned int x\_hours=0; unsigned int x\_minutes=0; unsigned int x\_seconds=0; unsigned int x\_milliseconds=0; unsigned int totaltime=0,count\_down\_time\_in\_secs=0,time\_left=0; clock\_t x\_startTime,x\_countTime; count\_down\_time\_in\_secs=10; // 1 minute is 60, 1 hour is 3600 x\_startTime=clock(); // start clock time\_left=count\_down\_time\_in\_secs-x\_seconds; // update timer while (time\_left>0) { x\_countTime=clock(); // update timer difference x\_milliseconds=x\_countTime-x\_startTime; x\_seconds=(x\_milliseconds/(CLOCKS\_PER\_SEC))-(x\_minutes\*60); x\_minutes=(x\_milliseconds/(CLOCKS\_PER\_SEC))/60; x\_hours=x\_minutes/60; time\_left=count\_down\_time\_in\_secs-x\_seconds; // subtract to get difference printf( "\\nYou have %d seconds left ( %d ) count down timer by TopCoder
",time_left,count_down_time_in_secs);
}printf( "\\n\\n\\nTime's out\\n\\n\\n");
return 0;
}. . . TopCoder
A busy loop is perhaps not the best way to go about things.
Steve
-
Hello I want to make a timer in maze.The timer should countdown to reach 0 and if the player doesn't reach to end he/she lose the game. I want to denote that if player reach to end timer should stopped working. How can I do it? Thanks anyone help me.
Hi Folks, nothing like coming late to the party but as no one has mentioned the way most games are written I thought I'd stick me oar in... In any game the timing is worked into the main dispatch loop. Every cycle around your dispatch loop you grab input, you update the timer, evolve the rest of the system based on how much time has elapsed and then render the game world according to what's happens. It looks something like this:
unsigned last_time = get_current_time_in_ms();
while( true )
{
/*
Record who's got keys pressed, where the mouse is, network stuff
*/update\_IO\_state(); /\* Sort out how much time has elapsed and how much time we have to evolve the game state over \*/ unsigned time\_now = get\_current\_time\_in\_ms(); unsigned ms\_this\_loop = time\_now - last\_time; last\_time = time\_now; /\* Change the state of all the game objects \*/ evolve( ms\_this\_loop ); /\* Display the changes \*/ render();
}
All the functions take some additional parameters depending on how you store your game state. The key point of this lot is that the game hammers along flat out - the thread this is on will eat a CPU. It churns out frames as often as it can and slows down when there's something system intensive happening. Oh, and if you do your IO on another thread make sure everything is synchronised properly or something weird WILL happen, possibly not on your computer but on your first customer's computer. Hope that helps, Cheers, Ash