04-03-PY-air-hockey.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. Ninjas use conditionals and if statements to keep score and move an object
  3. when a key is pressed.
  4. Reinforced Vocabulary and Concepts
  5. * Boolean Logic
  6. * Comparison Operators
  7. * Functions and Parameters
  8. * GDP isKeyPressed() Function
  9. * GDP Keys Object
  10. * GDP moveY() Function
  11. * GPD .x() and .y() Functions
  12. * if() Statements
  13. * Object Names
  14. * Pseudocode
  15. Decomposition
  16. * left paddle is controlled with keys (coconut chaos)
  17. * right paddle is controlled with mouse (laser chase)
  18. * left side gets a point if ball touches right wall (wall bounce)
  19. * right side gets a point if ball touches left wall
  20. * ball resets to middle after every point (hungry ninja)
  21. * points are incremented and updated (hungry ninja)
  22. Sensei Notes
  23. * This Prove Yourself requires the Ninja use every coding concept they have
  24. learned in the second half of the White Belt.
  25. * No code is provided in the manual, but guiding comments are in the scene.
  26. * The Ninja must reference the games they have created for hints.
  27. * The game is divided into three sections that require two if statements each.
  28. * The left paddle moves using the keyboard and the right paddle moves using the
  29. mouse.
  30. * Encourage the Ninja to take their time and thoroughly test at each step.
  31. */
  32. //*************Scene - Update Every Frame********************//
  33. /**
  34. * leftPaddle
  35. * if the up arrow is pressed, move the leftPaddle up
  36. * if the down arrow is pressed, move the leftPaddle down
  37. **/
  38. if ( isKeyPressed(Keys.upArrow) ) {
  39. moveY(leftPaddle, -300);
  40. }
  41. if ( isKeyPressed(Keys.downArrow) ) {
  42. moveY(leftPaddle, 300);
  43. }
  44. /**
  45. * rightPaddle
  46. * if the rightPaddle is below the mouse, move the rightPaddle up
  47. * if the rightPaddle is above the mouse, move the rightPaddle down
  48. **/
  49. if ( rightPaddle.y() > getMouseY() ) {
  50. moveY(rightPaddle, -300);
  51. }
  52. if ( rightPaddle.y() < getMouseY() ) {
  53. moveY(rightPaddle, 300);
  54. }
  55. /**
  56. * walls
  57. * if the ball touches right wall, give player 1 a point and reset the ball
  58. * if the ball touches left wall, give player 2 a point and reset the ball
  59. **/
  60. if ( ball.isTouchingRightWall() ) {
  61. leftPaddle.score += 1;
  62. leftScoreLabel.text(leftPaddle.score);
  63. ball.x(400);
  64. ball.y(300);
  65. }
  66. if ( ball.isTouchingLeftWall() ) {
  67. rightPaddle.score += 1;
  68. rightScoreLabel.text(rightPaddle.score);
  69. ball.x(400);
  70. ball.y(300);
  71. }
  72. /**
  73. Sensei Stops
  74. 5 Explain to a Sensei how you used and changed code from Laser Chase and
  75. Coconut Chaos to add paddle movement to this game.
  76. All good programmers know how to repurpose code in different situations. The
  77. Ninja should be able to explain the parts of the code that they changed and the
  78. parts of the code that they kept the same.
  79. 10 Explain to a Sensei how you used and changed code from Hungry Hungry Ninja to
  80. add scoring. How did you teleport the ball?
  81. The Ninja should be able to explain the parts of the code that they change and
  82. the parts of the code that they kept the same.
  83. 15 Tell a Sensei three things that you learned in White Belt. What are three
  84. things you still want to learn?
  85. Let the Ninja reflect on what they learned in White Belt, Ask what their
  86. favorite game was. Have them articulate what they still want to learn.
  87. */