
-----------------------------------
dwgb93
Sun Nov 23, 2008 2:30 pm

Running multiple loops at the same time
-----------------------------------
Hi, guys
I need help with a project, and need to have it snowing at the same time smoke is rising from a chimney, while a snowmobile goes across the screen in the background.
I can run them all individually, but need help getting them to go all at once.
I have tried making them processes and forking them, but it gets extremely flickery.
I have also tried putting them all in the same loop, or 

loop
%code to make snowmobile run
loop
%code to make snow fall
loop
%code to make smoke rise
end loop
end loop
end loop

I think it is a small error.
Can someone please tell me what I am doing wrong?
Thank you very much.

-----------------------------------
WaluiJ
Sun Nov 23, 2008 2:41 pm

Re: Running multiple loops at the same time
-----------------------------------
If you want to avoid flickeryness, before the loop, put

setscreen ("offscreenonly")


and then inside the loop (preferably near the end) put

View.Update

It'd be better if you told us how you're making the animations go, because there are some problems I've had with View.Update.

-----------------------------------
dwgb93
Sun Nov 23, 2008 3:10 pm

Re: Running multiple loops at the same time
-----------------------------------
Here is my code where the whole thing as two seperate loops (instead of a process and a loop, or a loop within a loop)
The output s just the background

%Program to create a winter scene
%dwgb93
%November 20, 2008
setscreen ("graphics:800,600") %........................................Makes screen 800x600 and uses pixels for measurement
View.Set ("offscreenonly") %............................................Makes changes off screen, then puts them on to reduce flickering
var YOval, YOval1, YOval2, YOval3, YOval4, YOval5,  x1, x2 : int 
var counter : int 
colorback (11) %.......................................................Background sky blue
cls %..................................................................Full screen
counter := 0 
YOval := 275 
YOval2 := 275 
YOval3 := 275 
YOval4 := 275 
YOval5 := 275 
x1:= 420
x2:=430
procedure BackgroundPic %...............................................Makes the following a procedure (an image in this case)
    drawfilloval (maxx div 2, -15, maxx, maxy div 4, white) %..........Ground on hill is white
    drawfilloval (maxx, maxy, 70, 70, yellow) %........................Sun in top right
    drawline (700, 600, 730, 580, black) %.............................Sun's rays
    drawline (730, 580, 710, 550, black) %.............................Sun's rays
    drawline (710, 550, 748, 548, black) %.............................Sun's rays
    drawline (748, 548, 750, 510, black) %.............................Sun's rays
    drawline (750, 510, 780, 530, black) %.............................Sun's rays
    drawline (780, 530, 800, 500, black) %.............................Sun's rays
    drawline (800, 500, 800, 529, black) %.............................Sun's rays
    drawoval (maxx, maxy, 70, 70, black) %.............................Sun outline
    drawline (700, 600, 739, 600, black) %.............................Sun's rays
    drawfill (749, 549, 42, black) %...................................Ray colour
    drawfillbox (220, 50, 500, 200, 115) %.............................House
    drawline (200, 200, 250, 250, black) %.............................Roof
    drawline (250, 250, 470, 250, black) %.............................Roof
    drawline (470, 250, 520, 200, black) %.............................Roof
    drawline (200, 200, 520, 200, black) %.............................Roof
    drawfill (360, 225, 115, black) %..................................Roof colour
    drawfillbox (400, 250, 450, 300, 115) %............................Chimney
    drawfillbox (390, 300, 460, 315, gray) %...........................Chimney
    drawfillbox (360, 50, 410, 150, 114) %.............................Door
    drawfillbox (355, 50, 360, 155, 116) %.............................Door frame
    drawfillbox (355, 150, 415, 155, 116) %............................Door frame
    drawfillbox (410, 50, 415, 155, 116) %.............................Door frame
    drawfilloval (370, 100, 5, 5, gray) %..............................Door knob
    drawfillbox (240, 100, 340, 160, 11) %.............................Window
    drawfillbox (240, 128, 340, 132, black) %..........................Window frame
    drawfillbox (266, 100, 270, 128, black) %..........................Window frame
    drawfillbox (308, 100, 312, 128, black) %..........................Window frame
    drawfillbox (430, 100, 490, 160, 11) %.............................Window
    drawfillbox (430, 128, 490, 132, black) %..........................Window frame
    drawfillbox (458, 100, 462, 160, black) %..........................Window frame
    drawfilloval (100, 100, 50, 50, white) %...........................Snowman's base
    drawoval (100, 100, 50, 50, black) %...............................Snowman outline
    drawfilloval (100, 150, 40, 40, white) %...........................Snowman's body
    drawoval (100, 150, 40, 40, black) %...............................Snowman outline
    drawfilloval (100, 100, 49, 49, white) %...........................Erases black line
    drawfilloval (100, 200, 30, 30, white) %...........................Snowman's head
    drawoval (100, 200, 30, 30, black) %...............................Snowman outline
    drawfilloval (100, 150, 39, 39, white) %...........................Erases black line
    drawfilloval (100, 160, 5, 5, black) %.............................Snowman's top button
    drawfilloval (100, 130, 5, 5, black) %.............................Snowman's middle button
    drawfilloval (100, 100, 5, 5, black) %.............................Snowman's bottom button
    drawfilloval (100, 180, 25, 5, brightred) %........................Snowman's scarf
    drawfilloval (100, 185, 25, 5, white) %............................Erases top of scarf
    drawfilloval (90, 210, 3, 3, black) %..............................Snowman's left eye
    drawfilloval (110, 210, 3, 3, black) %.............................Snowman's right eye
    drawline (100, 203, 125, 200, black) %.............................Snowman's nose
    drawline (125, 200, 100, 197, black) %.............................Snowman's nose
    drawline (100, 197, 100, 203, black) %.............................Snowman's nose
    drawfill (105, 200, 42, black) %...................................Colours snowman's nose
    drawfilloval (100, 185, 2, 2, black) %.............................Snowman's mouth
    drawfilloval (113, 190, 2, 2, black) %.............................Snowman's mouth
    drawfilloval (87, 190, 2, 2, black) %..............................Snowman's mouth
    drawfilloval (93, 186, 2, 2, black) %..............................Snowman's mouth
    drawfilloval (107, 186, 2, 2, black) %.............................Snowman's mouth
    drawfilloval (100, 225, 30, 5, black) %............................Hat brim
    drawline (90, 225, 90, 250, black) %...............................Hat left
    drawline (110, 225, 110, 250, black) %.............................Hat right
    drawfilloval (100, 250, 10, 2, black) %............................Hat top
    drawfill (100, 240, black, black) %................................Hat colour
    drawfillbox (630, 50, 680, 100, 115) %.............................Tree trunk
    drawarc (625, 290, 30, 70, 270, 0, black) %........................Tree top layer left
    drawarc (685, 290, 30, 70, 180, 270, black) %......................Tree top layer right
    drawline (625, 220, 685, 220, black) %.............................Tree top layer bottom
    drawfill (655, 270, green, black) %................................Tree top layer colour
    drawarc (610, 250, 40, 60, 270, 331, black) %......................Tree fourth layer left
    drawarc (700, 250, 40, 60, 212, 270, black) %......................Tree fourth layer right
    drawline (610, 190, 700, 190, black) %.............................Tree fourth leyer bottom
    drawfill (655, 210, brightgreen, black) %..........................Tree fourth layer colour
    drawarc (590, 210, 50, 50, 270, 338, black) %......................Tree treprd layer left
    drawarc (720, 210, 50, 50, 205, 270, black) %......................Tree treprd layer right
    drawline (590, 160, 720, 160, black) %.............................Tree treprd layer bottom
    drawfill (655, 180, green, black) %................................Tree treprd layer colour
    drawarc (560, 180, 80, 50, 270, 338, black) %......................Tree second layer left
    drawarc (750, 180, 80, 50, 205, 270, black) %......................Tree second layer right
    drawline (560, 130, 750, 130, black) %.............................Tree second layer bottom
    drawfill (655, 150, brightgreen, black) %..........................Tree second layer colour
    drawline (530, 100, 780, 100, black) %.............................Bottom of tree
    drawarc (530, 150, 100, 50, 270, 336, black) %.....................Tree bottom left
    drawarc (780, 150, 100, 50, 205, 270, black) %.....................Tree bottom right
    drawfill (655, 125, green, black) %................................Tree bottom layer colour
    drawdot (621, 129, green) %........................................Cover up wierd pixel
    drawdot (621, 130, black) %........................................Cover up wierd pixel
    drawdot (634, 161, green) %........................................Cover up wierd pixel
    drawdot (636, 191, brightgreen) %..................................Cover up wierd pixel
    drawdot (645, 221, green) %........................................Cover up wierd pixel
    drawfillstar (640, 270, 670, 300, yellow) %........................Star on tree
end BackgroundPic %....................................................Indicates the end of the procedure
loop
delay(50)
cls

counter += 1 

drawfilloval (x1, YOval, 10, 10 ,darkgray) 
drawfilloval (x2, YOval2, 10, 10 ,darkgray) 
drawfilloval (x1, YOval3, 10, 10 ,darkgray) 
drawfilloval (x2, YOval4, 10, 10 ,darkgray) 
drawfilloval (x1, YOval5, 10, 10 ,darkgray) 

YOval += 1 
if counter > 15 then  
    YOval2 += 1 
end if 
if counter > 30 then  
    YOval3 += 1 
end if 
if counter > 45 then 
    YOval4 += 1 
end if 
if counter > 60 then  
    YOval5 += 1 
end if 

if YOval > maxy+10 then 
    YOval := 275 
end if 
if YOval2 > maxy+10 then 
    YOval2 := 275 
end if 
if YOval3 > maxy+10 then 
    YOval3 := 275 
end if 
if YOval4 > maxy+10 then 
    YOval4 := 275 
end if 
if YOval5 > maxy+10 then 
    YOval5 := 275 
BackgroundPic
View.Update
%End Smoke 
end if
end loop

BackgroundPic%.........................................................Inserts the procedure (image) onto the screen

type Snowing : %........................................................The name of the record
    record %...........................................................Indicates the following will be a record
        x : int %......................................................Integer variable (x coordinate of snowflake)
        y : int %......................................................Integer variable (y coordinate of snowflake)
        speed : int %..................................................Integer variable (speed of snowflake)
        size : int %...................................................Integer variable (size of snowflake)
        xchange:int
        direction : int %..............................................Integer variable (direction snowflake travels)
    end record %.......................................................Indicates the end of the record

var snow : array 1 .. 100 of Snowing %.................................Creating an array of the record snowing from 1-100

for rep : 1 .. 100 %...................................................For loop for each part of the the array
    randint (snow (rep).x, 0, maxx) %..................................Random integer of the loop of the array which gives a value to the x coordinate of a snowflake
    randint (snow (rep).y, maxy, maxy + 100) %.........................Random integer of the loop of the array which gives a value to the y coordinate of a snowflake
    randint (snow (rep).size, 1, 3) %..................................Random integer of the loop of the array which gives a value to the sixe of a snowflake
    randint (snow (rep).speed, -3, -1) %...............................Random integer of the loop of the array which gives a value to the speed of a snowflake
    randint (snow (rep).xchange, -3, 3)
    randint (snow (rep).direction, -3, 3) %............................Random integer of the loop of the array which gives a value to the direction of a snowflake
end for %..............................................................Ends the for loop

loop %.................................................................Repeats the following
   
delay (10) %.......................................................Slows the speed that the program operates by 0.01 seconds
    cls %..............................................................Clears the screen
    BackgroundPic %....................................................Inserts the background picture onto the screen

    for rep : 1 .. 100%.................................................
        drawfilloval (snow (rep).x, snow (rep).y, snow (rep).size, snow (rep).size, white)
        snow (rep).x += snow (rep).direction
        snow (rep).x += snow (rep).xchange
        snow (rep).y += snow (rep).speed
        if snow (rep).y  15 then
        YOval2 += 1
    end if
    if counter > 30 then
        YOval3 += 1
    end if
    if counter > 45 then
        YOval4 += 1
    end if
    if counter > 60 then
        YOval5 += 1
    end if

    if YOval > maxy + 10 then
        YOval := 275
    end if
    if YOval2 > maxy + 10 then
        YOval2 := 275
    end if
    if YOval3 > maxy + 10 then
        YOval3 := 275
    end if
    if YOval4 > maxy + 10 then
        YOval4 := 275
    end if
    if YOval5 > maxy + 10 then
        YOval5 := 275
    end if
    BackgroundPic

    for rep : 1 .. 100 %.................................................
        drawfilloval (snow (rep).x, snow (rep).y, snow (rep).size, snow (rep).size, white)
        snow (rep).x += snow (rep).direction
        snow (rep).x += snow (rep).xchange
        snow (rep).y += snow (rep).speed
        if snow (rep).y 