Thread: Movement

  1. #1
    Registered User got matt?'s Avatar
    Join Date
    Mar 2002
    Posts
    16

    Question Movement

    Gee wiz. Sorry for asking so many questions guys but I have been having bad luck finding what I am looking for. I have a problem you see. I am making a program that has to do with racing horses...Or in this case blank " " with colored backgrounds. I have been using gotoxy all this way and I need to know how to make them move without them moving in an instant. The only option I have is using sleep. Is there a better way? Is there an better way to use sleep?
    -thnx
    "If there is a will, there is a way."

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Sleep is the best option in this case, delaying a program goes against the grain for most programmers because speed is usually a concern. The sleep and delay functions were created as a convenience in such situations where you need the program to wait for a bit. But beware using them, they aren't standard and you code will not be portable because of that.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266
    what if you sent the program through a loop that counted to a million or something?

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >what if you sent the program through a loop that counted to a million or something?
    That wouldn't work because different computers will take different amounts of time to loop the same number of times. If you need precise timing then a delay function is what you want since they use the system time as a basis for their operations.

    -Prelude
    My best code is written with the delete key.

  5. #5
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    Yeah, include time.h and use this....

    Code:
    int wait(int SecondsToWait)
    {
    	time_t TheTime = time(NULL);
    	while(time(NULL) - TheTime < SecondsToWait);
    	return 1;
    }
    It's a little touchy at times, but I use it.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ship Movement
    By gustavosserra in forum Game Programming
    Replies: 8
    Last Post: 11-27-2004, 07:00 PM
  2. I need movement...
    By Finchie_88 in forum C++ Programming
    Replies: 1
    Last Post: 10-04-2004, 03:10 PM
  3. natural leg movement
    By DavidP in forum Game Programming
    Replies: 32
    Last Post: 01-11-2004, 09:01 AM
  4. Movement problem...
    By Umoniel in forum C Programming
    Replies: 2
    Last Post: 11-10-2002, 12:46 PM
  5. Movement
    By drdroid in forum C++ Programming
    Replies: 5
    Last Post: 02-09-2002, 11:02 AM