Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week.

Similar presentations


Presentation on theme: "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week."— Presentation transcript:

1 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week is easier. 6-1

2 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Next week: No new lecture material. Monday lecture will review for optional part of final Work on final project. I would STRONGLY suggest starting on the final project THIS WEEK. –Finals weeks is stressful enough without adding completion of a project. 6-2

3 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Finals week REQUIRED project “quiz”. 20 point, short (30 minute). The best way to “study” for this is to just do the Alice programming. 11:30 Wed April 29th REQUIRED turn in final project by midnight April 29 th. OPTIONAL make up test – comprehensive, 90 points, given AFTER the project quiz during final exam time in Engr 103. You MUST tell me by Friday 24 th if you intend to take the optional part of the final. 6-3

4 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 14: Events

5 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-5 Responding to Events Event –User action that take place while a world is playing –interrupts regular execution and demands to be responded to NOW –Concurrent commands – “race condition” –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! –Events handling involves concurrency – doing two things simultaneously 6.1

6 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-6 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. This is how actions start normally. 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 - works for any object you click Let the arrow keys move let the mouse move the camera – nice, but may be too limiting Let the mouse orient the camera 6.1

8 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-8 Specialized Events General event must first be created –Right-click and select changes to Parameters change an event to a specialized event 6.1

9 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley try: Create following events Camera moves with mouse When we press “J” an object jumps. Can make anything the mouse clicks on jump 6-9

10 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-10 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

11 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-11 Handling the “While condition” Event This tile has three different placeholder slots: –Begin –During –End Known as BDE (begin, during, end) event 6.2

12 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Let’s do an event that has a loop You type “c” and the car moves towards the stop sign until it is close. Try it! Make sure moving forward will actually go towards the stop sign 6-12

13 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley world Events When the world starts Do: world.my first method While ( ( kangarooRobot distance to stopSign ) > 2 ) is true Begin: kangarooRobot think Time to start moving During: kangarooRobot move forward 0.5 meters End: kangarooRobot think Whoa 6-13

14 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-14 BDE Event Begin (one time) –Specifies an action to take place before beginning During (repeated) –Specifies an action to take place during the event (multiple times until condition becomes false) End (one time) –Specifies an action to take place when the event stops occurring 6.2

15 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-15 Mouse Events / When 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 6.2

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

17 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Events can contain do together do inorder 6-17

18 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-18 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

19 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-19 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

20 Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley 6-20 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

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


Download ppt "Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley This week: Whew!!! The last homework was tough! The homework for this week."

Similar presentations


Ads by Google