1. time loop

Hi, does anyone know what I can put in my game's major loop, so that if a
certain time hasn't passed, the game will wait?

(Thus controlling the speed of the game through different situations and
different computers)



=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The Reaper  (J. Lays)   http://www.geocities.com/TimesSquare/Alley/4444/
reaper at auracom.com      Check out my Euphoria Games page at:
            -= http://www.geocities.com/TimesSquare/Alley/4444/eugames.html
      ........................
     . .. -||..........__......  "Some will live life
      . /  ||......../-- \\.::::  Unwilling to ask why,
   . ..|   ||...... /    | |.:::  And they will be forgotten,
     .|  _-||.......||   / /.:::: After they die."
    ..| |..||...... -\_- \ |\-.:::
     .| |.[< \ .../            \.::
      .||.|||\|\ |  -      - .  \.::::
     ...|.\|| |  \  |        |   |.:::.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

new topic     » topic index » view message » categorize

2. Re: time loop

On Sat, 22 Nov 1997, The Reaper wrote:

> Hi, does anyone know what I can put in my game's major loop, so that if a
> certain time hasn't passed, the game will wait?
>
> (Thus controlling the speed of the game through different situations and
> different computers)
>
>
yeah at the beginning for your main loop (somewhere) add something like
frameclock=time()

Then at the bottom do something like
while time()-frameclock< whatevertimeyouwannawait do
end while

when it gets to the while, if the amount of time you want hasn't already
passed it'll wait until it has then go on.  This just waits, it does no
processing.  If you want to process anything while you wait (like looking
at keys and doing something about them) stick the code between the while
and end while.


Michael

new topic     » goto parent     » topic index » view message » categorize

3. Re: time loop

At 01:33 PM 11/22/97 -0500, you wrote:
>Hi, does anyone know what I can put in my game's major loop, so that if a
>certain time hasn't passed, the game will wait?
>
>(Thus controlling the speed of the game through different situations and
>different computers)
>
>Set a variable equal to time().  Then later if time() - variable is less
than the interval you wanted, loop back until it isn't 'less than' any more.
That would be something like 'while time() - variable < interval do' twiddle
thumbs 'end while'

Wally Riley
wryly at mindspring.com

new topic     » goto parent     » topic index » view message » categorize

4. Re: time loop

>Hi, does anyone know what I can put in my game's major loop, so that
>if a certain time hasn't passed, the game will wait?
>
>(Thus controlling the speed of the game through different situations
>and different computers)

Here are two routines that will work.
See below for better descriptions

global procedure delay(atom n)
    -- A n second pause... (Will work with fractional seconds)
    atom t
    t = time()
    while time() < t + n do end while
end procedure

global procedure tick_delay(atom l)
    atom oldtime, c
    oldtime = time()
    c = 0
    while l > c do
        if time() > oldtime then
            c = c + 1
            oldtime = time()
        end if
    end while
end procedure

delay() will pause for as many seconds as you want. By default, the
number is effectivly rounded up to approx. the nearest .055. Using
tick_rate() will change that resolution. (I kinda took delay() from
Language War....)

tick_delay() will delay for l/tick_rate()th of a second. The code is a
bit messy, but since it's a delay loop, nobody will notice.. :) The code
for this came up accidentally before I learned Euphoria while trying to
make a delay loop that did what delay() does. (Made the mistake in
QBasic, but it works much better than I expected, now I use tick_delay(1)
in any game I make to lock the frame rate at 18 frames per second)

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu