Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition.

Similar presentations


Presentation on theme: "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition."— Presentation transcript:

1 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition by Tony Gaddis Chapter 11: Events

2 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-2 Chapter 11 Objectives To understand: –what an event is and how to specify what type of event can be used –how to specify a different method to be executed when the world starts –the components of a BDE event

3 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-3 Today’s Agenda 1.Responding to Events 2.Handling Key Press and Mouse Events 3.Using Events in Simulations and Games 4.Tips for Games and Simulations

4 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-4 Responding to Events Event –Action that take place while a world is playing –Alice worlds detect events and respond to them –For example: when a user clicks an object with a mouse…it’s an EVENT! when a user types a key on the keyboard…it’s an EVENT! 6.1

5 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-5 Alice Events Process of responding to an event is called handling the event Tile for an event MUST appear in the Events Editor When world is first created, the event when the world starts appears in the Events Editor 6.1

6 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-6 Alice Events Most event tiles require that additional arguments be specified The method that is executed in response to the event is called the event handler 6.1

7 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-7 Alice Events When the world starts While the world is running When a key is typed While a key is pressed When the mouse is clicked on something While the mouse is pressed on something While something is true When something becomes true When a variable changes Let the mouse move Let the arrow keys move let the mouse move the camera Let the mouse orient the camera 6.1

8 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-8 Specialized Events Some events from the previous list do not appear in the Events Editor –General event must first be created –Right-click and select change to Changes an event to a specialized event 6.1

9 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-9 Handling Key Press and Mouse Events Alice can detect when a key on the keyboard has been pressed Key Press Events (such as when a key is typed) –The event is triggered when the user types a key –Key that will trigger the event must be specified –any key is the placeholder until the “real” key is selected 6.2

10 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-10 Handling the While a key is pressed Event The event occurs as long as the user holds down a key This tile has four different placeholder slots: –any key –Begin –During –End Known as BDE event 6.2

11 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-11 BDE Event Begin –Specifies an action to take place at the beginning During –Specifies an action to take place during the event End –Specifies an action to take place at the end (when the event stops occurring) 6.2

12 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-12 Mouse Events / While the mouse is clicked… When the mouse is clicked on something Event is triggered when the mouse is clicked on an object in the world While the mouse is clicked on something Event occurs as long as the user holds down the mouse button while the pointer is positioned over an object 6.2

13 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-13 Using Events in Simulations and Games Programs can have numerous events –They respond to various user interactions and internal events –Note the various events that appear in Island Rescue 6.3

14 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-14 Tips for Games and Simulations Random Numbers –Function that returns a fractional number between 0 and 1 –Function can be added by altering the more editing tag minimum: specifies a minimum value for the random number maximum: specifies a minimum value for the random number integerOnly: if the value is true, the function returns only whole numbers 6.4

15 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-15 Tips for Games and Simulations Random Numbers –Function that returns a fractional number between 0 and 1 –Function can be added by altering the more editing tag minimum: specifies a minimum value for the random number maximum: specifies a minimum value for the random number integerOnly: if the value is true, the function returns only whole numbers 6.4

16 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-16 Tips for Games and Simulations Playing Audio –Several classes include sounds –Sounds appear in the class’s thumbnail in the gallery –An object’s properties’ tab also allows for sound to be imported and played 6.4

17 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-17 Tips for Games and Simulations Importing Sounds –.wav or.mp3 sounds can be imported to an object Recording Sounds –With a mic attached to your computer, sounds can be recorded to the computer and then imported 6.4

18 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-18 Tips for Games and Simulations Character Builders –The people class provides many characters to choose from –Tool for building own characters is also included hebuilder shebuilder 6.4

19 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-19 Tips for Games and Simulations Hebuilder/Shebuilder –User selects the head, body, and leg types –User selects skin color, eyes, and mouth –User selects hair style and color –User selects the clothing 6.4

20 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-20 Tips for Games and Simulations Hebuilder and Shebuilder have custom methods 6.4

21 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-21 Tips for Games and Simulations Debugging with print –Diagnostic messages are statements that are inserted into a program to display information that can be used in debugging a program that isn’t working properly –Addition of the print instruction causes a menu to appear –Menu shows all the objects that appear in the world 6.4

22 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-22 Tips for Games and Simulations Debugging with print –Diagnostic messages are statements that are inserted into a program to display information that can be used in debugging a program that isn’t working properly –Addition of the print instruction causes a menu to appear –Menu shows all the objects that appear in the world 6.4


Download ppt "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Alice: A Visual Introduction to Programming First Edition."

Similar presentations


Ads by Google