Countdown.. 3.. 2.. 1?

This is a discussion on Countdown.. 3.. 2.. 1? within the C++ Programming forums, part of the General Programming Boards category; shh.......

  1. #16
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    shh....

  2. #17
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    idea

    I think I have an idea based on FillYourBrains reply... I'll try it and then tell you how it went.

  3. #18
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Hmmm...

    Doesn't seem to work... How can I get the timer to run in the background? I tried running it in a loop with a while(!kbhit).

  4. #19
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Post the rest of your code.

    Code:
    time_t timerTime = time(NULL) + (60*60);
    
    while (time(NULL) < timerTime)
    {
    	while (!kbhit)
    	{
    		// Do animation;
    	}
    	int iKeyCode = getch();
    	switch (iKeyCode)
    	{
    		// Do movement;
    	}
    }
    Last edited by Eibro; 08-31-2002 at 09:53 AM.

  5. #20
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297

    Re: Hmmm...

    Originally posted by drdroid
    Doesn't seem to work... How can I get the timer to run in the background? I tried running it in a loop with a while(!kbhit).
    There is no "background" unless you're multithreaded or at least message based as windows is. You're doing a DOS game if I'm not mistaken. You should have a game loop that controls animation based on a time check. This same time check can be used to figure out if your "countdown" has expired. What didn't work?

  6. #21
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    ...

    Basically I did what you posted... but it still pauses when it counts down... it stops the character from moving for the timer to wait and then subtract to the time left... is that any help?

  7. #22
    pronounced 'fib' FillYourBrain's Avatar
    Join Date
    Aug 2002
    Posts
    2,297
    no, you probably misunderstood what I said.

    most games have a "game loop". This is a place where all motion is decided and drawn to the screen. If you simply check what time it is one time in this loop you will be checking once for every screen drawn. There would be no pause. You were probably thinking putting the timer in a loop of its own. that's not at all what I suggested.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Day countdown
    By putty88 in forum C Programming
    Replies: 5
    Last Post: 02-15-2009, 05:55 PM
  2. Countdown
    By Zagaberoo in forum C++ Programming
    Replies: 3
    Last Post: 09-26-2004, 05:26 PM
  3. Replies: 4
    Last Post: 08-13-2003, 07:25 PM
  4. delay()?/sleep()?/need for countdown/
    By Robin Hood in forum C++ Programming
    Replies: 2
    Last Post: 07-19-2002, 04:04 PM
  5. Whats wrong with my countdown program?
    By Golden Bunny in forum C++ Programming
    Replies: 3
    Last Post: 04-23-2002, 01:15 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21