tutorial on kangaroo visiting his animal friends

28
Tutorial on Kangaroo visiting his animal friends visiting his animal friends parameters, events Susan Rodger Dk Ui i Duk e University June 2009

Upload: others

Post on 08-Jul-2022

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tutorial on Kangaroo visiting his animal friends

Tutorial on Kangaroo visiting his animal friendsvisiting his animal friends‐ parameters, events

Susan Rodger

D k U i iDuke University

June 2009

Page 2: Tutorial on Kangaroo visiting his animal friends

Start with a new world• Add a Kangaroo, a cow, and several animals of different heights, spread around the world

• I picked bunny, cow, horse, ladybug, tortoise, turtle – any animals will do but make sure you y yhave some tall animals.

Page 3: Tutorial on Kangaroo visiting his animal friends

ProblemProblem

• The kangaroo wants to visit each animalThe kangaroo wants to visit each animal where “visit” means: the kangaroo and the animal face each other the kangaroo movesanimal face each other, the kangaroo moves close in front of it, the kangaroo says “hi” and then the Kangaroo jumps over it However thethen the Kangaroo jumps over it. However, the kangaroo can only jump 1 meter high. 

Page 4: Tutorial on Kangaroo visiting his animal friends

Parts of the TutorialParts of the Tutorial

• Part 1: Kangaroo visit each friendPart 1: Kangaroo visit each friend

• Part 2: Kangaroo either go around or jump overover

• Part 3: Create an event to click on animal to i ivisit

Page 5: Tutorial on Kangaroo visiting his animal friends

Part 1: Kangaroo visit Cow

• Create a “Kangaroo” method called visit for the Kangaroo to visit the cowthe Kangaroo to visit the cow

Page 6: Tutorial on Kangaroo visiting his animal friends

See the new Kangaroo visit h d bmethod tab appear

Page 7: Tutorial on Kangaroo visiting his animal friends

Enter the following codeEnter the following code• The kangaroo turns to visit the cow and moves toward ittoward it.

• To test it out, change the event “when the world starts” to “kangaroo.visit” and PLAY

Page 8: Tutorial on Kangaroo visiting his animal friends

How to move the Kangaroo all the way hto the cow

• Click on Kangaroo andClick on Kangaroo, and under Kangaroo’s details, click on Functionsclick on Functions. 

• Click and drag “kangaroo distance to” on top of the 1distance to  on top of the 1 meter.

Page 9: Tutorial on Kangaroo visiting his animal friends

Resulting in….Resulting in….

• Click Play

• Yikes, The Kangaroo goes into the Cow!Yikes, The Kangaroo goes into the Cow!

• We want the Kangaroo to stop 2 meters in front of the cow (make sure the cow is morefront of the cow (make sure the cow is more than 2m away).

Page 10: Tutorial on Kangaroo visiting his animal friends

Use Math and subtract 2Use Math and subtract 2

• Click on white arrowClick on white arrow

S l “ h” h “ i i ” h “2”• Select “math”, then “minus sign” then “2”

Page 11: Tutorial on Kangaroo visiting his animal friends

Resulting in the following codeResulting in the following code

• The kangaroo will stop two meters in front of the center of the cowthe center of the cow…

Page 12: Tutorial on Kangaroo visiting his animal friends

Next add a greeting and jump overNext add a greeting and jump over

• Have the kangaroo say a greetingHave the kangaroo say a greeting• Then have the Kangaroo jump over the cow

– The kangaroo must jump upThe kangaroo must jump up– The kangaroo must jump 2m to the cow, plus the cow’s depth, plus another 2m past the cow

• Total distance: 4 + cow’s depth• Find cow’s depth in the cow functions…

h k j d– The kangaroo jumps down

( d th t )(code on the next page)

Page 13: Tutorial on Kangaroo visiting his animal friends

Add the remaining codeCh “ h th ld t t ” tChange “when the world starts” to

Kangaroo.visit and “Play”g y

Page 14: Tutorial on Kangaroo visiting his animal friends

How to visit any friend –Add a parameter named friendToVisit‐ type should be Object – click okyp j

2.

1.

Page 15: Tutorial on Kangaroo visiting his animal friends

Now click and drag friendToVisit on f h f ftop of the four occurences of Cow

Click and drag from hereClick and drag from here

Page 16: Tutorial on Kangaroo visiting his animal friends

Change “when the world starts” back to myFirstMethod

Click on myFirstMethod tab,Click on myFirstMethod tab,Drag in visit for each friend and “Play”

Page 17: Tutorial on Kangaroo visiting his animal friends

Add another parameter of type String so Kangaroo can give a differentso Kangaroo can give a different 

greeting to each animal• Click on the tab for Kangaroo.visit first

• Click on “create new parameter”p

• The type is “Other” then “String” sincethen  String  since the Kangaroo will say worldsworlds

• Then click ok

Page 18: Tutorial on Kangaroo visiting his animal friends

The result is…The result is…

N ti “ ti ” i f t “ABC” d• Notice “greeting” is of type “ABC” or words

• Now click and drag “greeting” over the phrase the Kangaroo says “How are you doing?” 

• Result is:

Page 19: Tutorial on Kangaroo visiting his animal friends

Back to MyFirstMethod, add greetingsBack to MyFirstMethod, add greetings

• Replace “greeting=default string” to aReplace  greeting=default string  to a different greeting for each animal.

• Then Click Play

Page 20: Tutorial on Kangaroo visiting his animal friends

Part 2: Going around or over friendPart 2: Going around or over friend

• Kangaroo can only jump 1 meter highKangaroo can only jump 1 meter high

• If friend is shorter than 1 meter, it is ok to jump overjump over

• If friend is 1 meter or taller, then go around hthem

Page 21: Tutorial on Kangaroo visiting his animal friends

First drag in an If/Else from the bottom f th i d l i ft th “ ”of the window, placing after the “say”

Page 22: Tutorial on Kangaroo visiting his animal friends

Select “world”, “functions” and scroll to find math functions, then click and 

drag “a<b” selecting 1’sg g

Page 23: Tutorial on Kangaroo visiting his animal friends

Drag in “cow’s height” from the cow f ti th d “f i dT Vi it”functions, then drop “friendToVisit” 

over cow

Page 24: Tutorial on Kangaroo visiting his animal friends

Move the kangaroo jump over code and put after the if. Then add code 

after the else to “go around”. gThen Play

Page 25: Tutorial on Kangaroo visiting his animal friends

Part 3 – create an event to visit friendPart 3  create an event to visit friend clicked on

Fi t di bl th t “ h thFirst, disable the event “when the world starts” so the movie will not playp y

• You can get the movie back, by enabling the eventevent.

Page 26: Tutorial on Kangaroo visiting his animal friends

Create a new eventWhen the mouse is clicked on something

Page 27: Tutorial on Kangaroo visiting his animal friends

Drag over the visit code into the do nothing and select “expressions”nothing and select  expressions , 

“object under mouse cursor”, then a greeting

Page 28: Tutorial on Kangaroo visiting his animal friends

Here is the event.Now click “play” and click on different 

animals but not the kangarooanimals, but not the kangaroo…

• The Kangaroo will go visit the animal you click• The Kangaroo will go visit the animal you click on.

• Click on another animal and it will go visit that• Click on another animal and it will go visit that animal.