1 / 19

Events

Events. Chapter 7 Part 2. While a Key is Pressed Event. Specialized event Choose “When a Key is Typed”, right click, choose “change to” An event occurs when you press a key and continues until you take your finger off of the key Event is called BDE. BDE.

faye
Download Presentation

Events

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. Events Chapter 7 Part 2

  2. While a Key is Pressed Event • Specialized event • Choose “When a Key is Typed”, right click, choose “change to” • An event occurs when you press a key and continues until you take your finger off of the key • Event is called BDE

  3. BDE • Begin- what is executed when key is pressed • During – what happens while key is kept down • If key is released quickly During will not execute • End – what executes when you key is released

  4. Example While Key is Pressed BDE • Tutorial 7-2 • Jump Jet moves up when space key is hit • Jump Jet goes forward if key is held down • Jump Jet moves down when space key is released Notice nothing is in world.animation

  5. Mouse Movement • Let mouse move object • Can move any object with a click and drag • Let mouse move the camera • Moves the camera location with click and drag • Let mouse move orient the camera • Rotates orientation with click and drag • When Mouse is clicked on an object • Occurs when mouse is quickly clicked over object

  6. When World is Running • Will do method while world is active • Continuously runs • When World Starts only starts when world starts • Uses BDE

  7. When Condition Becomes True • Does method when condition is true • Good to do something when object is moving and you want to see if it is close to another object • Choose “While something is true”, right click, choose change to • Example: Have person fall when 10 meters from drop zone

  8. Example Events in Game • See IslandRescue • Demonstrates • How to show user instructions with when mouse is clicked on anything • While the world is running • While key is pressed • When condition is true

  9. Random Number • Unpredictable number • Uniformly distributed over range of numbers • Not possible to predict where next number will be • Used in certain kinds of computer programs • Security for web applications • Encryption for satellite transmissions • Gaming programs • Scientific simulations

  10. Built-in Random Function • Alice provides World-level built-in functions for generating random numbers • In World object choose functions • Then random

  11. Random Number Function • Returns a floating point value • Fraction between 0 and 1 • Different range of values can be obtained by using the minimumand maximum parameters • The integer only option • True allows selection of whole numbers • False floating point numbers are used

  12. Demo • Penguin moves forward random distance • Ch06Lec3PenguinRandomMoves.a2w • Concepts illustrated • Range of values can be changed with minimumand maximum parameters • Integer only option

  13. Random 3D Motion • Penguin moved in only one direction • Random 3D motion • Object moves to random location in 3D • Ex: goldfish below swims in random motion, fish can move in any direction

  14. Six Possible Directions • Movement in six directions are possible • forward, backward, left, right, up, down • Eliminate backward because goldfish does not swim backward • To simplify code, we can use negative numbers • To move goldfish right and down

  15. Storyboard • Only three move instructions are needed • up (will move down if random number is negative) • left (will move right if random number is negative) • forward (no backward motion) • Two parameters (min, max) will be used to restrict motion of fish to nearby location -- to look like swimming randomMotion Parameters:min, max Do together fish moves up a random number distance fish moves left a random number distance fish moves forward a random number distance

  16. Demo • Ch06Lec3GoldfishRandom3DMotion • Concepts illustrated • 3D random movement accomplished by three simultaneous move instructions • Minimum distance of move forward instruction is 0 • Goldfish always moves forward • To call randomMotion method, min and max values are sent as arguments to parameters

  17. Debugging With Print • Print statement allows you to • See what values variables are during program execution • Print a text message to identify where program is • Print statement is a diagnostic message • Drag print from bottom of Method Editor • Causes a menu to appear asking if you want to • Print a text message • Print an object or variable under expression

  18. Output of Print Statement • Output is sent to text console at bottom of world when running Output of print statements

  19. Homework • Read chapter 6 sections 2 - 4 • Answer questions in handout • Do lab assignments after handing in answered questions • Due one week after assigned with 1 week grace

More Related