| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /**
- Ninjas create two if statements to use the mouse to control the position of an
- object in the scene.
- New Vocabulary and Concepts
- * Comparison Operators
- * GDP getMouseX()
- * GDP .x() function
- * Pseudocode
- Reinforced Vocabulary and Concepts
- * Boolean Logic
- * Functions and Parameters
- * if() statements
- * Object Names
- Sensei Notes
- * This is the first introduction to user input.
- * This activity uses if statements and Boolean logic.
- Solution Steps
- 1 Make sure the Ninja opens the correct scene.
- 2 Let the Ninja play the game so they can see what functionality needs to be
- added.
- 3 This step introduces pseudocode. As the code becomes more complex, the manual
- places a larger focus on the logic rather than the syntax.
- 4 Work with the Ninja to brainstorm and think about the first piece of
- pseudocode and the situations it applies to. Lead them to discover we need a
- second if statement that covers when the laser is to the right of the mouse.
- Help the Ninja write their pseudocode statement. It is okay if it is not perfect.
- 5 Compare and contrast the Ninja's pseudocode with the provided pseudocode.
- 6 Make sure the Ninja is coding in the scene's Update Every Frame event.
- Reference the pseudocode before the Ninja types the if statement. The GDP's
- editor will say there is an error. This is because we have an incomplete if
- statement. This will be fixed in the next step.
- if(){
- }
- 7 Make sure the Ninja writes the new line of code inside the parentheses. All
- GDP objects have an .x() and .y() function that can be used to get or set the
- object's position. The error is now gone, but the game hasn't changed. Ask the
- Ninja what functionality still needs to be coded.
- if(laser.x()) {
-
- }
- 8 This is the introduction to operators. If the Ninja does not understand what
- the less than operator means, then ask them if a real-world object's age or size
- is less than another object's age or size.
- if(laser.x() < ) {
- }
- 9 Make sure the Ninja writes the getMouseX() function in the correct location of
- the if statement. This function will return the x value of the current or last
- known mouse position.
- if(laser.x() < getMouseX()) {
- }
- 10 Make sure the Ninja writes the new line of code inside the body of the if
- statement. Since we want to easily control the direction that the laser moves,
- we are using a version of moveX that takes the speed as a second parameter. If
- the second parameter is left out, then the laser will move at the rate of speedX
- that is set directly in the properties tab. A speed of 400 is not too slow or
- too fast, but the Ninja can change it if they want.
- if(laser.x() < getMouseX()) {
- moveX(laser, 400);
- }
- 11 Make sure the Ninja types the new if statement after the first. There will be
- another error like in step 6.
- if() {
-
- }
- 12 Help the Ninja write the entire conditional statement using the pseudocode
- and the first if statement. Make sure they use the greater than sign.
- if(laser.x() > getMouseX()) {
-
- }
- 13 Help the Ninja write the body of the second if statement using the pseudocode
- and the body of the first if statement. Mention that since we want the laser to
- move to the left, we want to use a negative speed.
- if(laser.x() > getMouseX()) {
- moveX(laser, -400);
- }
- 14 This step asks the Ninja to change the speed being passed to the moveX
- function. Make sure the Ninja changes it at least twice to see how a smaller and
- a larger number affects the speed.
- 15 Before the Ninja submits the scene, verify that the script is correct.
- */
- if(laser.x() < getMouseX()) {
- moveX(laser, 400);
- }
- if(laser.x() > getMouseX()) {
- moveX(laser, -400);
- }
- /**
- Sensei Stops
- 5 Read your pseudocode if statement to a Sensei. Explain what your condition is
- and what happens when that condition is met. Why is it helpful to use pseudocode?
- If the Ninja's pseudocode is incorrect, discuss what is wrong and how to correct
- it. Pseudocode is important because it lets you plan before you start coding.
- 10 Play your game and explain your code to a Sensei. Be sure to explain the
- three parts of the condition and the code in the body. What do you think you
- need to change for the second if statement? Right now, the laser will only move
- right towards the mouse. Have the Ninja connect the code to the action in the
- scene. Have the Ninja think about what parts of the if statement will need to
- change to make the laser move in the opposite direction.
- 15 Explain to a Sensei how planning out your code before you program it is
- helpful. Was it easier to understand the real code ofter you wrote out the
- pseudocode?
- Compare planning with pseudocode to brainstorming and outlining before writing
- in school.
- */
|