
-----------------------------------
msimard8
Mon May 02, 2005 12:55 pm

Running two procedures at once
-----------------------------------
Is it possible to run two procedures at once.   For example (on Super Mario Games you have the turtles and the mushrooms both moving different directions.  

I need something where there is two seperate procudres executing at once.  A for loop wont work for me


Thanks

-----------------------------------
jamonathin
Mon May 02, 2005 1:33 pm


-----------------------------------
You can do something like this:

forward proc mario
proc turtle
    % do whatever
end turtle

body proc mario
    % do whatever
end mario

Or do you mean two loops?  then you would have to fork, but forking isn't always a great idea.
There's another way to delay, without using more than one delay, where that one delay is normally just the game's delay.

What you can do is assign a variable to whatever it is you want, and use it as a counter.  Once that counter hits a certain spot, then you can do whatever it is you want to do.

Here is a sample of what I'm talking about.  The pink ball moves twice as fast as the other ball, but the ball only moves when the counter assigned to it reaches a certain value.

View.Set ("offscreenonly")
colorback (black)
cls
var x, y : array 1 .. 2 of int := init (10, 10) %Varing x's and y's
x (2) := 100
var k, p : int := 0 %Varing Counters
loop
    cls
    drawfilloval (x (1), y (1), 5, 5, 13) %Drawing Balls
    drawfilloval (x (2), y (2), 5, 5, 10)
    k += 1 %Always adding to the counters
    p += 1
    if k = 10 then % 10 * 5 = delay(50)
        y (1) += 2 %Moving Ball
        k := 0 %Reseting Counter
    end if
    if p = 20 then % 20 * 5 = delay(100)
        y (2) += 2 %Moving Ball
        p := 0 %Reseting Counter
    end if
    View.Update
    delay (5)
end loop

