
-----------------------------------
colinlamm
Fri Dec 16, 2011 9:31 pm

Help with animating snow
-----------------------------------
What is it you are trying to achieve?
Im trying to make it so that when my box floats and stops my snow is still animating.


What is the problem you are having?
i cant seem to make my snow keep moving after the box floats


Describe what you have tried to solve this problem
i tried putting the snow code in a loop but it always freezes up the whole thing.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
setscreen ("graphics:800;600")
View.Set ("offscreenonly")
var Box_y, Box_y2, Box_x, Box_x2 : int %Moving the ipod Variables
Box_y := 10
Box_y2 := 40
Box_x := 10
Box_x2 := 40

%Snowflake Animation
const FlakesFalling := 400
var FlakeX : array 1 .. FlakesFalling of int
var FlakeY : array 1 .. FlakesFalling of int
for Flake : 1 .. FlakesFalling
    FlakeX (Flake) := Rand.Int (0, maxx)
    FlakeY (Flake) := Rand.Int (0, maxy)
end for

loop
    Draw.FillBox (0, 200, 800, 600, 105)     %Blue Sky Background
    Draw.FillBox (0, 0, maxx, 199, 29)     %Ground Background

    %Initials
    drawbox (785, 15, 745, 75, black)     %second initial
    drawbox (730, 15, 690, 75, black)     %first initial
    drawline (755, 20, 775, 20, black)     %Second initial
    drawline (755, 20, 755, 70, black)     %Second initial
    drawarc (715, 45, 20, 23, 75, 280, black)     %First initial

    %House
    Draw.FillBox (20, 150, 250, 350, 111)               %House Square shape
    var x1 : array 1 .. 3 of int := init (20, 250, 140)       %House Roof
    var y1 : array 1 .. 3 of int := init (350, 350, 450)     %House Roof
    Draw.FillPolygon (x1, y1, 3, 17)    %Drawing Roof

    %Christmas Tree:
    var x : array 1 .. 16 of int := init (599, 599, 641, 641, 714, 668, 695, 643, 671, 623, 573, 605, 547, 599, 527, 598)
    var y : array 1 .. 16 of int := init (203, 156, 156, 202, 202, 248, 248, 298, 298, 346, 299, 299, 244, 244, 200, 203)
    Draw.FillPolygon (x, y, 16, green)
    % This polygon was created using Gurjant Kalsi's Polygon Generator

    Draw.FillBox (650, 100, 750, 175, brightred)     %Presents
    Draw.ThickLine (700, 100, 700, 175, 5, brightgreen)     %Presents
    Draw.ThickLine (650, 140, 750, 140, 5, brightgreen)     %Presents
    Draw.FillBox (500, 100, 600, 175, brightgreen)     %Presents
    Draw.ThickLine (500, 140, 600, 140, 5, brightred)     %Presents
    Draw.ThickLine (550, 100, 550, 175, 5, brightred)     %Presents

    for Flake : 1 .. FlakesFalling
        %Drop The Flake
        FlakeY (Flake) -= Rand.Int (1, 5)
        %flakeX (flake) += Rand.Int (-1, 1)
        if FlakeY (Flake) < 0 then
            FlakeY (Flake) := maxy
            FlakeY (Flake) := Rand.Int (0, maxx)
        end if
        Draw.FillOval (FlakeX (Flake), FlakeY (Flake), 1, 1, white)
    end for

    %Moving the Ipod Touch upwards
        exit when Box_y = 300
        Draw.FillBox (380, Box_y, 400, Box_y2, black) %Ipod Touch        
        Draw.FillBox (350, 10, 450, 100, 90)
        Box_y := Box_y + 10
        Box_y2 := Box_y2 + 10
        View.Update
        delay (50)
        
        
       
end loop








Please specify what version of Turing you are using
4.1

-----------------------------------
Linkxgl
Fri Dec 16, 2011 10:18 pm

RE:Help with animating snow
-----------------------------------
It'll be easier to read your code if you wrap it around 

put "Hello World"


without:
put "Hello World"

I don't understand the problem? Your snow is in a loop, if it wasn't it wouldn't be moving in the beginning of the script...
Also, when the box moves, the snow is still falling, but in your script where it says:

exit when Box_y = 300 

When the box gets to 300 pixels on the y-axis on the screen, the loop exits, and the snow stops falling... All I did was comment out that exit and the snow kept falling, and the box kept flying up..

So what's the problem?

-----------------------------------
colinlamm
Fri Dec 16, 2011 10:36 pm

Re: Help with animating snow
-----------------------------------
Umm the main problem was that i wanted the box to stop at 300

 
exit when Box_y = 300 

so when i did that, it also stops the snow from moving. How do i make it so that it stops the box, and the snow keeps continuing? o_O

-----------------------------------
Raknarg
Sat Dec 17, 2011 12:49 am

RE:Help with animating snow
-----------------------------------
Do exactly what you said. Write the code so that it only animates one thing instead of two.

-----------------------------------
Linkxgl
Sat Dec 17, 2011 9:22 am

RE:Help with animating snow
-----------------------------------
Alright, then just have an if statement before the part where you move the box saying, "as long as the box_y variable is less than 300, do the following" So something like this?


if variable < 300 then
     %move box
end if


Using exit when, exits the loop you're current in. You want to keep the loop running since you need the know to keep falling, so use an if statement to check whether the box is over 300 pixels on the y, and when the if statement is false, it will stop moving the box!

Edit
Alright, so I just tried it, and it works perfect, I literally just added two lines of code, and erased one. The one that I erased was already mentioned, so you should be fine now!

-----------------------------------
Raknarg
Sat Dec 17, 2011 1:07 pm

RE:Help with animating snow
-----------------------------------
Basically what you were doing was something like this:


loop
     animate_box
     animate_snow

     if box is done animation then
          exit
     end if
end loop

You can do that if you want to. Then what you do is make a new loop and include everything but the animating box.
What Linkxgl works fine as well, but if you're going to be animating morethings, it may be best to just separate them into different loops to avoid having to use a rediculous amount of counters and such.

-----------------------------------
colinlamm
Sat Dec 17, 2011 3:44 pm

Re: Help with animating snow
-----------------------------------
Oh i see i kind of understand it now, thanks alot guys!

It actually works! Thanks A LOT.

-----------------------------------
chipanpriest
Sat Dec 17, 2011 4:45 pm

Re: Help with animating snow
-----------------------------------
I super easy to fix this would be to

 
%get rid of "exit when Box_y = 300"
%Then put this instead
if Box_y >= 300 then
Box_y := 300
Box_y2 := 330
end if

