Events (2) (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture 10 28 September 2012.

Slides:



Advertisements
Similar presentations
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
Advertisements

Space Man Sam: Grammar Mistakes By Aleis Murphy Duke University, Under the direction of Professor Susan Rodger July 2010.
Microsoft® Small Basic
Class-level Methods Chapter 6. Class-level Method Is specific to a class of objects We can give a class new abilities/methods Only involves this one class.
Skater World: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger May 29,
Review of Chapter 4 Sections 1 and 2 World-level methods involve two or more objects break a large problem into smaller, logical units follow a design.
Events Chapter 7. Interactivity The real world is interactive User determines order of actions instead of programmer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
Microsoft® Small Basic
1 Alice: Beyond the Basics Steve Cooper Michelle Venable-Foster Barbara Ericson May 2007.
1 Alice: Beyond the Basics Steve Cooper Michelle Venable-Foster Barbara Ericson Aug 2009.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Programming Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
CompSci 4 Chap 5 Sec 1 Oct 13, 2005 Prof. Susan Rodger Note: thanks to Wanda Dann and Steve Cooper for slide ideas.
Alice: Functions Alice Chapter 6 September 19, 2005.
Interaction: Events and Event Handling
Alice Learning to program: Part Three Camera Control, Invisibility, and 3-D Text By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger.
Alice in Action with Java Chapter 6 Events. Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use.
Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July.
Events Chapter 7 Part 2. While a Key is Pressed Event Specialized event An event occurs when you press a key and continues until you take your finger.
Today’s Agenda 1.Collect Pre-Lab 5 2.Collect Alice project storyboards 3.Events 4.Dummy Objects 5.Assign pair programming teams and meet upstairs for Lab.
Microsoft Visual Basic 2012 CHAPTER THREE Program Design and Coding.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
Finishing Touches. Headline Subheading Background Pictures Captions.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
Flow Control: boolean expressions, “if” selection statements (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Events (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
Introduction to Alice Alice is named in honor of Lewis Carroll’s Alice in Wonderland.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Methods (part 2) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS 120 Lecture 03 4 September 2012.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Skater World: Part Three By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009.
Tutorial 7 Creating Animations. XP Objectives Learn about animation Create a timeline Add AP divs and graphics to a timeline Move and resize animation.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
An Introduction to Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University, June 2009 Updated June 2014 by Ellen Yuan.
CompSci 4 Chap 5 Sec 2 Oct 9, 2008 Prof. Susan Rodger.
Flow Control: Repetition with While Loops (Alice In Action, Ch 4) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
Methods (part 1) Alice In Action, Ch 2 Slides Credit: Joel Adams, Alice in Action CS120 Lecture August 2012.
CompSci 4 Chap 5 Sec 1 and 2 Oct 14, 2010 Prof. Susan Rodger.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June.
Presenter: Carol Liss Timberlane Regional Middle School 6 th and 7 th grade Tech. Educator Co presenters:
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Variables and Inheritance Part 1 Alice. Review: Properties A class defines properties for its own kind of object. When an object is created (instantiated),
Chapter 2: The Visual Studio.NET Development Environment Visual Basic.NET Programming: From Problem Analysis to Program Design.
Functions (Alice In Action, Ch 3) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Alice in Action with Java Chapter 2 Methods. Alice in Action with Java2 Objectives Build world-level methods to help organize a story into scenes and.
Creating a UFO Rescue Game in Alice
Professor Susan Rodger
Alice Learning to program: Part Three Camera Control, Invisibility, and 3-D Text By Ruthie Tucker and Jenna Hayes, Under the direction of Professor Rodger.
Introduction to Events
Creating a UFO Rescue Game in Alice
Skater World: Part Three
Alice in Action with Java
Interactive Programming
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Headshots in Alice Duke University Professor Susan H. Rodger
Event-driven programming
Interactive Programming
Presentation transcript:

Events (2) (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012

Alice in Action with Java2 Objectives Create new events in Alice Create handler methods for Alice events Use events to build interactive stories

Alice in Action with Java3 Events Event: action generated by a user or a program –Ex: clicking the Play button will generate “ When the world starts ” event Interactive programs, such as games, are event-driven Two steps to making a program respond to an event –Choose or define a method to handle the event Such a method is called an event handler Define an event handler when responsive behavior is complex –Tell Alice to invoke the method when the event occurs

Alice in Action with Java4 Handling Key Presses: A Helicopter Flight Simulator The problem –The mayor’s cat is lost and city government has halted –You need to use your helicopter to find the cat –Search begins at an airport outside the city

Alice in Action with Java5 Event Design Six keys for six types of helicopter movement –‘a’ key: ascend –‘d’ key: descend –Up arrow key: move forward –Down arrow key: move backward –Left arrow key: turn left –Right arrow key: turn right Keys are chosen for two reasons –Convenient positions and mnemonic values Choosing correct keys improves usability

Alice in Action with Java6 Helicopter Flight Simulation Plan the world for a helicopter simulation –Add airport, helicopter, city terrain, buildings, and a cat –Position the helicopter at the airport –Position camera to be peering out in front of helicopter –Set the camera ’s vehicle property to be helicopter

Alice in Action with Java7 Helicopter Flight Simulation Event handling –Observation: feasible helicopter motion depends on its status in air E.g. it can only descend, turn L/R, or move F/B, when it is in air –Define Boolean property inTheAir for helicopter –In event handler methods, check the value of inTheAir and respond accordingly

Alice in Action with Java8 Helicopter Flight Simulation Making the helicopter ascend (continued) –Add a When a key is typed event –Change event to While a key is typed event –Associate the ‘ A ’ key with the event –Enable the handler to perform while ‘ A ’ key is pressed

Alice in Action with Java9 Helicopter Flight Simulation

Alice in Action with Java10 Helicopter Flight Simulation Making the helicopter descend –Define descend() method for helicopter Method logic mirrors the logic of ascend() Note that the ground provides a floor for the descent –Enable descend() to perform while ‘ D ’ key is pressed

Alice in Action with Java11 Helicopter Flight Simulation

Alice in Action with Java12 Helicopter Flight Simulation Define turnSlightly() to handle left or right turns –helicopter turns only if inTheAir is true –turnSlightly() takes a Left or Right argument –Arrow keys are associated with the method –Depressing arrow key sends a Left or Right argument

Alice in Action with Java13 Helicopter Flight Simulation Connect the left and right arrow keys with the method –Depressing arrow key sends a Left or Right argument

Alice in Action with Java14 Helicopter Flight Simulation Define go() to handle forward or backward movement –Logic is similar to logic for turnSlightly() method

Alice in Action with Java15 Alice Tip: Using 3-D Text Helicopter simulator should have flight instructions Solution: add 3-D text that explains the interface Creating 3-D text for the simulator –Return to the Add Objects screen –Click Create 3D Text (at far end of Local Gallery ) –Add flight instructions in the text box –Click OK –Rename the text object, instructions

Alice in Action with Java16 Alice Tip: Using 3-D Text (continued)

Alice in Action with Java17 Repositioning Text that is Off-Camera Right-click instructions to access methods Three settings for positioning text in front of camera –Choose methods-> setPointOfView( camera –Choose methods->move(, ) ->FORWARD->10 meters –Choose methods->turn, ) ->LEFT->1/2 revolution Linking text to camera and changing text color –Set instructions.vehicle to camera –Set instructions.color to yellow

Alice in Action with Java18 Repositioning Text that is Off-Camera (continued)

Alice in Action with Java19 Adding a Background Text for instructions is difficult to read Solution: provide a background for the text One way to add a background to instructions –Insert square object ( Square is in Shapes Folder ) –Resize and reposition square behind instructions –Set square.color property to black –Make light turn to face the instructions –Set the square.vehicle property to instructions

Alice in Action with Java20 Adding a Background (continued)

Alice in Action with Java21 Making Text Appear or Disappear Another example of two-state behavior Implementation strategy –Add handler to switch value of isShowing property Logic of toggleInstructionVisibility() –Negate the value of isShowing property –Apply negation to both square and instructions Completing the implementation of the handler –Add a When a key is typed event –Associate the toggle method with the spacebar

Alice in Action with Java22 Making Text Appear or Disappear (continued)

Alice in Action with Java23 Making Text Appear or Disappear (continued)

Alice in Action with Java24 Summary Event: action generated by a user or a program User events: keyboard events and mouse events Event handler: method called in response to an event Event-driven program: program directed by events and handlers Two-state behavior: pattern that switches the state of an object

Student To Do’s Readings: –Alice in Action, Chapter 6 Homework Due Lab Session Midterm: Friday, Oct 12 th on material through today We will start Java next week. –Make sure you have the Java textbook. Alice Project –Details on Monday in Lab –Can not be dropped –Groups of 1 to 3 people –In-Class Demos on Tuesday Oct 15 th 25