Thread: New game-Time-based movement?

  1. #1
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310

    Question New game-Time-based movement?

    We are starting a new game , and I'm wondering how to implement time-based movement. Origionally the character zoomed around the screen. To give this a temporary fix I set it up so you can only move 1 time every 4 times it goes through the game loop. The problem is obvious, it goes as fast at the CPU can run through the loop (taking 99% CPU).
    I was wondering if any of you know techniques to add time-based movement.

    Thanks in advance

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  2. #2
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    Here's a excerpt of how I implemented it.
    Code:
    if (!m_pause && m_lastupdate + speed < GetTickCount())
    {  
        m_lastupdate = GetTickCount();
        RenderScene();
        // Gey keys...
    }
    Pretty simple...

  3. #3
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    What library is GetTickCount() in? Forgot to add I'm using C++ and SDL.

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  4. #4
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    it's a part of the win32 API

    #include<windows.h>

  5. #5
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Thanks Eibro and Poly, I've successfully added pausing and time-based movement. The only problem is that it still eats up CPU time. Is there a command that tells it to wait for 10 milliseconds or something?

    Thanks,
    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  6. #6
    I can tell you're using programmer-art. . I am so thankful that I can do comp graphics and I am a coder. I'm not the best in the world, but I can do some pretty good tiles, drawing them pixel-by-pixel then using photoshop to add filters and color grading.

  7. #7
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Heh, yeah, programming graphics would fit the bill . I just made some starter graphics (grass, hud, mud) to get my mapl-loader started and a the graphics person is remaking those and making higher quality ones.

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Journey time prog 1 minute wrong
    By mike_g in forum C Programming
    Replies: 4
    Last Post: 10-12-2006, 03:41 AM
  2. C Programming 2d Array Question
    By jeev2005 in forum C Programming
    Replies: 3
    Last Post: 04-26-2006, 03:18 PM
  3. 2D Tile Based Game
    By cboard_member in forum Game Programming
    Replies: 6
    Last Post: 07-29-2005, 01:04 AM
  4. time based movement
    By werdy666 in forum Game Programming
    Replies: 5
    Last Post: 11-04-2002, 01:52 PM
  5. Text Based Pong Game Ready :-)
    By Akilla in forum C++ Programming
    Replies: 8
    Last Post: 08-05-2002, 06:24 AM