MicroWorlds


Flying Cars

In the following exercise you will drop cars from a flying plane that will disappear when they reach their destination.

The hatchnew procedure has several features

In its name it passes two variables (parameters) :num and :posit. These are passed from the calling procedure flyplane.
It then sets the turtlename to turtt1, assuming that :num = 1. It does this using the word command which joins "turtt and :num
Then creates a new turtle and sets its shape to "car
The setpos command sets the turtles position to posit which has been set in the calling procedure to be the location of the plane.
The pos command gives the coordinates of the turtle.
Seth sets the turtle heading to 220
The remove and clearnames commands remove the turtle that has just been hatched.

The flyplane procedure's main task is to fly a plane across the screen dropping cars. It does this by calling the hatchnew procedure.

Type in the following procedures on the procedures page then create a button to Flyplane and ensure that it works correctly.

to hatchnew :num :posit
   make "tname (word "turtt :num)
   newturtle :tname setsh "car st
   setpos :posit
   seth 220
   repeat 30 [fd 7]
   setsh "sun
   wait 3
   remove :tname
   clearnames
end
to flyplane
   t1, setsh "airplane
   seth 270
   repeat 5[make "num 0]
   t1,
   repeat 10[fd 4]
   wait 5
   make "num :num + 1
   make "posit pos
   hatchnew :num :posit
end

Add your own background and other turtles to make the page more interesting.

You are now ready to move on to A Conversation Program







Last Updated: 22-Oct-2006
Copyright © 2000 - 2006 Geoff Adcock