Top Banner
Tutorial on Kangaroo visiting his animal friends - parameters, events
20

Tutorial on Kangaroo visiting his animal friends - parameters, events.

Jan 02, 2016

Download

Documents

Hugo Reynolds
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Tutorial on Kangaroo visiting his animal friends

- parameters, events

Page 2: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Start with new world• Add a Kangaroo and several animals of

different heights, spread around the world• I picked bunny, cow, horse1, ladybug, tortoise,

turtle – any animals will do

Page 3: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Problem

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

Page 4: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Parts of the Tutorial

• Part 1: Kangaroo visit each friend• Part 2: Kangaroo either go around or jump

over• Part 3: Create an event to click on animal to

visit

Page 5: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Part 1: Kangaroo visit Cow

• Create a “Kangaroo” method called visit

Page 6: Tutorial on Kangaroo visiting his animal friends - parameters, events.

See the new Kangaroo visit method

Page 7: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Enter the following code

• For the third line• drop the move forward first• under “kangaroo”, “functions”, drag in “distance to” and

drop over the number• Then click on the last white arrow on the line to select

“Math” and then the minus and 2• The kangaroo will stop two meters in front of the center of the cow…

Page 8: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Add the remaining codeChange “when the world starts” to

Kangaroo.visit and “Play”

Page 9: Tutorial on Kangaroo visiting his animal friends - parameters, events.

How to visit any friend –Add a parameter named friendToVisit

- type should be Object – click ok

1.

2.

Page 10: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Now click and drag friendToVisit on top of the four occurances of Cow

Click and drag from here

Page 11: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Change “when the world starts” back to myFirstMethod

Drag in visit for each friend and “Play”

Page 12: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Part 2: Going around or over friend

• Kangaroo can only jump 1 meter high• If friend is shorter than 1 meter, it is ok to

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

them

Page 13: Tutorial on Kangaroo visiting his animal friends - parameters, events.

First drag in an If/Else from the bottom of the window, placing after the “say”

Page 14: Tutorial on Kangaroo visiting his animal friends - parameters, events.

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

“a<b” selecting 1’s

Page 15: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Drag in “cow’s height” from the cow functions, then drop “friendToVisit” over

cow

Page 16: Tutorial on Kangaroo visiting his animal friends - parameters, events.

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

after the else to “go around”. Then Play

Page 17: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Part 3 – create an event to visit friend clicked on

First, disable code in myFirstMethod

Page 18: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Create a new eventWhen the mouse is clicked on something

Page 19: Tutorial on Kangaroo visiting his animal friends - parameters, events.

Drag over the visit code and select “expressions”,

“object under mouse cursor”

Page 20: Tutorial on Kangaroo visiting his animal friends - parameters, events.

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

animals, but not the kangaroo…