03-01-wall-bounce.js 2.9 KB

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