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.

Slides:



Advertisements
Similar presentations
Create a Simple Game in Scratch
Advertisements

Mike Scott University of Texas at Austin
Data Structures Using Java1 Chapter 3 Array-Based Lists.
Space Man Sam: Grammar Mistakes By Aleis Murphy Duke University, Under the direction of Professor Susan Rodger July 2010.
Create a Simple Game in Scratch
Data Structures Using Java1 Chapter 1 Software Engineering Principles and Java Classes.
Skater World: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger May 29,
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.
Alice in Action with Java
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Using Microsoft Outlook: Basics. Objectives Guided Tour of Outlook –Identification –Views Basics –Contacts –Folders –Web Access Q&A.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Line up By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
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.
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.
Events (2) (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Teaching a character to walk in more than one world: Parameters and Inheritance. By Lana Dyck under the direction of Professor Susan Rodger Duke University.
Adobe Flash CS3 Revealed Chapter 3 - WORKING WITH SYMBOLS AND INTERACTIVITY.
Microsoft PowerPoint Tutorial Created by L. George 2006.
Microsoft Access 2010 Chapter 8 Advanced Form Techniques.
An Introduction to Alice (Short Version) – Extras! Yossra Hamid Under the Supervision of Professor Susan Rodger Duke University, June 2014 This is a continuation.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1,
PowerPoint Practice Exercise 1 1.Save this file in your AV-TECH Folder as PowerPoint Practice Exercise 1. 2.Open this file in PowerPoint. 3.Edit each slide.
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.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
Alice in Action with Java Chapter 5 Lists and Arrays.
Balancing the scales: Inequalities By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Ready, SET, go! By Melissa Dalis Professor Susan Rodger Duke University July 2011.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
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.
Skater World: Part Four By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 1, 2009.
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.
Presenter: Carol Liss Timberlane Regional Middle School 6 th and 7 th grade Tech. Educator Co presenters:
Making Billboards By Deborah Nelson Duke University, Under the direction of Professor Susan Rodger, July 14, 2008.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Introducing Scratch Learning resources for the implementation of the scenario
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
By Melissa Dalis Professor Susan Rodger Duke University June 2011
Professor Susan Rodger
Scratch for Interactivity
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.
Chapter 1: An Introduction to Visual Basic 2015
Getting started in Alice
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko
Introduction to Events
Creating a UFO Rescue Game in Alice
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
Skater World: Part Three
Alice in Action with Java
Learning to Program: Part 3 Camera Control, Invisibility and 3-D Text
Headshots in Alice Duke University Professor Susan H. Rodger
Creating a Simple Game in Scratch
Presentation transcript:

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 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 Events (continued)

Alice in Action with Java5 Handling Mouse Clicks: The Magical Doors Goal: add events to world built in Section –Review: castle door tells random knock-knock jokes Events that will be added to the original program –Right door opens when the user clicks it –Left door tells knock-knock joke when the user clicks it

Alice in Action with Java6 The Right Door First step: stop door from automatically telling jokes by making world.my first Method do nothing Recall the two steps to handle an event –Use a predefined method or define a new method –Create an event that invokes the handler Enabling the right door to respond to a mouse event –The door open/close motion feels simple let us choose turn() to handle the event –Add When the mouse is clicked on something –Specify castle1.door as the event source

Alice in Action with Java7 The Right Door (continued)

Alice in Action with Java8 The Left Door Enabling the left door to respond to a mouse event –Specify castle.door2 as the source of this event –Drag-and-drop world s random joke method as handler Test the program by clicking each door

Alice in Action with Java9 The Right Door Revisited Logic error: right door continues to turn with user click Right door should open if closed, and close if open –i.e. exhibiting the two-state behavior General approach for dealing with multi-state behavior –Add an object property variable to store the object state –In object methods, use control flows such as the if statement to generate appropriate actions and perhaps also change the object state value afterwards

Alice in Action with Java10 The Right Door Revisited Fix: implement two-state behavior for right door –Add Boolean property rightDoorClosed to castle –Replacement handler: openOrCloseRightDoor() –Build turn logic around the value of rightDoorClosed

Alice in Action with Java11 The Right Door Revisited (continued)

Alice in Action with Java12 Event Handling is Simultaneous Example: left door tells jokes while right door turns Alice handles simultaneous events well

Alice in Action with Java13 More on Events Conflicts can arise when coding parallel event logic –Example: two handlers modify the same property How to avoid conflict –Ensure that handlers modify a property in sequence Event categories –Mouse event: triggered by mouse movement or click –Keyboard event: triggered when user presses a key –Program event: triggered when variable value changes

Alice in Action with Java14 Handling Key Presses: A Helicopter Flight Simulator The problem –The mayors 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 Java15 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 Java16 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 Java17 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 Java18 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 Java19 Helicopter Flight Simulation

Alice in Action with Java20 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 Java21 Helicopter Flight Simulation

Alice in Action with Java22 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 Java23 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 Java24 Helicopter Flight Simulation Define go() to handle forward or backward movement –Logic is similar to logic for turnSlightly() method

Alice in Action with Java25 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 Java26 Alice Tip: Using 3-D Text (continued)

Alice in Action with Java27 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 Java28 Repositioning Text that is Off-Camera (continued)

Alice in Action with Java29 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 Java30 Adding a Background (continued)

Alice in Action with Java31 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 Java32 Making Text Appear or Disappear (continued)

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

Alice in Action with Java34 Alice Tip: Scene Transitional Effects for the Camera (not covered in CS120) Transition: bridge between two scenes (or shots) Some transition effects –Cut: instantaneous jump from one scene to another –Fade: darken existing scene, light another –Wipe: cover existing scene, uncover new scene Alice does not provide built-in transitional effects Alice does provide building blocks for transitions

Alice in Action with Java35 Setup for Special Effects Creating shutters for your camera –Add four square s outside of the viewport –Change names to indicate shutter positions –Change each square color to black –Change each square.vehicle to camera –Move the shutters outside of the viewing area Shutters will be manipulated to create effects

Alice in Action with Java36 Setup for Special Effects (continued)

Alice in Action with Java37 Setup for Special Effects (continued)

Alice in Action with Java38 The Fade Effect A fade effect darkens and then lightens a screen Create effect using complementary methods Overview of implementing fadeToBlack() –Set the topShutter s opacity to zero percent –Move the topShutter to cover the camera viewport –Set topShutter opacity back to 100 percent Overview of implementing fadeFromBlack() –Reverse the actions of fadeToBlack() Use fadeToBlack() and fadeFromBlack() in pairs –The scene changes between method calls

Alice in Action with Java39 The Fade Effect (continued)

Alice in Action with Java40 The Fade Effect (continued)

Alice in Action with Java41 The Barndoor Edge Wipe Effect Edge wipe: edges cover one scene, reveal another Barndoor wipe: shutters slide like doors of a barn –Vertical: doors close and open from sides of screen –Horizontal: doors close and open from top and bottom Create barndoor wipes with complementary methods Implementing verticalBarndoorClose() –Move the left and right shutters into the viewing area Implementing verticalBarndoorOpen() –Move the left and right shutters out of the viewing area

Alice in Action with Java42 The Barndoor Edge Wipe Effect (continued)

Alice in Action with Java43 The Barndoor Edge Wipe Effect (continued)

Alice in Action with Java44 The Box Iris Wipe Effect Iris contains the open area of the screen End one scene by shrinking the iris As iris expands, the new scene is revealed Defining the box iris close effect –Simultaneously move all four shutters onto viewport –Sender specifies duration of the effect –Sender specifies percentage the iris is closed One parameter and two local variables are needed Box iris open effect is complementary to close effect

Alice in Action with Java45 The Box Iris Wipe Effect (continued)

Alice in Action with Java46 The Box Iris Wipe Effect (continued)

Alice in Action with Java47 The Box Iris Wipe Effect (continued)

Alice in Action with Java48 Reusing Transition Effects Limitations of save object as… technique –Cannot be used to save properties as objects –Consequence: camera cannot be saved with shutters Solution: define transitions in a template world Contents of template (named TransitionEffects ) –camera, light, ground, and square s Using TransitionEffects template world –Open template as starting world for user story –Use File->Save world as… to save and rename

Alice in Action with Java49 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 Add 3D Text dialog box: tool for inserting text

Alice in Action with Java50 Summary (continued) square : convenient shape for creating a text background and transition effects Transition effect: bridge between two scenes Types of transition effects: cut, fade, and wipe A transition effects template world includes ground, light, camera, and effects objects