time reaction game

This is a discussion on time reaction game within the C++ Programming forums, part of the General Programming Boards category; I need to create a piece of code that starts a timer and stops when a key is hit, and ...

  1. #1
    Registered User
    Join Date
    May 2003
    Posts
    3

    time reaction game

    I need to create a piece of code that starts a timer and stops when a key is hit, and then displays how far away from 2.5 seconds that the key was hit. It needs to do this 4 times. I can use the clock() and kbhit() functions. The only problem is I can't reset the counter to ZERO for each time. If anyone understands and can help... please do. Thanks!

  2. #2
    The Pantless Man CheesyMoo's Avatar
    Join Date
    Jan 2003
    Posts
    262
    Instead of reseting the counter save the value of when they first hit it and subtract that from the current time.

    Like:
    Code:
    // ...
    double previous_time;
    double current_time;
    // do whatever to get the times;
    
    current_time -= previous_time;
    
    // that will give you how long it took from the first press to the second one.
    Hope that helps and makes sense.
    If you ever need a hug, just ask.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    3

    that might help but...

    I have to display the time continually...

  4. #4
    Registered User
    Join Date
    May 2003
    Posts
    3
    Thanks dude, that helped.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how do the game engine and the api interact?
    By Shadow12345 in forum Game Programming
    Replies: 9
    Last Post: 12-08-2010, 12:08 AM
  2. 2D Game project requires extra C++ programmers, new or experienced
    By drallstars in forum Projects and Job Recruitment
    Replies: 2
    Last Post: 05-16-2007, 11:46 AM
  3. Need help with time
    By Gong in forum C++ Programming
    Replies: 7
    Last Post: 01-11-2007, 02:43 PM
  4. Military Time Functions
    By BB18 in forum C Programming
    Replies: 6
    Last Post: 10-10-2004, 02:57 PM
  5. real time game
    By Bingo The Clown in forum Game Programming
    Replies: 3
    Last Post: 07-23-2003, 12:09 PM

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