Escolar Documentos
Profissional Documentos
Cultura Documentos
Overview
In this tutorial, you will practice using the IF and WHILE control structures to control
the execution of procedures and functions based on a true or false condition.
Key Concepts
Use the IF control structure to affect execution of instructions
Learned
Use the WHILE control structure to create a conditional loop for repetitive
behavior
Difficulty
Advanced: This tutorial is appropriate for someone who has previously used Alice 3 to:
Level
Add and position objects in a scene
Code programming statements in the Code editor
Randomize movements
Declare a user-defined procedure
Create an animation that uses a control statement to control animation timing
Use functions to control movement based on a return value
Duration
60-90 minutes
Notes
This tutorial was built using Alice 3.1.81.
Part 1: Define the Scenario
Review the scenario and corresponding animation. In this tutorial, you are going to create an animation
from the scenario defined below.
Scenario
Animation
Walruses race to see who can get into the icy pond Two walruses race to a pond and the one that
first.
reaches the pond first dives in. Each time the
animation is played, a different walrus may win.
Part 2: Create the Scene
1.
Open the SNOW template.
Save the animation project with the file name Tutorial 6.
REMEMBER: SAVE FREQUENTLY AS YOU WORK!
2.
In the Gallery, go to the Browse Gallery by Theme tab
Select the SNOW theme.
3.
Add the following objects to the scene:
2 Baby Walruses
1 Baby Yeti with Tutu
1 Baby Yeti with Scarf
Note: Do not position the objects yet, as you will do so in later steps.
4.
In the Gallery, go to the Shapes/Text tab.
Add one Disc to the scene.
Select CYAN for the paint color.
5.
1
Copyright 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
6.
7.
Use the Resize handle
be able to dive into it.
to resize the pond so it is large enough for the two baby walruses to
8.
Move the two baby yetis to the right of the pond (your right), slightly facing the pond.
9.
In the following steps, you will precisely position the baby walruses for the start of the race so that
each baby walrus is the exact distance away from the center of the pond. This ensures that the
baby walruses have a fair start.
Right-click on the WalrusBaby.
Select Procedures.
Select moveAndOrientTo. Select the pond.
This will move the walrus to the center of the pond. The Walrus may appear to sink into the pond.
You will fix this in a future step.
10.
11.
12.
2
Copyright 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
13.
Both baby walruses should be precisely 10 meters away from the pond. Now you need to separate
them so they are standing next to each other.
Right-click on WalrusBaby in the object tree.
Select Procedures.
Select move.
Select arguments: LEFT 1.0.
14.
15.
16.
17.
18.
You may add additional objects to the scene to make your scene unique, such as people, props, or
animals.
Part 3: Program the Animation
PART 1
1.
Go to the Code editor.
2.
Drag a Do In Order
into myFirstMethod.
3.
Drag a comment
into the Do In Order.
Enter text: Race Start
4.
Select the YetiBabyTutu from the instance menu.
5.
Drag a say procedure into the Do In Order.
3
Copyright 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
PART 2
1.
Drag a Do In Order
into the myFirstMethod tab.
2.
Drag a comment
into the Do In Order.
Enter text: Walruses race each other to the pond. When one of the walruses reaches the pond,
the walruses stop.
3.
Drag a WHILE control statement into the Do In Order.
Select the true condition.
4.
Now you must specify the condition under which the while loop executes (while the walruses are
not colliding with the pond, they will continue to move forward a random amount). Once the
condition is no longer true, the while loop will stop executing.
4
Copyright 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
This complete condition states Either the WalrusBaby is not colliding with the pond or the
WalrusBaby2 is not colliding with the pond While either walrus is not colliding with the pond, the
while loop should continue executing.
Select the WalrusBaby from the instance menu.
Go back to the Procedures tab.
Drag a Do Together into the while statement.
Drag a move procedure into the Do Together.
Select arguments: FORWARD 1.0.
1.0 is a placeholder and will be changed in the next step.
Next, you will modify the distance argument in the move procedure so that a random value
between 0.25 and 2.0 is selected each time the move procedure is executed.
Click the arrow next to the 1.0 distance argument in the move procedure.
Select Random.
Select nextRandomRealNumberInRange ??? ???
5
Copyright 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
16.
17.
3.
4.
5.
6.
7.
Copyright 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective
owners.
8.
9.
10.
11.
12.
13.
14.