Introduction to Events

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

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.
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)
Interaction: Events and Event Handling
Methods Tutorial: Part One By Deborah Nelson Duke University Under the direction of Professor Susan Rodger June 9, 2008.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
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.
Creative Commons Attribution 3.0 creativecommons.org/licenses/by/3.0 Key Abstractions in Game Maker Foundations of Interactive Game Design Prof. Jim Whitehead.
Interaction: Events and Event Handling
Review For Test Chapter 4 & 5 Test is Wednesday, January 27th.
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.
CS329e – Elements of Visual Programming Implementing Programs Mike Scott (Slides 2-2)
An Introduction to Alice 3.1
Game Maker Terminology
Piñata Game: Keeping Score in Alice By Maggie Bashford Professor Susan Rodger Duke University July
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Events Programming with Alice and Java First Edition by John Lewis.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming Third Edition.
Interactive Programming Alice. Control of flow Control of flow -- how the sequence of actions in a program is controlled. What action happens first, what.
Beginning Animation. Storyboard An Invitation to Dinner 1.Marlin and Dory (two small fish) are swimming and talking. 2.A shark (Bruce) swims up behind.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Scratch Programming Cards
Under the direction of Susan Rodger
FOP: Multi-Screen Apps
Creating a UFO Rescue Game in Alice
Collision Theory and Logic
Forms Concepts Triggers Fired when Internal/External events occur
With and The Sims are a registered trademark of Electronic Arts, Inc
Programming & Scratch.
Scratch for Interactivity
An Introduction to Alice (Short Version)
Programming and File Management Part 2
Teaching Characters to Walk: Learning Methods, Part 1
Starting Out with Alice: A Visual Introduction to Programming
Collision Theory and Logic
Introduction to Event-Driven Programming
Comparing objects and changing color
Event-driven programming
Getting started in Alice
Putting Objects in Motion
Introduction to Triggers
1. Introduction to Visual Basic
Control Structures
Understand Windows Forms Applications and Console-based Applications
Lesson 1: Buttons and Events – 12/18
Creating a UFO Rescue Game in Alice
Chapter 16 – Programming your App’s Memory
Scratch for Interactivity
Programming – Touch Sensors
Event Driven Programming
Learning Java with Alice 3.0 Game Design Kathy Bierscheid
UNITY TEAM PROJECT TOPICS: [1]. Unity Collaborate
Making Procedural Methods
Alice: Beyond the Basics
Arrays
Interactive Programming
Using Functions
Princess & Dragon Part 3: A Knight Comes Riding In—Cameras & Events
Introduction to Object-Oriented Programming in Alice
Alice 2.2 Introduction.
Alice and Daisies: Positioning and Moving Objects in Alice
Lesson One: Objects in Alice: Positioning and Moving Them
Creating a Simple Game in Scratch
Interactive Programming
Presentation transcript:

Introduction to Events http://www.alice.org/resources/lessons/introduction-to-events/

Introduction to Events Interactivity Interactive programming means that the order of the program or outcome is not predetermined when we press play. In Alice there are two different ways to make an Alice world there are two different ways to make the outcome of the world depend on what happens during runtime: Include conditional statements that use randomized functions to determine the direction of a movement or outcome causing the program to perform differently every time it is executed - randomization functions Include user input such as mouse clicks or key presses that influence the way that the program executes - user input functions and events

Introduction to Events Events An event is something that happens. In Alice events can be constructed to happen based on one of the following major categories: Scene Activation/ Time - events driven by time elapsing Keyboard Inputs - events that are driven by user key presses Mouse - events that are driven by mouse clicks and interactions Position/ Orientation - events that are driven by the orientation of objects to each other such as objects colliding, being near or viewing each other.

Introduction to Events Event Listener The first things you need to do is to make your program aware that it needs to pay attention for something to happen. Until you do this the program will not bother to listen for a mouse click or a keypress or pay attention to whether an object came close to or hit another object. In Alice we call this setting up an event listener. These listeners run concurrently to the other processes in your program.

Introduction to Events Event Handler Once your program knows an event happened you still need to tell the computer what to do. We call these directions the event handler. In Alice 3 you can program the event handler directly into the event listener procedure but we recommend you write event handling methods. This will help you manage and organize your program.

Event Listener Types

Event Listener Types Scene Activation/ Time SceneActivationListener - This listener is setup to trigger in Alice when you press the Run button. By default this listener triggers myFirstMethod to begin your program when the Run button is clicked. TimeListener - This listener can be set up to fire off at different time increments by making use of the computers internal clock.

Event Listener Types Keyboard Events Keyboard events will listen for different keypresses and will be trigger when a key is pressed and can also support functions that will return and pass along which individual key was pressed to be used for any number of scene manipulations or object controls.

Event Listener Types Mouse Events The mouse event listeners track the movement of the mouse and the mouse click. These also work for built in trackpads. The listener will also check for information related to the mouse click like where the mouse carrot is located on the screen or what objects are under the mouse carrot when clicked.

Event Listener Types Position / Orientation Events Another very useful event listener constructed for you in Alice doesn’t check for external information instead it monitors and triggers based on events inside your world. These events are based on tracking the position and orientation of objects and triggering event you tell it to watch for happen such as two object colliding or when you can view and object.

Creating an Event

Creating an Event Initialize Event Listener To add events to you program first you navigate to a special procedural method in Alice called initializeEventListeners. You will see that one listener already exists that will call myFirstMethod. It is possible to add other procedures to this listener to have them run in sequence to myFirstMethod or within a do together to have them run concurrently.

Creating an Event Add Event Listener From the drop down select the type of listener you would like to add. As with other procedural methods some may require that you input default parameters to add them to your program.

Creating an Event Create Event Handler It is a good idea to create the directions you want to occur when the event is triggered in a separate method. Be sure to name it something that is easy for you to remember and for someone to understand. Separating the handler from the listener will make it easier for you to find and edit it later. It may also turn out that you want multiple events to call the same method.

Creating an Event Call Event Handler You need to then add the custom procedure into the event handler so that when the trigger happens it will run your directions. Some types of listeners will require further refinement to achieve the desired functionality. In this example any key press will cause the hare to say hello. We probably want to program a specific key to do that to allow other keys to do other things.

Modify Event Listeners There are a couple ways to refine the way that event listeners function. You may need to use these to limit the scope of the trigger, give more detail as to how the or when the handler should be initiated, or to pass required information to the handler. You may want to do this for things like: To know which key was pressed to determine which handler to trigger. To have mouse clicks only affect certain objects in the scene.

Creating an Event Add Details to Listener Just like in other built in procedural methods there are optional parameters under add detail for some of the different listeners. You can use these to affect things like: Set Of Visual - This will affect the object that can be affected by the event listener - object array Multiple Event Policy - This will affect how your program handles if multiple events of this type are triggered at the same - combine, ignore, or que Held Key Policy - What to do if the key is held down - multiple triggers or one trigger on press or release

Creating an Event Use Listener Functions Different listeners have special built in functions that will also allow you to use them to return more information about the event. These can then be used to inform the event handler in specific ways via conditionals in the event listener or by passing the information into the handler through a parameter. Some very useful ones are: isKey (???) - allows you build conditional methods for different keys to have them call different methods getModelAtMouseLocation - which can allow you to pass the selected model into the method as a parameter to have it respond differently to different objects

Built In Event Handlers

Built In Event Handlers Add Object Move For One of our built in fully developed event handlers is addObjectMoveFor. This will allow you to easily add keyboard interactions to a world. To add the default addObjectMoveFor select it from the drop down and then select the object you want the keypresses to manipulate from the nested menu. The handler for this event maps several keypresses to the basic move procedures for the object you selected: Up Arrow / W Keys - Move forward 1 Down Arrow / S Keys - Move Backward 1 Left Arrow / A Keys - Turn Left 1 Right Arrow / D Keys - Turn Right 1

Built In Event Handlers Add Default Model Manipulation Another fully implemented event handler is the default model manipulation. This is a global handler when added to your world will enable this manipulation for all objects in the world. The underlying system does the following: Listener - Get the object at the location of the mouse click Handler - While clicked move object to track mouse location

Tips and Tricks

Tips and Tricks First Person Camera The easiest way to set up an interactive world with a first person camera is to use the add object mover for and select camera as your object. This will make your camera move based on the keyboard inputs similar to many first person games. An added trick for a 3rd person camera is to add the main character and adjust the camera to a point over the shoulder and use the setVehicle property in the scene editor to vehicle the camera to the object. Then add the movement to the object and the camera will follow it around.

Tips and Tricks Using Say To Debug Since Alice renders your code in the virtual world we don’t a simple text based way to easily track if an event is triggering when you expect it to. A good trick is to use the say command for a character to visualize when something has happened.