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.

Slides:



Advertisements
Similar presentations
Mike Scott University of Texas at Austin
Advertisements

Objects in Alice: Positioning and Moving Them By Jenna Hayes under the direction of Professor Susan Rodger Duke University July
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010 modified July 2011.
Alice Learning to program: Part Four Creating Sounds, Making Billboards, Fun with 3-D Text, New Events, and Rotating Objects by Ruthie Tucker and Jenna.
Princess & Dragon – Version 2 By Michael Hoyle under the direction of Professor Susan Rodger Duke University July 2012 Part 2: Using Methods.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
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.
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.
Lights Camera Action! Part 3: BDE Events By Deborah Nelson under the direction of Professor Susan Rodger Duke University July 2008.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University Feb. 24, 2007.
Alice Learning to program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke.
Alice Learning to program: Part Two by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2008.
Lights Camera Action! Part 2: Controlling Light in Alice By Elizabeth Liang under the direction of Professor Susan Rodger Duke University June 2009.
Getting Started With Alice By Ruthie Tucker under the direction of Prof. Susan Rodger Duke University, July
Making a Boat Racing Game in Alice By Jenna Hayes Under the direction of Professor Susan Rodger Duke University, July 2010.
Skater World: Part Two By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June
Programming with Alice Computing Institute for K-12 Teachers Summer 2011 Workshop.
Interaction: Events and Event Handling
3–D Helium Molecule Tutorial Alice Project Duke University Professor Susan H. Rodger Gaetjens Lezin June 2008.
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.
Alice 2.0 Introductory Concepts and Techniques Project 1 Exploring Alice and Object-Oriented Programming.
Poses Tutorial Alex Boldt Under the direction of Professor Susan Rodger Duke University July 2015.
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.
CompSci 4 Fall 2010 Classwork 2 – Princess and Dragon World By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Princess & Dragon Part 1: Objects in an Alice World By Elizabeth Liang under the direction of Professor Susan Rodger Duke University May 2010.
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,
Game Maker – Getting Started What is Game Maker?.
Visual Basic CDA College Limassol Campus Lecture:Pelekanou Olga Semester C Week - 1.
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,
Alice Learning to program: Part Two Writing Your Own Methods by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
The Essentials of Alice Mrs. Jayne Slease SBMS CTE Computer Science and Animation Credit to Duke Students under the direction of Professor Susan Rodger.
Simple Collision Detection By David Yan Under the direction of Professor Susan Rodger and Chari Distler Duke University, June 2015.
Creating a 3D Interactive Story Prof. Susan Rodger Duke University July 19, 2007.
Changing Camera Views! Part 1: Set Point of View to By Bella Onwumbiko under the direction of Professor Susan Rodger Duke University July 2013 Updates.
Learning to Program: Part 1 Scene Setup and Starting Animation by Ruthie Tucker and Jenna Hayes Under the direction of Professor Susan Rodger Duke University,
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.
An Introduction to Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University, June 2009 Updated June 2014 by Ellen Yuan.
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.
Repetition everywhere – comparing while in a method and as an event Susan Rodger Duke University July 2010.
Illuminating Computer Science CCIT 4-6Sep
PowerPoint Basics Tutorial 2: A Slide Show In this tutorial you’re going to create a presentation from scratch. You will have to keep this presentation.
Headshots in Alice Duke University Professor Susan H. Rodger Gaetjens Lezin July 2008.
Lesson 8C Animation and Events. Step 3: Animation Drag it into the method and have him say “let her go!” Click on the knight in the object tree and scroll.
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:
The Essentials of Alice By Jenna Hayes under the direction of Professor Susan Rodger Duke University May 2009.
An Introduction to Programming Using Alice 2.2, Second Edition Chapter 7 Recursive Algorithms.
An Introduction to Alice (Short Version)
Getting started in Alice
The Alice Interface.
Introduction to Events
Skater World: Part Three
Objects in Alice: Positioning and Moving Them
An Introduction to Alice
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
Getting Started With Alice
Professor Susan Rodger
Headshots in Alice Duke University Professor Susan H. Rodger
Alice and Daisies: Positioning and Moving Objects in Alice
Lesson One: Objects in Alice: Positioning and Moving Them
Professor Susan Rodger
Presentation transcript:

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. Move the ballerinas apart from each other and turn them to face the camera. Exit Scene Editor mode.

Continuing… Create a world-level method called bothSpin to make both ballerinas spin at once. You’ll need a do together tile Turn each ballerina left 1 revolution

Setting up a recognized event Drag the tile for bothSpin to the event area and replace world.my first method in the When the world starts tile. We no longer need world.my first method; throw it away. Play the world and you should see both ballerinas spin together. Save your world; name it bothBallerinas1

Now let’s experiment with a few more events

Save your world as blueBallerinas2 Click the create new event button and then click When the world starts. Change the form of the newly added event. –Right-click the newly added event tile. –Select change to then click While the world is running.

Events interacting Play the world Note two behaviors: –First, the pink ballerina continues to spin while the world is running. –Second, when the world starts, she spins more quickly. Play the world a couple of times until you see this.

Events interacting, cont’d Why does she spin more quickly when the world starts? This is a side effect of two event handlers running at the same time. The default event handler causes pinkBallerina to spin one time at one revolution per second. Combined with the spin from the new event (also one rev./sec.), she spins twice as fast for one revolution.

Side effects Change the direction of the spin to the right in the while the world is running event tile. Play the world

Side effects Change the direction of the spin to the right in the while the world is running event tile. Play the world Now what happens?

Why?

Side effects pinkBallerina does not spin at all this time The two method calls triggered by the two events cancel out each other. After the first method stops, she spins to her right. Two events or methods that overlap might sometimes cause unintended results known as side effects.

The BDE event Begin, during, and end event Makes use of up to three event handlers

Begin When the trigger condition first becomes true call the Begin method once.

During While the trigger condition continues to hold, continue to call the During method

End When the trigger condition becomes no longer true, call the End method.

When a key is typed event The event trigger is the press of a key The event handler can be almost anything that can be coded in Alice.

When a key is typed event Add a “when a key is typed” event to your ballerinas world. Click on “any key” in the event tile Select letters from the menu and then B Drag a blueBallerina turn method tile from the Details area and drop in on “Nothing”. Select right and 1 revolution.

When a key is typed event Play the world. Try the b key a few times. Note that if you hold b down blueBallerina will not continue to spin. When a key is typed will call the event handler only once per key press.

While a key is pressed event You can change the form of the When a key is typed event to make an event handler run continuously as long as the triggering key is held down.

While a key is pressed event Right-click the When B is pressed tile’s blue background. Select change to then While a key is pressed. Drag and drop a blueBallerina turn tile into place after “During” (right, 1 revolution).

While a key is pressed event Play the world. Note that blueBallerina continues to turn while the b key is held down. She stops when the key is released, even if in mid-turn.

When the mouse is clicked on anything event In your ballerinas world, click the create a new event button and select when the mouse is clicked on something. Let’s make blueBallerina roll one revolution whenever the mouse is clicked on her. Select blueBallerina and the entire blueBallerina as the target object. Drag the blueBallerina roll tile from the methods tab and drop it to replace “Nothing” in the event tile (right, 1 rev.).

More mouse events Changing When the mouse is clicked on something to While the mouse is pressed on something by right clicking on the event tile. Let the mouse move is a little beyond us at the moment. We need to know about Lists first.

Using events for something more practical

Building a flying machine Remember the program development cycle: design, code, test, debug?

Initial specifications Initial specifications for our world: 1.It should contain a flying machine in a somewhat realistic environment. 2.The flying machine should be able to fly throughout the world. 3.There should be user controls to turn the object up, down, left, and right while the flying machine is in motion 4.The user should be able to find the flying machine if it moves off camera.

Refining specifications Beginning with #1: It should contain a flying machine in a somewhat realistic environment. First, let’s find objects that can serve as a flying machine. How about a seaplane with a water template? We also need some realism.

Revised specification #1 1.Create a water world with a seaplane in it 1.Select the water template. 2.Add a seaplane to the world. 3.Add a few more items – perhaps an island or two, and a sailboat.

Refining specification #2 2. The flying machine should be able to fly throughout the world. –This means it needs to be able to move along the x, y, and z axes –Let’s not worry about moving backward. –Planes don’t move backward while in the air. –We need to be able to turn left, right, up, down –We also need to be able to go forward.

Refining specification #2 2. The flying machine should be able to fly throughout the world. –How about if we just make the plane move forward continuously so that the user simply needs to drive it? –Let’s make the following refinement: –Create an event – while the world is running do: seaplane move forward one meter

Refining specification #2 2. Create an event – while the world is running do: seaplane move forward one meter –The specifications don’t for the user to be able to modify the seaplane’s speed, let’s assume the speed to be constant.

Revised specifications 1.Create a water world with a seaplane in it 1.Select the water template. 2.Add a seaplane to the world. 3.Add a few more items – perhaps an island or two, and a sailboat. 2.Create an event – while the world is running do: seaplane move forward one meter

Refining specification #3 3. There should be controls to turn the object up, down, left, and right while the flying machine is in motion. –Left and right are easy –Is turning up, turning the object backward or forward? –We also need to decide by how much to turn when a turn is requested.

Refining specification #3 3. Create four turn control events: –When the left arrow key is pressed, turn left 1/8 revolution –When the right arrow key is pressed, turn right 1/8 revolution –When the up arrow key is pressed, turn backward 1/8 revolution. –When the down arrow key is pressed, turn forward 1/8 revolution.

Revised specifications 1.Create a water world with a seaplane in it 1.Select the water template. 2.Add a seaplane to the world. 3.Add a few more items – perhaps an island or two, and a sailboat. 2.Create an event – while the world is running do: seaplane move forward one meter 3.Create four turn control events: 1.When the left arrow key is pressed, turn left 1/8 revolution 2.When the right arrow key is pressed, turn right 1/8 revolution 3.When the up arrow key is pressed, turn backward 1/8 revolution. 4.When the down arrow key is pressed, turn forward 1/8 revolution.

Revising specification #4 4. The user should be able to find the flying machine if it moves off camera. –Several ways to do this. –A simple way is to point the camera at the seaplane. –Should be easy to do; let’s use the spacebar.

Revising specification #4 4. Create an event: When the spacebar is pressed, point the camera at the seaplane.

Revised specifications 1.Create a water world with a seaplane in it 1.Select the water template. 2.Add a seaplane to the world. 3.Add a few more items – perhaps an island or two, and a sailboat. 2.Create an event – while the world is running do: seaplane move forward one meter 3.Create four turn control events: 1.When the left arrow key is pressed, turn left 1/8 revolution 2.When the right arrow key is pressed, turn right 1/8 revolution 3.When the up arrow key is pressed, turn backward 1/8 revolution. 4.When the down arrow key is pressed, turn forward 1/8 revolution. 4.Create an event: When the spacebar is pressed, point the camera at the seaplane. Let’s code this specification. Test and debug after each step