/** Ninjas use conditionals and if statements to move an object when a key is pressed. New Vocabulary and Concepts * GDP isKeyPressed() function * GDP Keys Object Reinforced Vocabulary and Concepts * Boolean Logic * Comparison Operators * Functions and Parameters * GPD moveX() Function * if() Statements * Object Names * Pseudocode Sensei Notes * This game takes the concepts learned in 03-02 and 03-03 and applies them to keyboard inputs. * This activity introduces isKeyPressed() and the Keys object. * The steps in section 4 are denser than the previous 3 sections. If a Ninja is getting overwhelmed with how much they need to do at each step, help them break the step down into smaller and more manageable pieces. Solution Steps 1 Make sure the Ninja opens the correct scene. 2 The Ninja should play the game to see what functionality needs to be added. They should write down the provided pseudocode so they can reference it when they write their own. 3 The Ninja should attempt to write their own pseudocode and then compare it to the provided pseudocode. 4 Make sure the Ninja has correct pseudocode before they code in the GDP. if(){ } 5 Make sure the Ninja places the function call inside the if statement's parentheses. Explain that the GDP uses the isKeyPressed() function to communicate when a key is being pressed by the user. Explain that the Keys object is an easy way to ask the isKeyPressed function about a specific key on the keyboard. if(isKeyPressed(Keys.rightArrow)){ } 6 Make sure the Ninja types the new line of code inside the body of the if statement. The name of the GDP object is ninjas and 300 is a good starting move speed. if(isKeyPressed(Keys.rightArrow)){ moveX(ninjas, 300); } 7 Have the Ninja play the game to verify that their code is working. They can change the speed to whatever they think is best. 8 Make sure the Ninja types the new if statement after the first one. if(){ } 9 Make sure the Ninja places the function call inside the if statement's parentheses. if(isKeyPressed(Keys.leftArrow)){ } 10 Make sure the Ninja types the new line of code inside the body of the if statement. If they changed the speed of the first if statement, make sure they have the negative version of their speed in this if statement. if(isKeyPressed(Keys.leftArrow)){ moveX(ninjas, -300); } 11 Let the Ninja play the game that they built. Encourage them to playtest it to find the best move speed values. 12 Before the Ninja submits the game, verify that their code is correct. */ if(isKeyPressed(Keys.rightArrow)){ moveX(ninjas, 300); } if(isKeyPressed(Keys.leftArrow)){ moveX(ninjas, -300); } /** Sensei Stops 5 Tell a Sensei if isKeyPressed(Keys.rightArrow) returns true of false when the right arrow key is pressed. How about if the space bar is pressed? The Ninja should be able to understand that the function will return true if and only if the right arrow key is being pressed. Make sure they understand that the body of the if statement will run only if the condition evaluates to true. 10 Tell a Sensei how you used your pseudocode to understand the GDP code. Why did we use a negative speed in the second if statement? The Ninja should be able to connect the pseudocode they wrote to the code they typed. If they do not understand, then walk through each of the pseudocode and how it translates to JavaScript code. The Ninja should be able to state that a negative x speed moves an object to the left. */