1 / 47

PIIT Computer Science Summer Camp - Alice

PIIT Computer Science Summer Camp - Alice. July 11, 2012 Brenda Parker Computer Science Department MTSU. Welcome. Review?? Demonstrations?. Today’s Topics. Event Programming Event Event handler Interactive Programming Billboards Games. Event-Driven Programming.

Download Presentation

PIIT Computer Science Summer Camp - Alice

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. PIIT Computer Science Summer Camp - Alice July 11, 2012 Brenda Parker Computer Science Department MTSU

  2. Welcome • Review?? • Demonstrations? Brenda Parker - Alice Workshop

  3. Today’s Topics • Event Programming • Event • Event handler • Interactive Programming • Billboards • Games Brenda Parker - Alice Workshop

  4. Event-Driven Programming Event – special condition that occurs while a program is running (event trigger) Event Handler – method that executes when an event has occurred. Brenda Parker - Alice Workshop

  5. Sample Events • The user presses the left mouse button • The user presses a key on the keyboard • The user presses the space bar on the keyboard Brenda Parker - Alice Workshop

  6. Event Handlers We must create “event handlers” – we must create methods to tell the computer what to do if an event occurs! What do we do if the user presses the spacebar? Brenda Parker - Alice Workshop

  7. Events and Event Handlers use Interactive Programming • Interactive • User participates while the video is playing • When the user clicks mouse or presses a key, an event occurs and must be handled by a given method Brenda Parker - Alice Workshop

  8. Event Programming • Click “create new event” in the Events Editor Window • Choose desired event • Create method to handle the event • Play and save video Brenda Parker - Alice Workshop

  9. Simple Example of Event and Event Handlers Suppose that we wish to create a video which contains a fish swimming in the ocean by an island. The fish jumps out of the water when the user presses the space bar. EVENT: user presses the space bar EVENT HANDLER: a method indicating what to do when the space bar is pressed Brenda Parker - Alice Workshop

  10. Fish Example • Open Alice and create the original scene. Brenda Parker - Alice Workshop

  11. Fish Example 2. Create the code to allow the fish to swim (forever). Brenda Parker - Alice Workshop

  12. Fish Example 3. Create a world method to tell the fish to jump out of the water. • Select the world object • Choose “create new method” • Name the method (jumpOut) • Write the method Brenda Parker - Alice Workshop

  13. Fish Example Brenda Parker - Alice Workshop

  14. Fish Example 4. Create the Event a. In the Events Area, click on “create new event” b. Click on “when key is typed” Brenda Parker - Alice Workshop

  15. Fish Example c. Replace “any key” with “Space” d. Replace “do nothing” with “jumpOut” Brenda Parker - Alice Workshop

  16. Fish Example 5. Play the video. Brenda Parker - Alice Workshop

  17. Practice X Choose from any one of the following to create “interactive” programming. Save the file! • Create a boat scene in which the boat moves to the right when the right arrow key is pressed and moves to the left when the left arrow key is pressed. • Create a scene with 2 penguins (Sam and Joe). When the user presses “J” on the keyboard, Joe jumps or flaps his wings. When the user presses “S”, Sam jumps and flaps his wings. • Create your own scene which allows user input of some type. Brenda Parker - Alice Workshop

  18. User Input If a program (video) requires interactive input, the user should be given instructions on what to input. Example: In the “fishJump.a2w” video, the user should be told to press the space bar to make the fish jump.

  19. User Input The user should be given a set of instructions to read when the world first starts. These instructions can be displayed in Alice with a “billboard” A billboard is a picture file that is added to an Alice world.

  20. Displaying User Instructions 1. Use Microsoft Word to create the instructions. 2. Use Copy and Paste to place the image into Microsoft Paintbrush or Paint and save the file as a picture (jpg or gif). Brenda Parker - Alice Workshop

  21. Practice XICreate Instructions • Open Word • Type in instructions • Format instructions • Copy instructions • Open Paint • Paste instructions • Save your picture as jump.jpg Brenda Parker - Alice Workshop

  22. Instructions created in Microsoft Word

  23. Displaying Game Instructions 3. In Alice, FileMake Billboardselect your instructions picture. 4. Position your billboard in your Alice world so that it is displayed appropriately. 5. Make all other objects invisible (propertiesis showing=false) Brenda Parker - Alice Workshop

  24. Billboard is visible!

  25. Practice XII • Use Microsoft Word to create instructions for your Practice X program. • Copy the instructions. (Control + C) • Open Microsoft Paint • Paste the instructions (Control+P) • Save your instructions (instructions.jpg) Brenda Parker - Alice Workshop

  26. We now have 2 Events • If user presses the space bar, our program will execute the jumpOut method • What do we do if the user presses a 1?

  27. Events

  28. Summary • We have events (user presses space bar and user types a 1) • We have event handlers. • We have a Billboard to display instruction • Now, let’s put it all together! Brenda Parker - Alice Workshop

  29. Putting it All Together When the World starts: • Make everything invisible except the billboard (instructions). • When the user presses a 1, the world.myfirstmethod should begin execution. • The world.myfirstmethod should make the billboard invisible and everything else should be visible.

  30. Practice XIII Choose 1 of the following: • Add instructions for your Practice XI program. Make sure that your billboard “is showing=true” but that it changes to “is showing=false” when the user presses a particular key. • Page AL 224, Three Dancing Penguins • Page AL 226, Simple Flight Simulator

  31. Practice VI Test • What is the difference between “interactive” and “passive” animations? • Interactive animations are created in Alice creating a/an ___________. 3. _________________ run __________________ when certain things happen like a key is pressed or the mouse is clicked. on an object. 4. Show the specific instruction that should be used for each of the following scenarios. a. We wish to move a penguin when a number is typed on the keyboard b. We wish to move a penguin when the mouse is click on the penguin c. We wish to allow the mouse to move the penguin d. We wish the arrow keys to move the penguin. e. Allow the mouse to control the camera location 5. If we want a custom method called “jump” to be executed each time the mouse is clicked on a penguin, what must we do first? Brenda Parker - Alice Workshop

  32. Review of Variables A variable is a name for a storage location in the computer’s memory. In Algebra: x=21 (x is called a variable) In computer science, a variable is a name for a location in memory.

  33. Variables • In a programming language, when working with variables: • You should create “good” variable names (names should be meaningful • use the camelCase naming convention • camelCase means that multi-word names begin with a lowercase letter and following words are in uppercase • Example: timesToJump,yourAge,yourFirstName

  34. Variables • You should specify the type: number, object, string, Boolean (true or false) • You should give variables a beginning value • Example: timesToJump (number), yourFirstName(string)

  35. Creating and using a variable in Alice Example 1: Let’s create a world with a bunny. Your program should have a variable called numberHops, set it as a number and give it the value 5. Then, create a Alice file that will allow the bunny to jump 5 times using the variable numberJumps

  36. Using Variables • Click on “create new variable” • Name the variable and give a value • Bring in loop structureexpressionsvariable name • Add code to the loop

  37. Using a Variable

  38. Creating and using a variable in Alice Example 2: Same problem. However, this time let’s ask the user how many times the bunny should jump.

  39. Practice XIII Choose one of the following: • Create an Alice scene which will compute and display the average of two test grades. (Alice should ask for data from the user) • Create an Alice scene which computes and displays amount of pay (hours worked * pay rate) • Create an Alice scene which asks for your name and then prints a welcome message that includes your name. • Create an Alice scene of your own but you must use variables!

  40. Class Demonstrations Volunteers???? Brenda Parker - Alice Workshop

  41. Manipulating the Camera • Create world methods • Scene1 • Scene2 • Add Objects • Click “more controls” • Move camera and drop dummy at camera for each scene • At the beginning of each scene, place “camera set point of view to ….” (dummy1, dummy2, etc. Brenda Parker - Alice Workshop

  42. User Input Example – Ask user to input a name • Create a new variable – name, string • Drag variable to editor window and set valueexpressionname • Drag world function “ask user for a string” and place on top of “name”other”What is your name?” Brenda Parker - Alice Workshop

  43. Using Random Numbers Example: Create a world with Alice. Alice should ask the user for a number between 1 and 10. The user will get three choices to guess the number.

  44. Using Lists Suppose we wish to work with several similar objects. (7 penguins, for example) We should use a programming construct called “list” or “array”.

  45. To create a list of 7 penguins • Create a new variable • Select Object • Choose make a List • Add items to the list.

More Related