controlling game speed

This is a discussion on controlling game speed within the Game Programming forums, part of the General Programming Boards category; Im making a snake game and i need some help figuring out how to control the snake speed, and make ...

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    26

    controlling game speed

    Im making a snake game and i need some help figuring out how to control the snake speed, and make it the same speed on all machines. i want the snake to move a couple times every second, or something like that, but i need a function to measure time less than 1 second. i think i could then test the time twice, subtract them, and see if the diff is a certain amount and if it is move the snake. does this sound about right. thanks for the help
    Jesse

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    yup.. sounds right.

    have a look at time(), GetTime(), timeGetTime(), or functions similar to that. if you're using windows you could even set a time to go off every half second to update the snake position.. there are quite a few ways of doing this.

    hope that helps!
    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    Registered User
    Join Date
    Feb 2002
    Posts
    26
    i tried time(), and it will only return whole seconds, it looks like gettime() does the same, only w/ hour min, sec, and i couldn't find any info on timegettime()
    can some help me out some more?

  4. #4
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    timeGetTime() returns the number of milliseconds (as a DWORD)since Windows started. You need to include <mmsystem.h> and link to winmm.lib. Here's an example:

    Code:
    DWORD StartTime=0, EndTime=0;
    
    //in your loop
    EndTime=timeGetTime();
    if(EndTime-StartTime>1000)
    {
       //do stuff
       StartTime=EndTime; //reset start time variable
    }

  5. #5
    . Driveway's Avatar
    Join Date
    May 2002
    Posts
    469
    What header is timeGetTime() in? I'm pretty sure it's time.h, right?

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    It's in the windows multimedia headers. You'll also need to link to the multimedia library. Following code will do both..

    #include <windows.h>

    #pragma comment( lib, "winmm.lib" )

    EDIT: Alternatively, if you don't want to use the pre-processor directive, you can link to the winmm.lib under project settings.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  2. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 04:18 PM
  3. Try my game
    By LuckY in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 09-15-2004, 12:58 PM
  4. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 05:19 AM
  5. My Maze Game --- A Few Questions
    By TechWins in forum Game Programming
    Replies: 18
    Last Post: 04-25-2002, 12:00 AM

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