Docstoc

Event handler Flight Simulator

Document Sample
Event handler Flight Simulator Powered By Docstoc
					                         Building a Simple Flight Simulator

In this exercise, you will build a simple flight simulator. You will start with a water
world, add a seaplane to the 'World, build events to allow the user to control the
plane, and then add other objects to the world to make it look more interesting. You
will create the following keyboard controls for the seaplane:

UP ARROW-turn the plane forward (nose down)

DOWN ARROW - turn the plane backward (nose up)

LEFT ARROW- turn left

RIGHT ARROW- turn right

You will also modify world.my first method to keep the plane in motion with its
propeller spinning, and create an event to activate this method while the world is
playing. When you are finished, you will have a world that functions as a simple
flight simulator, and that you can further develop on your own into a more
sophisticated flight simulator or game.

Instructions: First, start a new Alice world and add a seaplane.

1. Open Alice and begin a new world with the water template.

2. Click the ADD OBJECTS button to enter Scene Editor mode, then open the
Vehicles folder in the Local Object gallery.

3. Click the Seaplane Class tile and then click the Add instance to world button to
add a seaplane to the world.

4. Turn the seaplane so that it is facing away from the camera and slightly to the
right, then reposition the camera using the blue camera control arrows so that the
view in the World window looks similar to the figure below
5. Click the DONE button to return to the standard Alice interface and then save
the world with the filename, Flight simulator.a2w, before continuing.

Next, you add four events to steer the plane. Begin by creating an event to turn the
plane forward, which will turn its nose downward. You will then copy and modify
this event to create the three other steering events.

1. Click the create new event button in the Events area and then select when a key is
typed from the menu that appears. A new When any key is typed, do Nothing tile
will appear at the bottom of the Events area.

2. Right-click the new event tile, point to change to on the menu that appears, then
select While a key is pressed.

3. Click the any key parameter in the new event tile and then select Up from the
menu that appears.

4. Click the seaplane tile in the Object tree and the methods tab in the Details area,
then drag a copy of the seaplane turn at speed tile and drop it in the new event
following During:. Select forward and .25 revolutions per second from the menus
that appear.

Now copy the event to the Clipboard and, one at a time, build the three remaining
turn controls from the copy.

1. Drag a copy of the new event from the Events area and drop it on the Clipboard.

2. Drag the content of the Clipboard and drop it in the Events area, below the
existing events.

3. Click UP ARROW in the new copy of the event, then select D from the menu that
appears.

4. Click the forward parameter in the turn at speed instruction in the event handler
of the new copy of the event, and select backward from the menu that appears.

5. Again, drag a copy of the contents of the Clipboard into the Events area. In this
copy, change UP ARROW to Left and change the forward parameter to left.

6. Once more, drag the contents of the Clipboard into the Events area. In this copy,
change UP ARROW to Right and the forward parameter to right.

7. The four turn events are now complete. Save the world again, and then play the
world to test the events. The plane should turn in place in response to your
keystrokes, but it should not yet move. If it does not respond correctly, then
carefully retrace the steps above to find and correct the error.

Next, you will add an event to make the plane move and the propeller spin.
Instructions to do both of these actions will be in world.my first method. Also,
modify the default event so that world.my first method continues to run while the
world plays, and does not run only once when the world starts.

1. Drag a copy of the Do together tile from the bottom of the Editor area and drop it
in world.my first method in place of Do Nothing.

2. Drag a copy of the seaplane move at speed tile from the methods tab and drop it
in the Do together tile in place of Do Nothing. Select forward and 10 meters per
second from the menus that appear.

3. Click the plus sign next to the seaplane tile in the Object tree, and then click the
propeller tile to select the propeller.

4. Drag a copy of the propeller roll at speed tile from the methods tab and drop it in
the Do together tile, below the seaplane move at speed tile. When the menu appears,
point to right, then click other and use the Custom Number dialog box to enter 10 as
the number of revolutions per second.

5. Right-click the When the world starts default event tile in the Events area. When
the menu appears, point to change to, then select While the world is running.

6. Click the world tile in the Object tree. Drag a copy of the my first method tile and
drop it in place of None in the While the world is running tile in the Events area,
following the word During:.

7. The changes to the default event and world.my first method are now complete.
Save the world again and then play the world. This time, the turn controls should
work and the plane should move with the propeller spinning.

You can now fly the plane, but you can easily fly it off camera and lose track of
where it is. Next, add mouse events to the world to control the camera: one to allow
the user to move the camera, and one to point the camera at the plane. These will
allow you to follow the plane as it flies around, and to find the plane if it moves off
camera.

1. Click the create new event button in the Events area and select Let the mouse
move the camera. This is a built-in event type; you do not need to do anything else to
create the complete event.
2. Click the create new event button and select When the mouse is clicked on
something from the menu. Scroll to the bottom of the Events area to see the new
event tile.

3.- Click the camera tile in the Object tree, then drag a copy of the camera point at
instruction tile and drop it in the new event in place of Nothing, following the word
do. When the menu appears, select seaplane. The new event now reads When the
mouse is clicked on anything, do camera point at seaplane. Save the world before
continuing.

Your two new events are complete and ready to be tested. While the world is
playing, click and drag the mouse pointer forward, backward, left, and right in the
playing world window to move the camera. You can pan left and right and zoom in
and out. Simply click the mouse without dragging it to point the camera at the
plane. These controls will work while the keyboard controls are being used to fly the
plane. One person can operate both the mouse and the keyboard using two hands,
or two people can work together - one flying the plane and the other operating the
camera.

Your final task in this exercise is to populate the world with several objects to make
the scene more interesting, as in the Figure below. For example, you could place a
lighthouse in the distance, and then fly the plane around the lighthouse. Several
folders, particularly the Vehicles folder and the Beach folder, contain objects that
you can place in the water to make your world more interesting as you fly the plane.
The Environments folder contains two different islands. Once you have created a
world you like, save the world.

Also, remember that you can use the Take Picture button while the world is playing
to capture an image of the plane in your virtual world. Perhaps you can fly the
plane near some of the objects you add to the world and capture it in an interesting
position while the world is playing.

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:8
posted:10/27/2011
language:English
pages:5