Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.

Slides:



Advertisements
Similar presentations
Visual Lists By Chris Brown under Prof. Susan Rodger Duke University July 2012.
Advertisements

Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 2: Using Methods.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Coloring Randomly: Random Selection in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
How Tall Are You? Introducing Functions By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made June 2014 by.
Using Functions in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University July 2008.
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Using Functions in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University July 2008.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University Feb. 24, 2007.
Alice Learning to program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke.
Calvin and Hobbes Teach Properties and Functions Created by Daniel MacDonald under the direction of Professor Susan Rodger Duke University June 2013.
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Checking for Collisions Ellen Yuan Under the direction of Professor Susan Rodger at Duke University June 2014.
Making a Timer in Alice.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July.
Poses Tutorial Alex Boldt Under the direction of Professor Susan Rodger Duke University July 2015.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Methods Tutorial: Part Two By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
Scene changes By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Lists Tutorial By Deborah Nelson Duke University Professor Susan Rodger July 13, 2008.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July 2013 Updates.
Skater World: Part Three By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1, 2009.
An Introduction to Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University, June 2009 Updated June 2014 by Ellen Yuan.
BDE tutorial By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 13, 2008.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Illuminating Computer Science CCIT 4-6Sep
Using Placeholders to Simplify your Methods: Learning Methods, Part 2 By Deborah Nelson Duke University Professor Susan Rodger June 16, 2008.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
How Tall Are You? Introducing Functions for Alice 3 By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008 Updates made.
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
Jonathon Kuo Under the Direction of Dr. Susan Rodger
Teaching Characters to Walk: Learning Methods, Part 1
Professor Susan Rodger
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Changing Color, Using Text Objects, and Random Selection in Alice
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Skater World: Part Three
Methods Tutorial: Part Two
Making Objects Move in Unison: Using Lists
Princess & Dragon Part 2: Teaching a Dragon to Fly—Methods & Properties By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
How Tall Are You? Introducing Functions
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Professor Susan Rodger
Professor Susan Rodger
Using Placeholders to Simplify your Methods: Learning Methods, Part 2
Professor Susan Rodger
Making Objects Move in Unison: Using Lists
under the direction of Professor Susan Rodger
Presentation transcript:

Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011

Repetition We first illustrate simple looping using “loop,” when you know how many times you want to repeat a section of code. Then we examine looping based on a condition. The loop continues repeating as long as a condition is true, and stops when the condition is no longer true. We also write some methods.

Add in objects Drop a dummy camera to save the original camera view (always a good idea!). Add a bunny from the animals folder Add three broccoli from the Kitchen folder and inside there the food folder.

The world should look like this: The broccoli spears will be floating in the air. Right click on their name in the object tree and select “methods”, “move to”, “ground”. That will get them on the ground. Then click on them and push them all back far behind the bunny. You can use the up/down button to move them up a little. Your world looks like:

Create new method: bunny.hop First let’s teach the bunny to hop, and then to hop over to the broccoli to eat it. Click on “bunny” in the object tree, then the “methods” tab, then “create new method”

Name the method: hop Name the method “hop” And you should see a bunny.hop tab now

Write the method “hop” Drag up “Do together” from the bottom of the pane and put a “Do in order” inside it. In the “Do in order” drag in a “bunny move up 0.5 meter” Select “more” and set the duration to.25 sec

Write the method “hop” (cont) Make a copy of the “move” command and change “up” to “down” in the second one. In the “Events” editor, under “when the world starts”, Change “my First Method” to “bunny”, then “hop” Now play your world

Write the method “hop” (cont) The bunny moves up, but not forward. Add into the Do together - “bunny move forward.25” Then select “more”, “duration”, “0.5” Play again, and the bunny hops and moves forward

Let’s get the bunny to hop in our story Click on the “my First Method” tab Click on bunny, methods and you should see the “hop” method Drag the “hop” method into my first method In the Events, change “when the world starts” to “world.my first method”

Repeating the hop - loop Click “Play” and the bunny hops once. We’d like to get the bunny to hop 4 times. A “loop” allows you to repeat commands a specified number of times. Drag “loop” into “my First Method”, select “other” and type “4”

Bunny hop 4 times Drag the hop method inside the loop and click Play. The Bunny should hop 4 times. We could add more items to the loop. Drag in “bunny say” and type in “hop”, select “more” and pick “duration = 0.5 seconds” Now the bunny hops and says “hop” 4 times

Loop The number of times the bunny hops is exact. We can change the number to another number, say 3 by clicking on the 4 and changing it to 3 Now the bunny hops and says “hop”exactly 3 times.

Next let’s teach the bunny to eat Now we will teach the bunny to eat one of the broccoli. We don’t know how far the broccoli is, so we will need the bunny to hop over to the broccoli repeatedly until the bunny is close to the broccoli.

Create new method “eat” Click on “bunny” in the object tree, then the “methods” tab, and then “create new method” Type in “eat” as the name You should see the bunny.eat tab

Create new method “eat” (cont) Drag in bunny method “turn to face” and select “broccoli” To test this out, in the Events area, change “when the world starts” to “bunny” “eat” Then “Play” to see the bunny turn toward the broccoli

Create new method “eat” (cont) To repeat code based on a condition, we will need a “while” loop Drag up the “while” and select “true”

How a while loop works while If the condition is true, the code is executed. If the condition is still true, the code is executed again. This repeats until the condition is false, then the code in the loop is no longer executed.

Create new method “eat” (cont) We want the bunny to keep hopping over to the broccoli as long as the distance between them is greater than 0.6 Click on “world” then “function”s tab Drag a>b into the “true”, select 1, and 0.6

Create new method “eat” (cont) Click on “bunny”, “functions” tab Drag the “bunny distance to” over the 1 and select “broccoli”

Create new method “eat” (cont) Click on “bunny”, “methods” tab and drag the bunny “hop” method into the “Do Nothing” Play, and the bunny heads over to the broccoli, stopping when it is closer than 0.6 meters distance.

Create new method “eat” (cont) Now let’s add some commands to bend over and eat the broccoli. Add after the while loop, commands for the bunny to turn forward.2, the broccoli to disappear (set isShowing to false) and the bunny to turn backward.

bunny.eat Here is the code now for bunny.eat Click Play and watch the bunny eat the broccoli

Eat all the broccoli We need to parameterize the broccoli so the bunny can eat other pieces of broccoli In bunny.eat, click on “create new parameter”, name it “tastyMorsel” and select “Object” for type

Parameter (cont) Drag “tastyMorsel” over all three occurrences of “broccoli”

Now finish story First, change “when the world starts” back to “my first method” Click on the “world.my first method” tab After the “loop” put in a “Do in order” From “bunny” “methods”, drag in “eat tastymorsel” three times, selecting broccoli, broccoli2, and broccoli3.

Final code for “my first method” Here is the final code. Play to watch the bunny eat all the broccoli.

More on “loop” Instead of “Loop 3 times”, click on the 3 and select “infinity times” Play the world, when will the bunny eat the broccoli? Never! Infinity is dangerous to use. The statements after it never happen. Change the “infinity times” back to “3”

If you know about lists …. If you have done the list tutorial, then look at the rest of this tutorial. Otherwise you are done. You could make a list of broccoli for the bunny to eat. Under “world” “properties”, click on “create new variable” Name it “food”, select type “object” and select “make a list” Add the three broccoli to the list

Food list Here is the food list And after clicking “ok” you should see:

Now use the list In “my first method” disable or delete the “Do in order” Drag up from the bottom the “For all in order” and select “expressions”, “world.food” Click on “bunny”, “methods” tab Drag over the bunny “eat tastyMorsel” into the “do nothing” and select “expressions”, “item_from_food” Play your world to watch the bunny eat the broccoli

Final Code with List You could add more broccoli into the world and add them into the list to get eaten You could have the bunny move other parts when it hops, such as its feet or its head. EXTRAS