Posted: Sun Nov 23, 2008 2:30 pm Post subject: 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
code:
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.
Sponsor Sponsor
WaluiJ
Posted: Sun Nov 23, 2008 2:41 pm Post subject: 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
Posted: Sun Nov 23, 2008 3:10 pm Post subject: 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
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 <= 50 then
randint (snow (rep).x, 0, maxx)
randint (snow (rep).y, maxy, maxy) % + 100)
randint (snow (rep).size, 1, 3)
randint (snow (rep).speed, -3, -1)
randint (snow (rep).direction, -3, 3)
randint (snow (rep).xchange, -3, 3)
end if
snow (rep).x += snow (rep).direction
snow (rep).x += snow (rep).xchange
snow (rep).y += snow (rep).speed
if snow (rep).x <= 0 then
snow (rep).x := maxx
elsif snow (rep).x >= maxx then
snow (rep).x := 0
end if
end for
View.Update
end loop
If I change the smoke loop to a process and fork it inside of the snow loop, the output is correct, but the whole screen flashes like crazy even with offscreenonly and view.Update
I just don't get why it is not doin anything.
I'm pretty sure it is because of the order of the loops, but I don't know what is wrong with it.
Tony
Posted: Sun Nov 23, 2008 3:14 pm Post subject: Re: Running multiple loops at the same time
dwgb93 @ Sun Nov 23, 2008 2:30 pm wrote:
I have tried making them processes and forking them
Don't do that.
You should be looking at
code:
loop
%code to make snowmobile run
%code to make snow fall
%code to make smoke rise
end loop
Worry about flickering after you get it to work in a loop. At that point it's very easily fixable with offscreenonly, but the same technique will not work with forks.
Posted: Sun Nov 23, 2008 3:24 pm Post subject: Re: Running multiple loops at the same time
Do I want to have View.Update, cls, delay() and the background pic in the code multiple times then?
or do I only have them once, and synchronize the movement of each object?
If I make it all one loop, the picture shows up, but there is no smoke, and the snow runs across the maxy row.
Tony
Posted: Sun Nov 23, 2008 4:08 pm Post subject: RE:Running multiple loops at the same time
View.Update, cls, and delay should appear just once, inside the loop.
Think of it this way
code:
setscreen ("offscreenonly")
var frame_number : int := 0
loop
frame_number += 1 % increment counter
draw_my_frame(frame_number) % draw all parts of the frame
View.Update % update the screen with entire frame
delay % wait a bit
cls % clear screen for next frame
end loop % repeat
Animation is simply drawing a series of static pictures, such that the difference is small enough for the transition to appear to be smooth.
What you have to do is figure out what exactly changes between frame number N and frame number N+1
Posted: Sun Nov 23, 2008 4:54 pm Post subject: Re: Running multiple loops at the same time
It works great
There is one problem, though.
The smoke is behind the house (the chimney) which is good, but the snow is behind it, too (that is bad)
If I rearrange the order of the snow, smoke, and cls/Draw the background, then both the smoke and the snow are infront of the house.
Here is my code
code:
%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
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
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
%End Smoke
end if
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 <= 50 then
randint (snow (rep).x, 0, maxx)
randint (snow (rep).y, maxy, maxy) % + 100)
randint (snow (rep).size, 1, 3)
randint (snow (rep).speed, -3, -1)
randint (snow (rep).direction, -3, 3)
randint (snow (rep).xchange, -3, 3)
end if
snow (rep).x += snow (rep).direction
snow (rep).x += snow (rep).xchange
snow (rep).y += snow (rep).speed
if snow (rep).x <= 0 then
snow (rep).x := maxx
elsif snow (rep).x >= maxx then
snow (rep).x := 0
end if
end for
View.Update
delay(10)
cls
BackgroundPic
end loop
Can someone tell me how to rearrange the order of the snow, smoke, and background, please
Thank you!
dwgb93
Posted: Sun Nov 23, 2008 5:26 pm Post subject: Re: Running multiple loops at the same time
Nevermind
I got it!
All I did was reinserted the background into the loop directly after the smoke, and before the snow!
Thanks
Sponsor Sponsor
WaluiJ
Posted: Sun Nov 23, 2008 5:36 pm Post subject: Re: Running multiple loops at the same time
Oh gee, way to make me waste five minutes figuring it out.
You posted right before I did, so I didn't see it. asdfjsdaf.
Program is looking great since I last checked it. What you could do though, to save lines, is draw the objects like the snowman and house seperately in MS paint, then use Pic.ScreenLoad to get them in the picture. Just a thought.
dwgb93
Posted: Sun Nov 23, 2008 5:37 pm Post subject: Re: Running multiple loops at the same time
Thanks a lot, but the snow does not go infront of the house either.
In my last post, I found the solution.
Thanks anyway
dwgb93
Posted: Sun Nov 23, 2008 6:34 pm Post subject: Re: Running multiple loops at the same time
Great idea.
I will post the final program when I have it completed.
Thanks a lot, though.
dwgb93
Posted: Sun Nov 23, 2008 8:07 pm Post subject: Re: Running multiple loops at the same time
I have one last problem.
My snowmoblie is made up of many drawlines and drawboxes etc
To make it move, do I have to change the x and y values of each one?
Or is there a way to change the whole thing at once?
andrew.
Posted: Sun Nov 23, 2008 8:17 pm Post subject: RE:Running multiple loops at the same time
Have a variable like snowmobilex. It will keep track of all the snowmobile parts. Each time you go around the loop, add 1 to snowmobilex so that all your parts move.
e.g.
Turing:
var snowmobilex :int:=0 loop
snowmobilex +=1% everytime it loops, the snowmobile will move to the right 1 pixel drawfillbox(snowmobilex, 0, snowmobilex + 50, 50, black)% this is supposed to be your snowmobile View.Update endloop
dwgb93
Posted: Sun Nov 23, 2008 8:20 pm Post subject: Re: Running multiple loops at the same time
Here is the code I have so far.
The way the snomobile is travelling is not 100% determined yet, so I gave it simple path to follow until I figure out where it goes.
The speed of the program is much slower when I run it, and the snowmoblie is just one blank path, not a moving image.
end BackgroundPic %....................................................Indicates the end of the procedure
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
for i : 0 .. 100
drawfillbox (375 + i, 35 + i, 400 + i, 85 + i, black)
drawline (400 + i, 85 + i, 395 + i, 125 + i, black)
drawarc (300 + i, 50 + i, 150, 100, 18, 50, black)
drawfillarc (400 + i, 60 + i, 75, 25, 270, 90, black)
drawarc (375 + i, 75 + i, 10, 10, 90, 180, black)
drawarc (355 + i, 75 + i, 10, 10, 270, 0, black)
drawline (365 + i, 75 + i, 365 + i, 77 + i, black)
drawfillbox (305 + i, 35 + i, 355 + i, 65 + i, black)
drawarc (305 + i, 70 + i, 5, 5, 180, 270, black)
drawline (300 + i, 70 + i, 300 + i, 80 + i, black)
drawarc (295 + i, 80 + i, 5, 5, 0, 90, black)
drawline (295 + i, 85 + i, 280 + i, 85 + i, black)
drawarc (280 + i, 80 + i, 5, 5, 90, 180, black)
drawline (275 + i, 80 + i, 275 + i, 40 + i, black)
drawarc (280 + i, 40 + i, 5, 5, 180, 270, black)
drawline (280 + i, 35 + i, 375 + i, 35 + i, black)
drawfill (290 + i, 50 + i, black, black)
drawfill (360 + i, 50 + i, black, black)
drawline (300 + i, 35 + i, 280 + i, 15 + i, black)
drawfilloval (284 + i, 12 + i, 5, 5, black)
drawline (286 + i, 7 + i, 350 + i, 7 + i, black)
drawfilloval (352 + i, 12 + i, 5, 5, black)
drawfilloval (318 + i, 12 + i, 5, 5, black)
drawline (355 + i, 8 + i, 382 + i, 35 + i, black)
drawline (276 + i, 36 + i, 270 + i, 10 + i, black)
drawfillbox (415 + i, 35 + i, 420 + i, 15 + i, black)
drawfillbox (375 + i, 10 + i, 450 + i, 15 + i, black)
drawarc (450 + i, 25 + i, 50, 15, 270, 10, black)
drawarc (450 + i, 30 + i, 50, 15, 270, 350, black)
drawarc (485 + i, 25 + i, 15, 10, 0, 229, black)
drawdot (475 + i, 17 + i, black)
drawfill (455 + i, 12 + i, black, black)
end for
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
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 <= 50 then
randint (snow (rep).x, 0, maxx)
randint (snow (rep).y, maxy, maxy) % + 100)
randint (snow (rep).size, 1, 3)
randint (snow (rep).speed, -3, -1)
randint (snow (rep).direction, -3, 3)
randint (snow (rep).xchange, -3, 3)
end if
snow (rep).x += snow (rep).direction
snow (rep).x += snow (rep).xchange
snow (rep).y += snow (rep).speed
if snow (rep).x <= 0 then
snow (rep).x := maxx
elsif snow (rep).x >= maxx then
snow (rep).x := 0
end if
end for
View.Update
cls
BackgroundPic
end loop
dwgb93
Posted: Sun Nov 23, 2008 8:28 pm Post subject: Re: Running multiple loops at the same time
I'm afraid I don't understand.
Was the box in the last one supposed to be the same as all of the parts of the snowmobile?
Am I supposed to put All of the drawlines, and drawboxes as snowmobilex +/- a number?