5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.

Slides:



Advertisements
Similar presentations
Sprite-visual object (actor on the stage) Scripts- Tells actors (sprites) what to do.
Advertisements

Introduction to Macromedia Director 8.5 – Lingo
Create a Simple Game in Scratch
Create a Simple Game in Scratch
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
As you come in…  Sign in (in back) and pick up  Badge  Name Card – write your first name LARGELY on back  Log in:  Launch/Start Alice  Any questions?
PIIT Computer Science Summer Camp - Alice July 10, 2012 Brenda Parker Computer Science Department MTSU.
PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU.
Alice Inheritance and Event Handling. Inheritance Concept Consider this hierarchy; parents describe properties of children Animals Vertebrates MammalsFish.
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.
Lets Play Catch! Keeping Score in Alice By Francine Wolfe Duke University Professor Susan Rodger May 2010.
Code Club Session 3 Shark Eats Fish. Picture of finished product here.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
Exploring Events. Try this Start Alice and create a blank world using the grass template. Add an instance of a BlueBallerina. Add an instance of a PinkBallerina.
CS320n –Visual Programming Interactive Programs Mike Scott (Slides 5-1)
Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Rodger Duke University, July 2008.
Wizard Game: Class-Level Variables in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July
Adding Automated Functionality to Office Applications.
SE320: Introduction to Computer Games Week 8: Game Programming Gazihan Alankus.
Scratch the Cat. Object Oriented Programing Writing computer programs Based on Objects Instead of Actions Based on Data Instead of Logic.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
V Avon High School Tech Club Agenda Old Business –Delete Files New Business –Week 16 Topics: Intro to HTML/CSS –Questions? Tech Club Forums.
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.
This will let you see the game you are going to play on the inside. It will help you see what all goes into creating instance to that goes into setting.
Branching and Looping Examples, cont’d. Remember the generic triple jump world…
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
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.
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
Introduction to Arrays. definitions and things to consider… This presentation is designed to give a simple demonstration of array and object visualizations.
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.
Checking for Collisions: Alternative Method Erin Taylor Under the Direction of Susan Rodger July 2015 Duke University.
Events (2) (Alice In Action, Ch 6) Slides Credit: Joel Adams, Alice in Action CS 120 Lecture September 2012.
Interactive Programming Sec 49 Web Design. Objectives The student will: Understand the difference between movie mode and an interactive program Understand.
© Jalal Kawash Programming Peeking into Computer Science 1.
Mathematical Expressions, Conditional Statements, Control Structures
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.
Buttons and Birds: Introduction to Interactive Events in Alice By Henry Qin, edited by Jenna Hayes under the direction of Professor Susan Rodger Duke University,
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Unit 3 Music and Sound Evangel College S.2 ICT.
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.
Today we are learning to: Understand how actions and events control our game. Completing the catch the clown game – making a room – adding music Gather.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Input Boxes, List Boxes, and Loops Chapter 5. 2 Input Boxes Method for getting user’s attention to obtain input. InputBox() for obtaining input MessageBox()
Scratch for Interactivity Dr. Ben Schafer Department of Computer Science University of Northern Iowa.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Creating a Simple Game in Scratch Barb Ericson Georgia Tech May 2009.
Creating a UFO Rescue Game in Alice
Collision Theory and Logic
Scratch for Interactivity
Starting Out with Alice: A Visual Introduction to Programming
Collision Theory and Logic
Scratch Unit Overview We are going to look at computer programming and how to create your very own computer game The piece of software we will be using.
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops
Introduction to Events
Creating a UFO Rescue Game in Alice
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Introduction to TouchDevelop
ICT Gaming Lesson 3.
ICT Programming Lesson 5:
Creating a Simple Game in Scratch
Presentation transcript:

5 Event Handling Interactive Programming

Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term with new textbook copies If you bought a used copy, then read the lab manual: JT’s examples: examples_part5.htm

Objectives By the end of the section, the student will: 1. Understand events and event handling 2. Create and use 9 events and even handlers in Alice 3. Start working on interactive games

Interactive Programming Programs seen so far do not interact with the user Interactive programs: react to user events ◦Such as: moving the mouse, clicking, or pressing a key on the keyboard Interactive games are one example

JT (Until Now): Program control is largely determined by the program through a series of sequential statements. Simple program: pure linear sequence Program with loops: not purely linear but the timing of execution can be directly predicted

JT: Traditional Software The user can only interact with the program at places that are specified by the program (e.g., when an input statement is encountered). Examples

Program control can also be sequential Example 14 JT: Event-Driven Software

JT: Event-Driven Software Can Include Code That Occurs Only When Event Occurs Regular code instructions Event: When??? Always runs when program runs Only runs when event occurs as program is running

Event Types When the world starts When a key is typed When the mouse is clicked Let the mouse move an object Let the arrow keys move an object Let the mouse move the camera Let the mouse orient the camera While something is true When a variable changes

Event Handling When an event takes place, a method is executed JT: Recall this example Method ‘startOfTheWorld’ is an example of an event handler

JT: Steps For Creating An Event Handler 1. Identify the event

JT: Steps For Creating An Event Handler 2. Create a handler for it (define a method that runs when the event occurs)

JT: Steps For Creating An Event Handler 3. Register the handler for this event

When an event happens Wait until an event happens Every time it happens, a handler is performed E.g. when a mouse is clicked

JT: Specific Events May Be Tied To Handlers Example 15: (up/down) arrows

JT: Events Specific To Objects, Random Reactions Example 16: Example 16 Likes body petting Hates head petting

JT: Method “catPettedPoorly” Play angry cat sound Cat’s random reactions to event

JT: Method “catPettedGood” Sounds of contented cat Cat’s happy reactions

When the world starts When the world starts, “world.my first method” is executed You can change it

When the world starts In a world with an monkey object Create a simple method of monkey, dance:

When the world starts Register the new method for the event When the world starts, monkey.dance will be executed instead of world.my first method

When a key is typed Create a new event

When a key is typed Choose the key to be typed

When a key is typed Choose handler method

When a key is typed Every time the space key is typed, the monkey dances

Example A world with two penguins facing each other

Example White penguin moves towards pink penguin until too close

Example Holding the white penguin back: event and its handler

Exercise Create an Alice world and add one object to it Write handlers so that: UP arrow key: moves the object up ½ meters DOWN arrow key: moves the object down ½ meters LEFT arrow key: moves the object left ½ meters RIGHT arrow key: moves the object right ½ meters

When the mouse is clicked Create a method for monkey, head fly:

When the mouse is clicked Register the handler

When the mouse is clicked Register the handler

Let the mouse move an object Create a new event

Let the mouse move an object This event works on lists Create a new list

Let the mouse move an object This event works on lists Create a new list Click on the monkey to drag it

Let the arrow keys move an object Create a new event

Let the arrow keys move an object Create a new event

Let the mouse move the camera This event allows you to drag the mouse and move the camera

Let the mouse orient the camera Similar to moving the camera, except it only moves the camera left or right (orientation)

While and events As long as something is true, perform the handler action This action is performed repeatedly, until the while condition becomes false

While something is true While a condition is true do the following Up to three actions are performed: When the while condition becomes true, while the condition is true, and when it becomes false.

When a variable changes

JT: Event For Changing Variables Example 17 Important variable Define key methods Register methods

JT: Event For Changing Variables