Re: time loop

new topic     » goto parent     » topic index » view thread      » older message » newer message

>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 thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu