04-01-cocunut-chaos.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /**
  2. Ninjas use conditionals and if statements to move an object when a key is pressed.
  3. New Vocabulary and Concepts
  4. * GDP isKeyPressed() function
  5. * GDP Keys Object
  6. Reinforced Vocabulary and Concepts
  7. * Boolean Logic
  8. * Comparison Operators
  9. * Functions and Parameters
  10. * GPD moveX() Function
  11. * if() Statements
  12. * Object Names
  13. * Pseudocode
  14. Sensei Notes
  15. * This game takes the concepts learned in 03-02 and 03-03 and applies them to
  16. keyboard inputs.
  17. * This activity introduces isKeyPressed() and the Keys object.
  18. * The steps in section 4 are denser than the previous 3 sections. If a Ninja is
  19. getting overwhelmed with how much they need to do at each step, help them break
  20. the step down into smaller and more manageable pieces.
  21. Solution Steps
  22. 1 Make sure the Ninja opens the correct scene.
  23. 2 The Ninja should play the game to see what functionality needs to be added.
  24. They should write down the provided pseudocode so they can reference it when they
  25. write their own.
  26. 3 The Ninja should attempt to write their own pseudocode and then compare it to
  27. the provided pseudocode.
  28. 4 Make sure the Ninja has correct pseudocode before they code in the GDP.
  29. if(){
  30. }
  31. 5 Make sure the Ninja places the function call inside the if statement's
  32. parentheses. Explain that the GDP uses the isKeyPressed() function to communicate
  33. when a key is being pressed by the user. Explain that the Keys object is an easy
  34. way to ask the isKeyPressed function about a specific key on the keyboard.
  35. if(isKeyPressed(Keys.rightArrow)){
  36. }
  37. 6 Make sure the Ninja types the new line of code inside the body of the if
  38. statement. The name of the GDP object is ninjas and 300 is a good starting move
  39. speed.
  40. if(isKeyPressed(Keys.rightArrow)){
  41. moveX(ninjas, 300);
  42. }
  43. 7 Have the Ninja play the game to verify that their code is working. They can
  44. change the speed to whatever they think is best.
  45. 8 Make sure the Ninja types the new if statement after the first one.
  46. if(){
  47. }
  48. 9 Make sure the Ninja places the function call inside the if statement's
  49. parentheses.
  50. if(isKeyPressed(Keys.leftArrow)){
  51. }
  52. 10 Make sure the Ninja types the new line of code inside the body of the if
  53. statement. If they changed the speed of the first if statement, make sure they
  54. have the negative version of their speed in this if statement.
  55. if(isKeyPressed(Keys.leftArrow)){
  56. moveX(ninjas, -300);
  57. }
  58. 11 Let the Ninja play the game that they built. Encourage them to playtest it to
  59. find the best move speed values.
  60. 12 Before the Ninja submits the game, verify that their code is correct.
  61. */
  62. if(isKeyPressed(Keys.rightArrow)){
  63. moveX(ninjas, 300);
  64. }
  65. if(isKeyPressed(Keys.leftArrow)){
  66. moveX(ninjas, -300);
  67. }
  68. /**
  69. Sensei Stops
  70. 5 Tell a Sensei if isKeyPressed(Keys.rightArrow) returns true of false when the
  71. right arrow key is pressed. How about if the space bar is pressed?
  72. The Ninja should be able to understand that the function will return true if and
  73. only if the right arrow key is being pressed. Make sure they understand that the
  74. body of the if statement will run only if the condition evaluates to true.
  75. 10 Tell a Sensei how you used your pseudocode to understand the GDP code. Why did
  76. we use a negative speed in the second if statement?
  77. The Ninja should be able to connect the pseudocode they wrote to the code they
  78. typed. If they do not understand, then walk through each of the pseudocode and
  79. how it translates to JavaScript code. The Ninja should be able to state that a
  80. negative x speed moves an object to the left.
  81. */