DOC PREVIEW
Duke CPS 004 - Chap 5 Sec 1

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CompSci 4Chap 5 Sec 1Feb 22, 2005Prof. Susan RodgerNote: thanks to Wanda Dann and Steve Cooper for slide ideasAnnouncements• Read Chapter 5 Sec 2 for next Tuesday• No Class on Thursday –– TA’s will be in D240 9:15-10:15am for checkoffs– catch up day, get old work checked off– Need to catch up if behind!• MakeUp Class, Pixar Talk– Monday Mar 21, 7:30pm• New groups todayWhat we will do today• Lecture on Chap 5, Sec 1 – Interactive Programming• ClassworkControl of Flow• Control of flow – how the sequence of actions in a program is controlled– What action happens first, second, third, ….• In movie-style programs (Chaps 1-4) the sequence of actions is determined by the programmer– Creating a storyboard design– Writing program methods to carry out the designed sequenceInteractive Animations• In interactive programs, the sequence of actions is determined at runtime, when the user provides input– Clicks the mouse– Presses a key on the keyboard• Other sources of input are possibleInteractive Games• In a video game where the user is guiding a spaceship, the sequence of actions …– Depends on what direction the user guides the ship– How fast the user presses the controls• Each time the program runs, user input may cause a different sequence of actions• Control of flow is “in the hands of the user”Events• Each time the user provides some sort of input, an event is generated– An event is something that happensFrom AppendixWhen spacebar pressed,Bee turns aroundEvent Handlers• An event may– Trigger a response, or– Move objects into positions that create some condition (e.g. a collision) that triggers a response• A method is called to carry out the response. The type of method is called an event handler.• When an event is linked to an event handler, a behavior is created.How does this effect your program?• Our goal is to write interactive programs.• The approach is the same as before, but the difference is now must be concerned with behaviors.– input from the user (events)– How objects respond to an event (event handler methods)Example• Build an air show flight simulator. The pilot uses the biplane controls to perform acrobatic stunts.Problem• The idea in a flight simulator– Allow user to control the flight path• Problem– How do we write program code to provide a guidance system that allows the user to be the pilot?Solution• Use keyboard input– Up-arrow key to move the biplane forward– Spacebar to make the biplane do a barrel roll– Note: other keys could be chosen• Write event handler methods that respond to each key pressStoryboards• Since two keys are used, two events are possible – so two storyboards are needed• Each storyboard outlines and event handler– Responds to a particular eventEvent: Spacebar pressResponse:Do togetherroll biplane a full revolutionplay biplane engine soundEvent: Up arrow pressResponse:Do togethermove biplane forwardplay biplane engine soundDemo• A demo of building the biplane simulation– flyForward– barrelbiplane.flyForward• Do not modify the length of the sound – use “as is”• Coordinate duration of move and play sound– Match duration of move to duration of soundEvents Editor - Linking• Each event handler method must be linked to an event1) Select “create new event”Then choose the type of event2) A template linking is createdEvents Editor – Linking (cont)3) Select type of key for event 4) Select event handler methodFinal result:Testing• Test event handler methods as they are developed• Write a method and test it, write a method and test it, and so on– incremental developmentClasswork today• Create 4 buttons and a spider robot• Press green button and spider moves forward• Press red button and spider moves backward• Other two


View Full Document

Duke CPS 004 - Chap 5 Sec 1

Documents in this Course
Lecture

Lecture

18 pages

Chapter 7

Chapter 7

18 pages

Chapter 9

Chapter 9

15 pages

Java 1

Java 1

24 pages

Java 3

Java 3

11 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

28 pages

Chap 2

Chap 2

16 pages

Graphics

Graphics

20 pages

Lecture

Lecture

12 pages

HTML

HTML

16 pages

Java 1

Java 1

6 pages

Chapter 4

Chapter 4

16 pages

The Plan

The Plan

25 pages

Lecture

Lecture

16 pages

Chapter 6

Chapter 6

21 pages

Lecture

Lecture

18 pages

Lecture

Lecture

23 pages

Lecture

Lecture

16 pages

Lecture

Lecture

19 pages

Lecture

Lecture

12 pages

Lecture

Lecture

5 pages

Lecture

Lecture

26 pages

Lecture

Lecture

16 pages

Chapter 7

Chapter 7

23 pages

Lecture

Lecture

21 pages

Lecture

Lecture

4 pages

Lecture

Lecture

4 pages

Lecture

Lecture

8 pages

Lecture

Lecture

4 pages

Lecture

Lecture

10 pages

Chapter 4

Chapter 4

32 pages

Java

Java

4 pages

CompSci 4

CompSci 4

18 pages

Lecture

Lecture

26 pages

CompSci 4

CompSci 4

12 pages

HTML

HTML

17 pages

Lecture

Lecture

16 pages

Chapter 5

Chapter 5

22 pages

Lecture

Lecture

4 pages

Chapter 4

Chapter 4

10 pages

Chapter 2

Chapter 2

15 pages

Chapter 8

Chapter 8

14 pages

Lecture

Lecture

15 pages

Load more
Download Chap 5 Sec 1
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Chap 5 Sec 1 and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Chap 5 Sec 1 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?