03-01-wall-bounce.js 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. Ninjas will use the GDP's moveX function to move a ball and then write the if
  3. statement that bounces the ball if it touches the wall.
  4. New Vocabulary and Concepts
  5. * Boolean Logic
  6. * GDP moveX() function
  7. * If statements
  8. Reinforced Vocabulary and Concepts
  9. * Functions and Parameters
  10. * Object Names
  11. Sensei Notes
  12. * This is the first introduction to Boolean logic.
  13. * Make sure the Ninja understands that true is like yes or on, and that false is
  14. like no or off.
  15. Solution Steps
  16. 1 Make sure the Ninja opens the correct scene.
  17. 2 To simplify this activity, some of the code is hidden from the Ninja. Make sure
  18. the focus is on the logic of why and when code is executing and not how it is
  19. happening.
  20. 3 Make sure the Ninja is in the scene's Update Every Frame event. The name of the
  21. object is circle.
  22. moveX(circle);
  23. 4 Relate the moveX function to the spin function. Ask the Ninja to explain the
  24. similarities and differences between the two.
  25. 5 The ball should not bounce, but the text should change from false to true.
  26. 6 Help the Ninja type the if statement, making sure that the brackets and
  27. parentheses are in the correct places. This is a lot more code than in previous
  28. games but introducing Boolean logic will allow for more interactive games.
  29. Explain that moveX is a GDP function and isTouchingWall is a function that this
  30. circle knows.
  31. if(circle.isTouchingWall()) {
  32. }
  33. 7 Explain the different parts of an if statement. Walk through the example of
  34. looking outside and grabbing an umbrella if it is raining . Ask the Ninja to
  35. come up with another real-world situation and write a code version of it together.
  36. 8 Help the Ninja place the new line of code inside the if statement. Explain
  37. again that we are asking the circle to perform its function named bounce.
  38. if(circle.isTouchingWall()) {
  39. circle.bounce();
  40. }
  41. 9 The circle should bounce every time it hits the wall.
  42. 10 Before the Ninja submits the scene, make sure they have a basic understanding
  43. of if statements and Booleans.
  44. */
  45. moveX(circle);
  46. if(circle.isTouchingWall()) {
  47. circle.bounce();
  48. }
  49. /**
  50. Sensei Stops
  51. 5 Tell a Sensei why your circle doesn't bounce. What does it mean when
  52. circle.isTouchingWall is false? What about when it is true?
  53. The Ninja should recognize that we are just asking the ball to move. We have not
  54. asked it to bounce yet, but it is reporting when it is touching the wall. Ask the
  55. Ninja to describe what the circle looks like when it says false and compare it to
  56. when it says true.
  57. 10 Act out what is happening in the scene with a Sensei. You are the circle, so
  58. say out loud what you are thinking! You must always move. How often do you ask
  59. yourself if you are touching the wall? Once? Every step? What happens if you
  60. touch the wall?
  61. Help the Ninja act out this activity. You can use the real walls in the Dojo or
  62. come up with other bounds. The Ninja should understand that the circle is
  63. constantly asking itself if it is touching a wall.
  64. */