Title: Chapter 5 - Alice
1Chapter 5 - Alice
- Interaction Events and Event Handling
2Interactive Program vs- Non-Interactive
ProgramWhat is the main difference?
- Interactive
- The sequence of actions is determined at runtime!
- Occurs when
- The user clicks the mouse
- Presses a key on the keyboard
- Objects in the scene move (randomly or guided by
the user) - User can create some conditions like a collision.
- Non-Interactive
- The sequence of actions is pre-determined by
programmer - Programmer designs a complete storyboard
- Programmer writes the program code for the
animated actions. - Every time the program runs the same sequence
will occur.
3What is an Event?
- An event is something that happens.
- Every time the user clicks the mouse or presses a
key on the keyboard to send a signal to Alice
about what to do next. The mouse click or key
press is an event! - In this chapter we learn the mechanics of how the
user create an event and how the program responds
to the event. - Example think of a video game A Car Race.
The scene is determined on how skillful the
driver is steering the car.
4Event handling method!How does it affect what I
do?
- As a animation programmer you must think about
all possible events and make plans for what
should happen. - You need to response to the events.
- Remember When the event handling method occurs,
the location of objects in the scene may or may
not be the same as the last time.
5Biplane Example
- Is an interactive program!
- Biplane is in mid-air and the user is able to fly
the plane. - The plane can move forward, left, and right and a
barrel turn. The user uses the keyboard and mouse
to provide interaction. - The whole idea is to let the user interact with
the biplane.
6Biplane Example
- Has two events
- The spacebar press for the barrel turn and the up
arrow key to move the biplane forward.
Event Spacebar Response Do together roll
biplane a full revolution Play biplane engine
sound
Event Up arrow key press Response Do together
move biplane forward play biplane egine sound
- Page 122 to 123. Just follow the steps.
7Testing!
- How to test? Just save the world and press the
PLAY button. - Tip It is important to test event handling
methods as they are developed. Write a method
and test it, write a method and test it, until
the program is completed. - Why? Incremental development! The advantage is
in making it easier to debug your program. When
something isnt working, it can easily be fix
before it causes bigger problems elsewhere in
your program.
8Parameters and event handling methods
- Parameters are powerful! They allow us to
customize methods to work with different objects
and different numeric values. - Take a look at the Firetruck/Burning Building
example. (page 125 to 127, just follow the steps)
9Burning Building Example
- Another interactive program that shows how to use
parameters in event handling methods. - Firetruck is called to a burning building. The
truck will need to extend its ladder so that each
person can climb down to safety.
10Burning Building Example
Event Click on guy1 Responding Method Save guy
on the first floor
Event Click on girl2 Responding Method Save
girl on the second floor
Event Click on girl3 Responding Method Save
girl on the third floor
Are all these events necessary? Why three? Can
we do the same in one event?
11Burning Building Example
- A better solution is to write only one event and
send the information to the action. Look -
savePerson Parameters whichFloor, whichPerson,
howFar Do in order Point ladder at
whichFloor Extend the ladder howFar
meters whichPerson slides down the ladder to the
firetruck Pull the ladder back howFar meters
Take a look at the program. Follow the steps on
page 125 to 127
12A Greek tragedy!
- A more complex program!
- Responses to an event may involve multiple
actions. Can be a bit messy! - Use stepwise refinement! Break up your
instructions into small steps. - In Greek mythology, Zeus was an all-powerful god.
If Zeus was angered, a thunderbolt would be shot
out of the heavens and strike anyone who got in
the way. - In this program, the tunderbolt has been hidden
in a cloud and smoke is waiting 5 meters below
the gound. - To make this program interactive, we will let the
user choose the object that will be the next
victim of Zeuss anger. - When the user clicks the object, the object will
be passed to the event handling method. We have
alot of actions going on in this program.
13A Greek tragedy!
- We need a parameter to send in the object that
was click. This may contain lots and lots of
coding we simply break it down (stepwise
refinement) it the following
Event An object is mouse-clicked Event handler
shootBolt Parameter who-the object that was
clicked Do in order Call prepareToShoot
method-send who as the target Call
lightingAndThunder method-send who as the
target Lightning move to clouds position
Take a look at the program. Follow the steps on
page 129 to 134.
14For Today
- Re-read chapter 5! Take notes for yourself.
(You can use them on the test) - Complete the worksheet questions. You have 5 of
them! Answers in Chapter 5. - Finish with the examples in Chapter 5. Last
chance if you want credit. - Plane Program Page 121 to 124
- Burning Building Page 125 to 127
- A Greek Tragedy Zeus Page 128 to 134
- Page 137, 5 Rotational Motion Program.
- Project 1 Due Wednesday, February 11th before
you leave.
15Alice Project 1 for Semester Two!
- Due Date is Wednesday, February 11th.
- Problem
- Build an animation for an electronic greeting
card for Valentines Day. You can get ideas
from the following web sites - free.bluemountain.com or greetings.yahoo.com
- The animation is to be a program that is
interactive. Use the material from Chapter 5. - You are also to create a storyboard for your
animation. The storyboard should be done first.
Templates on Web Site www.prosseracademy.org - You will give a presentation next week where you
are required to show off your storyboard and then
demonstrate a working version of your program. - Grading is to be as follows
- Storyboard 25
- Presentation 25
- Program 50
- Instructions
- Create your Valentines Greeting Card.
- Save to your flash drive and bring to my
computer.