Events (Alice In Ac.on, Ch 6)

Similar documents
Events (Alice In Action, Ch 6)

Methods (part 2) Alice In Action, Ch 2

Skater World: Part Three

Methods (part 1) Alice In Action, Ch 2

Methods (part b) Alice In Ac5on, Ch 2

Getting Started with Java Using Alice. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Plotting Points. By Francine Wolfe Professor Susan Rodger Duke University June 2010

Repetition everywhere comparing while in a method and as an event. Comparison

Changing Camera Views! Part 2: Simple Scene Change & Lighting Fixes

Variables and Functions Chapter 3

Alice: A Free 3D Animation World for Teaching Programming

Flow Control: boolean expressions, if selec5on statements (Alice In Ac5on, Ch 4)

Class-level Methods. Chapter 6 part 1

TSS. Event CAD Tutorial. Event Hire Software. Software Solutions for the Event Hire Industry. 2D/3D Layout and Presentation. T S Solutions Limited

Learning to Program: Part 1 Scene Setup and Star4ng Anima4on

Headshots in Alice. Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008 Updates made June 2014 by Yossra Hamid

Introduction to Events

The Essentials of Alice

potions. The troll doubles in size.

Alice. Creating Sounds, Making Billboards, Fun with 3 D Text, New Events, and Rotating Objects

Getting Started with Java Using Alice. 1 Copyright 2013, Oracle and/or its affiliates. All rights reserved.

Princess & Dragon Part 4: Breathing Fire Adding Effects to Alice

Chapter 0. Getting Started. Objectives

Customizing Ribbon with New Main Tab. 1 of 8

The Alice Scene Editor

The Matrix. By Melissa Dalis Professor Susan Rodger Duke University June 2011

move object resize object create a sphere create light source camera left view camera view animation tracks

Appendix A Reference: Built-in Methods

(Refer Slide Time: 01:40)

In this lesson you are going to create a drawing program similar to Windows Paint. 1. Start with a new project and remove the default cat sprite.

Graphical User Interface. GUI in MATLAB. Eng. Banan Ahmad Allaqta

Setting up A Basic Scene in Unity

Name Introduction to Computer Science. 1. A sequence of instructions that tell the computer what to do is known as a?

Layers (Just the Basics) By Jerry Koons

Autodesk Inventor Design Exercise 2: F1 Team Challenge Car Developed by Tim Varner Synergis Technologies

Simply Personnel Screen Designer

Creating Postcards in Microsoft Publisher

Word Creating & Using Tables. IT Training & Development (818) Information Technology

Prezi Creating a Prezi

2 SELECTING AND ALIGNING

2 The Stata user interface

Chapter 2 Motion. Now consider a horizontal pipe running through it (left to right). Now, a vertical pipe (top to bottom) runs through the same point.

Sphero Lightning Lab Cheat Sheet

The Essentials of Alice (Bunny) By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008

Advanced Flex Control Builder Guide: Tricks and Tips

Constants. Why Use Constants? main Method Arguments. CS256 Computer Science I Kevin Sahr, PhD. Lecture 25: Miscellaneous

3D Massing Graphics Using Sketchup and Photoshop

Step 1: Changing the Penguins Colors. Download the starting world that goes with this tutorial. We are

Microsoft PowerPoint 2013 Beginning

Princess & Dragon Part 1: Objects in an Alice World

Copyright GeoSLAM Viewer User Guide 2017 GeoSLAM Ltd. All rights reserved. Version GeoSLAM Ltd 1 GeoSLAM Viewer User Guide v1.0.

icms Pro USER s MANUAL Ver 1.0

Word 2003: Flowcharts Learning guide

icms Pro USER S Manual Ver 1.4

Using Flash Animation Basics

Peeking into Computer Science Alice Lab Manual. Lab Manual. Programming

Word 2016 Tips. Rylander Consulting

Microsoft PowerPoint 2007 Beginning

Instructions for automatically masking a black background in Agisoft PhotoScan

Finder windows To open a new Finder window, click the Finder icon in the Dock, then select File > New Window.

EASY INTERACTIVE WHITEBOARD

Maya 2014 NURBS Modeling Tutorial Airship

Our Goals Teaching with Power Point

Word 2007: Flowcharts Learning guide

Windows XP. A Quick Tour of Windows XP Features

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

Skater World: Part Four. By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 2009

XPEL DAP SUPPORT. DAP Tool List & Overview DESCRIPTION ICON/TOOL (SHORTCUT)

Alice 3 Workshop. CS & IT Irvine, CA July 9, Copyright 2012 Wanda Dann, Don Slater, Steve Cooper

How to set up an Amazon Work Profile for Windows 8

Chapter 5. Inserting Objects. Highlights

This guide will help you with many of the basics of operation for your Epson 485wi BrightLink Projector with interactive functionality.

CS 4300 Computer Graphics

Microsoft PowerPoint 2010 Beginning

Word 3 Microsoft Word 2013

Index. Guide. Camera Detect Event Guide. AcuraVision

ABOUT THIS COURSE... 3 ABOUT THIS MANUAL... 4 LESSON 1: MANAGING LISTS... 5

Making Billboards. By Deborah Nelson Duke University, Under the direc:on of Professor Susan Rodger, July 14, 2008

Getting Started with Snapper.Photo s. PhotoManager. Welcome to the World of. S napper.photo

How to Draw Wireframe for Android Apps? Written Date : February 3, 2016

Teach Yourself Microsoft PowerPoint Topic 4: Slide Master, Comments and Save Options

A Guide to Autodesk Maya 2015

CS 106A, Lecture 14 Events and Instance Variables

Game Design Unity Workshop

Excel Formulas & Functions I CS101

ENVI Classic Tutorial: A Quick Start to ENVI Classic

Severe Weather Safety PSA

A BEGINNERS GUIDE TO USING ADOBE PREMIERE PRO

Quick Start Guide to using Light Converse along with Pangolin LD2000 and BEYOND

PowerPoint Intermediate 2010

3 D Helium Molecule Tutorial. Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008

Useful Google Apps for Teaching and Learning

Opening the Program. Movie Maker II 1

Exploring Microsoft Office Word 2007

Managed Reporting Environment

The PCC CIS etutorial to Windows

Organize Mail into Folders

Project 2: 3D transforms and Cameras

Bombardier Business Aircraft Customer Services. Technical Publications. SmartPubs Viewer 3.0 User Guide. Updated January 2013 [2013]

BSc Computing Year 3 Graphics Programming 3D Maze Room Assignment Two. by Richard M. Mann:

Transcription:

CS 101 Lecture 26/27 Events (Alice In Ac.on, Ch 6) Slides Credit: Joel Adams, Alice in Action Objectives Programming to respond to events Create new events in Alice Create handler methods for Alice events Use events to build interactive stories Alice in Action with Java 2 1

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 Java 3 More on Events 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 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 Alice in Action with Java 4 2

Events (continued) Alice in Action with Java 5 Handling Mouse Clicks: The Magical Doors 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 Java 6 3

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 Java 7 The Right Door (continued) Alice in Action with Java 8 4

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 Java 9 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 Java 10 5

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 Java 11 The Right Door Revisited (continued) Alice in Action with Java 12 6

Event Handling is Simultaneous Example: left door tells jokes while right door turns Alice handles simultaneous events well Alice in Action with Java 13 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 Java 14 7

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 Java 15 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 Java 16 8

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 Java 17 Helicopter Flight Simulation Alice in Action with Java 18 9

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 Java 19 Helicopter Flight Simulation Alice in Action with Java 20 10

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 Java 21 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 Java 22 11

Helicopter Flight Simulation Define go()to handle forward or backward movement Logic is similar to logic for turnslightly()method Alice in Action with Java 23 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 Java 24 12

Alice Tip: Using 3-D Text (continued) Alice in Action with Java 25 Repositioning Text that is Off-Camera Right-click instructions to access methods Three settings for positioning text in front of camera Choose methods-> setpointofview (<asseenby)->camera Choose methods->move(<direction>,<amount>) ->FORWARD->10 meters Choose methods->turn<direction>,<amount>) ->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 Java 26 13

Repositioning Text that is Off-Camera (continued) Alice in Action with Java 27 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 Java 28 14

Adding a Background (continued) Alice in Action with Java 29 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 Java 30 15

Making Text Appear or Disappear (continued) Alice in Action with Java 31 Making Text Appear or Disappear (continued) Alice in Action with Java 32 16

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 Alice in Action with Java 33 17