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.

Slides:



Advertisements
Similar presentations
Introduction to Macromedia Director 8.5 – Lingo
Advertisements

Mike Scott University of Texas at Austin
AliceWhileLoop1 While Loop in Alice Stephen Cooper Wanda Dann Randy Pausch Barb Ericson Oct 2009.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Coloring Randomly: Random Selection in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July 2008.
PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU.
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.
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Repetition Structures
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Fall 2007ACS-1805 Ron McFadyen1 Ch 7 Loops Alice has two control structures for controlling the repeated execution of statements Loop While.
While: Indefinite Loops Sec 8-14 Web Design. Objectives The student will: Understand what an Indefinite Loop is Understand how create an indefinite loop.
Functions and Visual Effects Chapter 6 Part 3. Built-in Functions We have been using built-in functions so far 2.
Repetition: Definite Loops Alice. Repetition In many kinds of animations, especially simulations and games, some actions happen again and again. Example:
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Introducing While loops (and random numbers too) Alice.
While: Indefinite Loops Alice. Repetition In some situations, we don’t know exactly how many times a block of instructions should be repeated. All we.
Alice in Action with Java Chapter 5 Random Numbers.
Programming in Alice Chapter 2. Today’s Agenda Designing a Program Writing Methods Executing Instructions Simultaneously Comments Tips for Setting Up.
CS320n –Visual Programming Random Numbers and Random Motion (Slides 6-3) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for slide ideas.
Fall 2007ACS-1805 Ron McFadyen1 Chapter 5 Interactive Programs.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
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.
Programming in Alice Chapter 2 Part 2. Events Editor Identifies what method is executed (run) when the “Play” button is hit 2.
Functions and Conditionals in Alice 1 Stephen Cooper Wanda Dann Barb Ericson September 2009.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running o Stored in.
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.
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
Branching and Looping Examples, cont’d. Remember the generic triple jump world…
Execution Control with If/Else and Boolean Functions
Welcome! The Topic For Today Is…Review for Test. Your Topic Basics of Programming Control Statements Programming Concepts InteractionAlice Concepts 200.
Study Guide For Test Chapter 5, 6,& 7 Test is Friday, May 15th.
Class-level Methods Chapter 6 part 1. Classes and Objects Classes o In Alice, classes are predefined as 3D models Objects o An object is an instance of.
Decision Structures Chapter 4 Part 2. Chapter 4 Objectives To understand o What relational operators are and how they are used o Boolean logic o Testing.
Getting started with Alice Adapted from presentations by Jenna Hayes, Duke University Donna Gavin, UWP Computer Science and Software Engineering.
Changing Color, Using Text Objects, and Random Selection in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Programming: Simple Control Structures Alice. Control Statements We have been using Do in order and Do together to control the way instructions are executed.
Functions Alice.
Making a Timer in Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Mathematical Expressions, Conditional Statements, Control Structures
Bunny Eat Broccoli Repetition – Simple loops and Conditional loops Susan Rodger Duke University July 2011.
Can I get your number? By Melissa Dalis Professor Susan Rodger Duke University June 2011.
Variables and Functions Chapter Variables Named storage location in computer’s memory Programs may need to store data when running Types of data.
Functions Sec 8-11 Web Design. Objectives The Student will: Understand what a function is Know the difference between a method and a function Be able.
Repetition Structures Chapter 5 Part The While Instruction  Combines Loop and the condition that is also used in If/else statements  The loop.
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.
Programming: Putting Together the Pieces Built-in Functions and Expressions Alice.
Obj: Programming: Simple Control Structures HW: Read section 3 – 2 AC3 D2 Do Now: 1.Log on to Alice. Open the file firstEncounter.a2w located in the folder.
5 Event Handling Interactive Programming Suggested Reading Interaction: Events and Event Handling, Supplemental Text for CPSC 203 Distributed this term.
BDE tutorial By Deborah Nelson Duke University Under the direction of Professor Susan Rodger July 13, 2008.
Programming: Simple Control Structures Sec 46 Web Design.
February 25,  The BDE(Begin-During-End) event.  Worksheet – Exercise # 9 Instructions  2nd Period Test.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Tips & Techniques 6 Random Numbers and Random Motion Alice.
CS320n –Visual Programming Execution Control with If / Else and Boolean Functions (Slides 6-2-1) Thanks to Wanda Dann, Steve Cooper, and Susan Rodger for.
Starting Out with Alice: A Visual Introduction to Programming
Programming: Simple Control Structures
Programming: Simple Control Structures
While: Indefinite Loops
Introduction to Events
under the direction of Professor Susan Rodger
Restricting Events Creating Conditional Events in Alice By Henry Qin
Presentation transcript:

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 off of the key Choose “When a Key is Typed”, right click, choose “change to” Event is called BDE

BDE Begin- what is executed when key is pressed During – what happens while key is kept down o If key is released quickly During will not execute End – what executes when the key is released

Example While Key is Pressed BDE Tutorial 7-2 o Jump Jet moves up when space key is hit o Jump Jet goes forward if key is held down o Jump Jet moves down when space key is released Notice nothing is in world.animation

Mouse Movement Let mouse move object o Can move any object with a click and drag Let mouse move the camera o Moves the camera location with click and drag Let mouse move orient the camera o Rotates orientation with click and drag When Mouse is clicked on an object o Same thing happens if mouse is clicked briefly or long

When World is Running Will do method while world is active o Continuously runs When World Starts only executes when world starts While is like an infinite loop since world is always running Uses BDE

When Condition Becomes True Does method when condition is true Useful when object is moving and you want to see if it is close to another object Example: Have person fall when 10 meters from drop zone Choose “While something is true”, right click, choose change to

Example Events in Game See IslandRescue Demonstrates o How to show user instructions at beginning of game  When mouse is clicked on anything instructions disappear o While the world is running o While key is pressed o When condition is true

IslandRescue Events

IslandRescue Alice Methods

Random Number Number that is unpredictable o Uniformly distributed over range of numbers o Not possible to predict where next number will be Programs random numbers are used in o Security for web applications o Encryption for satellite transmissions o Gaming programs o Scientific simulations

Built-in Random Function Alice provides World-level built-in functions for generating random numbers In World object choose functions o Then random

Random Number Function Returns a floating point value o Fraction between 0 and 1 The integer only option o True: only integers are use o False: floating point numbers are used Change range of values by using the minimum and maximum parameters

Demo Penguin moves forward random distance Concepts illustrated o Range of values can be changed with minimum and maximum parameters o Integer only option

Random Penguin Moves

Random 3D Motion Penguin moved in only one direction In random 3D motion o Object moves to random location in 3D  Forward, backward, left and right, up and down o Ex: goldfish below swims in random motion, fish can move in any direction except backward

Six Possible Directions in 3D Movement in six directions are possible o forward, backward, left, right, up, down Eliminate backward because goldfish don’t swim backward To simplify code, we can use negative numbers o Positive numbers move goldfish to left and up o Negative numbers move goldfish right and down

Algorithm Only three move instructions are needed o up (will move down if random number is negative) o left (will move right if random number is negative) o forward (no backward motion) Two parameters (min, max) define the fish’s range of motion to look like swimming randomMotion Parameters: min, max Do together fish moves up a random distance fish moves left a random distance fish moves forward a random distance

Goldfish Alice Program

Demo Concepts illustrated o 3D random movement accomplished by three simultaneous move instructions o Minimum distance of move forward instruction is 0  Goldfish always moves forward never bacward o To call randomMotion method, min and max values are sent as arguments to parameters

Debugging With Print o Print statement allows you to  See what values variables are during program execution  Print a text message to identify where program is o Print statement is a diagnostic message o Drag print from bottom of Method Editor  Causes a menu to appear asking if you want to Print a text message Print an object or variable under expression

Output of Print Statement Output is sent to bottom of world when running Output of print statements

Homework Read chapter 6 sections Answer questions in handout Due one week after assigned with 1 week grace