Alice Concepts: Threshold and Conditional Statements

Objects in Alice have the ability to sense and interact with each other.  Threshold is a given distance from the center point of an Alice object. For example:

 Proximity: Within Threshold - Distance from Center Point of Object Threshold Away Distance/Direction (Above, Below, Left, Right . . .)

A key concept in programming is the Conditional Statement.  Usually Conditions are stated as an "If -> Then" statement.

 If -> Condition is True     Then -> Do Method(s)

To demonstrate Threshold and Conditionals,  we are going to use the Chicken-Tank from "Alice: Aiming"  to launch the chicken at a dinosaur.

Program Summary:

 Tank Aims and Fires Chicken:     Arrow Keys Aim Tank     Space Key Fires Chicken If Chicken "Touches" dinosaur:     Then Dinosaur Falls Over

Directions:

1. Open the Tank-Chicken activity from "Alice: Aiming."  If you do not have a Tank-Chicken program, do "Alice: Aiming" and save the file.

2. Click green "ADD OBJECTS" button and select Trex from the Animals Gallery.

3. Use the mouse to move Trex behind the tank.

4. Click "DONE."

5. Click the "trex" on the object tree.

6. Click the methods tab.

7. Click "create new method" and make the following methods:
a. openMouth
b. fallOver

8. Click on "trex.openMouth" tab and put the following methods and blocks:
a. Drag a "Do Together" into "trex.openMouth."
b. Click on Plus sign next to "trex" and find trex.neck.head.jaw
c. Drag "trex.neck.head.jaw" turn into the "Do Together."
1. Select "forward" and "0.12" revolutions.
e. Drage "trex.neck.head.jaw.tongue" move into the "Do Together."
1. Select "forward" and "0.5" meters.

9. Click on "trex.fallOver" tab and add the following methods and blocks:
a. Drag a "Do Together" into "trex.fallOver"
b. Click on "trex" in the object tree.
c. Drag a "trex" roll "left" "0.25" revolutions into the "Do Together."
d. Drag a "trex" move "left" "5" meters into the "Do Together."

10. Click on "world.my first method" tab

11. Drag a "Loop" block and select "infinity" times below the Chicken Blocks

12. Drag a "If/Else" block into the "Loop" block.

13. Click on the "Chicken" in the object tree.

14. Click on the "functions" tab on the Chicken

15. Drag the "Chicken is within threshold of" block into the "If Block"

16. Select "10 meters" of "trex."

17. Click on the "trex" in the object tree.

18. Drag a "Do in order" into the "If Else" block.

19. Drag the "trex.openMouth" into the "Do in Order."

20. Drage the "trex.fallOver" into the "Do in Order."

21. The Loop and If/Else should look like this:

22. The entire "world.my first method" should look like:

23. Save your program.  Click Play and shoot the chicken at the dinosaur.  When the chicken is close to the dinosaur - it should fall over.

 Assignment: 1. Create a short game where the "shooter" object must aim and "hit" a "target" object. 2. Use Conditional statements and Proximity to have the target fall over or react. 3. Save Project into our File Area.