فهرست منبع

Finish Yellow Belt

Michael Tang 3 سال پیش
والد
کامیت
af3a18687f

+ 77 - 57
01-white/04-02-hungry-hungry-ninja.js

@@ -1,5 +1,6 @@
 /**
 /**
-Ninjas use conditionals and if statements to keep score and move an object when a key is pressed.
+Ninjas use conditionals and if statements to keep score and move an object when 
+a key is pressed.
 
 
 Reinforced Vocabulary and Concepts
 Reinforced Vocabulary and Concepts
 * Comparison Operators
 * Comparison Operators
@@ -12,48 +13,54 @@ Reinforced Vocabulary and Concepts
 * Pseudocode
 * Pseudocode
 
 
 Sensei Notes
 Sensei Notes
-* This game introduces the use of the x and y functions to set the position of an object. Previously they were
-used to get the position of an object.
-* This game will give the Ninja the last pieces of knowledge they need to complete the final activity in the
-White Belt.
+* This game introduces the use of the x and y functions to set the position of 
+an object. Previously they were used to get the position of an object.
+* This game will give the Ninja the last pieces of knowledge they need to 
+complete the final activity in the White Belt.
 * The Ninja will need to write the code to keep score.
 * The Ninja will need to write the code to keep score.
-* This is the most code that a Ninja has written in a single game, but it is a series of similar if statements.
+* This is the most code that a Ninja has written in a single game, but it is a 
+series of similar if statements.
 
 
 Solution Steps
 Solution Steps
 1 Make sure the Ninja opens the correct scene.
 1 Make sure the Ninja opens the correct scene.
 2 The Ninja should play the game to see what functionality needs to be added.
 2 The Ninja should play the game to see what functionality needs to be added.
 3 Have the Ninja copy the provided pseudocode down as a reference.
 3 Have the Ninja copy the provided pseudocode down as a reference.
 4 Have the Ninja copy the provided pseudocode down as a reference.
 4 Have the Ninja copy the provided pseudocode down as a reference.
-5 Have the Ninja write the pseudocode for pressing the down and right arrows based on the pseudocode
-provided in steps 3 and 4.
+5 Have the Ninja write the pseudocode for pressing the down and right arrows 
+based on the pseudocode provided in steps 3 and 4.
 6 Make sure the Ninja is in the scene's Update Every Frame event.
 6 Make sure the Ninja is in the scene's Update Every Frame event.
     if() {
     if() {
 
 
     }
     }
-7 Make sure the Ninja places the function call inside the if statement's parentheses. Ask them to explain how
-the GDP uses the isKeyPressed function to communicate when a key is being pressed by the user. Ask them
-to explain that the Keys object is an easy way to ask the isKeyPressed function about a specific key on the
-keyboard.
+7 Make sure the Ninja places the function call inside the if statement's 
+parentheses. Ask them to explain how the GDP uses the isKeyPressed function to 
+communicate when a key is being pressed by the user. Ask them to explain that 
+the Keys object is an easy way to ask the isKeyPressed() function about a 
+specific key on the keyboard.
     if(isKeyPressed(Keys.upArrow)) {
     if(isKeyPressed(Keys.upArrow)) {
 
 
     }
     }
-8 Make sure the Ninja types the new line of code inside the body of the if statement. The name of the GDP
-object is ninja and we want to set its x position to exactly 400.
+8 Make sure the Ninja types the new line of code inside the body of the if 
+statement. The name of the GDP object is ninja and we want to set its x position 
+to exactly 400.
     if(isKeyPressed(Keys.upArrow)) {
     if(isKeyPressed(Keys.upArrow)) {
         ninja.x(400);
         ninja.x(400);
     }
     }
-9 The Ninja should play the game and investigate what happens when the up arrow is pressed. The ninja
-object will go to 400 on the x axis, so it will be stuck in the hole.
-10 Make sure the Ninja types the new line of code inside the body of the if statement and sets they value to
-exactly 240.
+9 The Ninja should play the game and investigate what happens when the up arrow 
+is pressed. The ninja object will go to 400 on the x axis, so it will be stuck 
+in the hole.
+10 Make sure the Ninja types the new line of code inside the body of the if 
+statement and sets they value to exactly 240.
     if(isKeyPressed(Keys.upArrow)) {
     if(isKeyPressed(Keys.upArrow)) {
         ninja.x(400);
         ninja.x(400);
         ninja.y(240);
         ninja.y(240);
     }
     }
-11 Have the Ninja play the game to see what happens when the up key is pressed. The Ninja should move to
-the top conveyer belt, but it will not be able to move somewhere else.
-12 Make sure the Ninja writes the new if statement after the first if statement. Make sure they correctly place
-the isKeyPressed function and the Keys.leftArrow object.
+11 Have the Ninja play the game to see what happens when the up key is pressed. 
+The Ninja should move to the top conveyer belt, but it will not be able to move 
+somewhere else.
+12 Make sure the Ninja writes the new if statement after the first if statement. 
+Make sure they correctly place the isKeyPressed function and the Keys.leftArrow 
+object.
     if(isKeyPressed(Keys.leftArrow)) {
     if(isKeyPressed(Keys.leftArrow)) {
             
             
         }
         }
@@ -68,38 +75,45 @@ exactly 300.
         ninja.y(300);
         ninja.y(300);
     }
     }
 15 The ninja can now move to the top and to the left conveyer belts.
 15 The ninja can now move to the top and to the left conveyer belts.
-16 Help the Ninja write a new if statement based off their pseudocode statement from step 5. They should be
-able to use the first two if statements to help them. This code is explicitly provided in the manual in step 18.
+16 Help the Ninja write a new if statement based off their pseudocode statement 
+from step 5. They should be able to use the first two if statements to help them. 
+This code is explicitly provided in the manual in step 18.
     if(isKeyPressed(Keys.downArrow)) {
     if(isKeyPressed(Keys.downArrow)) {
 
 
     }
     }
-17 Help the Ninja write the code that sets the ninja's position to exactly 400, 360.
+17 Help the Ninja write the code that sets the ninja's position to exactly 
+400, 360.
     if(isKeyPressed(Keys.downArrow)) {
     if(isKeyPressed(Keys.downArrow)) {
         ninja.x(400);
         ninja.x(400);
         ninja.y(360);
         ninja.y(360);
     }
     }
-18 Verify that the Ninja's code matches and that the ninja in the game moves to the correct place when the
-down arrow is pressed.
+18 Verify that the Ninja's code matches and that the ninja in the game moves to 
+the correct place when the down arrow is pressed.
 19 Help the Ninja write the final piece of movement code.
 19 Help the Ninja write the final piece of movement code.
     if(isKeyPressed(Keys.rightArrow)) {
     if(isKeyPressed(Keys.rightArrow)) {
         ninja.x(460);
         ninja.x(460);
         ninja.y(300);
         ninja.y(300);
     }
     }
-20 The game's movement code is now complete. The ninja can collect the food, but the score is not updating.
-21 Help the Ninja write the final if statement. Explain that the ninja object knows a function called ateFood() that
-will return true when the ninja collects a piece of food off a conveyer belt.
+20 The game's movement code is now complete. The ninja can collect the food, but 
+the score is not updating.
+21 Help the Ninja write the final if statement. Explain that the ninja object 
+knows a function called ateFood() that will return true when the ninja collects 
+a piece of food off a conveyer belt.
     if(ninja.ateFood()) {
     if(ninja.ateFood()) {
 
 
     }
     }
-22 The ninja object keeps track of the game's score through the ninja.score property. This line of code takes the
-current score, adds one, and updates the value.
+22 The ninja object keeps track of the game's score through the ninja.score 
+property. This line of code takes the current score, adds one, and updates the 
+value.
     if(ninja.ateFood()) {
     if(ninja.ateFood()) {
         ninja.score += 1;
         ninja.score += 1;
     }
     }
-23 The Ninja should notice that the game now gets harder, but the score number in the UI does not update.
-Explain that we are keeping track of the score, but not yet displaying it to the user.
-24 Explain that the GDP uses labels to display text to the user. In this game, we need to set the scorelabel's
-text by passing the score to the text function.
+23 The Ninja should notice that the game now gets harder, but the score number 
+in the UI does not update.
+Explain that we are keeping track of the score, but not yet displaying it to the 
+user.
+24 Explain that the GDP uses labels to display text to the user. In this game, 
+we need to set the scorelabel's text by passing the score to the text function.
     if(ninja.ateFood()) {
     if(ninja.ateFood()) {
         ninja.score += 1;
         ninja.score += 1;
         scoreLabel.text(ninja.score);
         scoreLabel.text(ninja.score);
@@ -134,25 +148,31 @@ if(ninja.ateFood()) {
 
 
 /**
 /**
 Sensei Stops
 Sensei Stops
-5 Read over your pseudocode with a Sensei. Talk obout whot you need to change to convert it into real
-JavaScript code.
-The Ninja should be able to explain how to convert the pseudocode into JavaScript code. If they are
-struggling, you can use Coconut Chaos as a reference point.
-10 Before you play your game, tell a Sensei what you think will happen to your ninja. Using the words horizontal,
-vertical, and coordinate, explain the difference between the ninja's x and y values.
-Answers will vary, but Ninjas should be able to pair horizontal with x and vertical with y. They should know
-that x starts at O on the left and increases in value to the right. They should know that y starts at O at the top
-and increases up in value down.
-15 Tell a Sensei what code you still need to write to make your ninja move to the bottom and the right conveyer
-belts.
-The Ninja should be able to explain that they need two more if statements that respond to the down and
-right arrows and move the ninja to the appropriate location.
-20 Tell a Sensei how you planned, coded, ond tested moving the ninja down ond right. What parts were eosy?
-What parts were hard?
-Answers will vary. This is a time for the Ninja to reflect on the process of creating pseudocode,
-programming, and testing.
-25 Explain the difference between ninja.score and scoreLabel to a Sensei. Why do we need both?
-We are keeping track of the value of score with ninja.score and we display the score in the scorelabel GDP
-object. Explain that the ninja is keeping track of how many pieces of food they ate, and they need to tell the
-user since we can't read the ninja's mind.
+5 Read over your pseudocode with a Sensei. Talk obout whot you need to change to 
+convert it into real JavaScript code.
+The Ninja should be able to explain how to convert the pseudocode into 
+JavaScript code. If they are struggling, you can use Coconut Chaos as a 
+reference point.
+10 Before you play your game, tell a Sensei what you think will happen to your 
+ninja. Using the words horizontal, vertical, and coordinate, explain the 
+difference between the ninja's x and y values.
+Answers will vary, but Ninjas should be able to pair horizontal with x and 
+vertical with y. They should know that x starts at O on the left and increases 
+in value to the right. They should know that y starts at O at the top and 
+increases up in value down.
+15 Tell a Sensei what code you still need to write to make your ninja move to 
+the bottom and the right conveyer belts.
+The Ninja should be able to explain that they need two more if statements that 
+respond to the down and right arrows and move the ninja to the appropriate 
+location.
+20 Tell a Sensei how you planned, coded, ond tested moving the ninja down ond 
+right. What parts were easy? What parts were hard?
+Answers will vary. This is a time for the Ninja to reflect on the process of 
+creating pseudocode, programming, and testing.
+25 Explain the difference between ninja.score and scoreLabel to a Sensei. 
+Why do we need both?
+We are keeping track of the value of score with ninja.score and we display the 
+score in the scorelabel GDP object. Explain that the ninja is keeping track of 
+how many pieces of food they ate, and they need to tell the user since we can't 
+read the ninja's mind.
  */
  */

+ 10 - 0
02-yellow/05-01-starscape.js

@@ -0,0 +1,10 @@
+/** 
+Ninjas are reintroduced to the remove() function and taught to understand it after 
+using it in Ninja Supplies, this will become more significant as they start building 
+games that rapidly clone objects to limit what their game engines have to process.
+*/
+
+//********************Star Object: Update Every Frame Event*************************//
+if($this.x() <= 0) {
+    $this.remove();
+}

+ 25 - 0
02-yellow/05-02-zapper-pt-1.js

@@ -0,0 +1,25 @@
+/**
+A new application of the remove() function is presented. Instead of removing objects 
+based on an x-coordinate condition, they’re removed on contact with another object.
+*/
+
+//*****************Beam Object: Update Every Frame Event***************************//
+var spacePressed = isKeyPressed(Keys.space);
+if(spacePressed) {
+    $this.visible(true);
+} else {
+    $this.visible(false);
+}
+
+//*****************enemy Object: Update Every Frame Event***************************//
+// remove base if enemy reaches base
+if (!this.isTouching(base)) {
+    moveBy($this);
+} else {
+    base.remove();
+    beam.remove();
+}
+// remove enemy when hit with beam
+if ($this.isTouching(beam) && beam.visible()) {
+    $this.remove();
+}

+ 23 - 0
02-yellow/05-03-zapper-pt-2.js

@@ -0,0 +1,23 @@
+/**
+This activity is a combination of several functions from previous lessons.
+*/
+
+//*****************Scene Object: Initialize When Scene Starts***********************//
+if($this.scene.state() == "PLAY") {
+    createTimer(1000, function() {
+        var nship = enemy.clone();
+        nship.x(31);
+        nship.y(12);
+    })
+}
+
+//*****************enemy Object: Update Every Frame********************************//
+moveX($this);
+if($this.isTouching(beam) && beam.visible()) {
+    $this.remove()
+} 
+// ninjas may experiment with the conditions to make enemy move towards base 
+if ($this.x() >= 700 || $this.x() <= 0) {
+    $this.speedX(-$this.speedX());
+    $this.y($this.y() + 100);
+}

+ 27 - 0
02-yellow/05-04-wall-blaster.js

@@ -0,0 +1,27 @@
+/**
+Ninjas are presented with the for loop, which they will use to build a scene, 
+and then create a game utilizing the remove function.
+*/
+
+//************************Scene Object: Initialize When Scene Starts***************//
+if($this.scene.state() == "PLAY" ) {
+    var brickX = 4;
+    var nbrick;
+    $this.score = 0
+
+    //for() loop to create the bricks across the screen
+    for (var brickCount = 1; brickCount <= 9; brickCount++) {
+        nbrick = brick.clone();
+        nbrick.x(brickX + 80 * brickCount);
+        nbrick.y(150)
+    }
+}
+
+//************************brick Object: Update Every Frame Event*******************//
+if($this.isTouching(ball)) {
+    ball.speedY(-ball.speedY()); //bounce the ball in opposite direction
+    $this.remove(); //remove brick
+    $this.scene.score += 10; //score update
+    lblScore.text(parseInt($this.scene.score));
+}
+

+ 53 - 0
02-yellow/05-05-py-color-change-pt-2.js

@@ -0,0 +1,53 @@
+/**
+The ninja can change objects colors by using the isTouching and toggleDraggable 
+functions. This is similar to the first Color Change activity but with additional 
+functionality. The player should not be able to drag the circles once they have made 
+the rectangle change color.
+
+hex codes not needed for this game, $this.fill() returns the current color
+yellow - #FEFD06
+green - #43C318
+red - #DE2121
+blue - #186EC3
+purple - #9608AF
+*/
+
+//***********************button1 Object: Mouse Button Up Event********************//
+if($this.isTouching(rectangle)) {
+    rectangle.fill($this.fill());
+    $this.x(166);
+    $this.y(440);
+    $this.toggleDraggable();
+}
+
+//***********************button2 Object: Mouse Button Up Event********************//
+if($this.isTouching(rectangle)) {
+    rectangle.fill($this.fill());
+    $this.x(292);
+    $this.y(440);
+    $this.toggleDraggable();
+}
+
+//***********************button3 Object: Mouse Button Up Event*******************//
+if($this.isTouching(rectangle)) {
+    rectangle.fill($this.fill());
+    $this.x(420);
+    $this.y(440);
+    $this.toggleDraggable();
+}
+
+//***********************button4 Object: Mouse Button Up Event*******************//
+if($this.isTouching(rectangle)) {
+    rectangle.fill($this.fill());
+    $this.x(550);
+    $this.y(440);
+    $this.toggleDraggable();
+}
+
+//***********************button5 Object: Mouse Button Up Event*******************//
+if($this.isTouching(rectangle)) {
+    rectangle.fill($this.fill());
+    $this.x(684);
+    $this.y(440);
+    $this.toggleDraggable();
+}

+ 60 - 0
02-yellow/05-06-py-lift-off.js

@@ -0,0 +1,60 @@
+/**
+The ninja can activate the objects either by clicking or by dragging. 
+This example solution uses dragging.
+
+Decomposition:
+* variable created to count supplies
+* 
+
+*/
+
+//****************Scene Object: Initialize When Scene Starts Event***************//
+$this.totalSupplies = 0;
+
+//******************Scene Object: Update Every Frame Event***********************//
+if ($this.totalSupplies >= 4) {
+    //animate on ship sprite
+    spaceShip.animation("thrust");
+    spaceShip.incrementAnimation();
+    rocket.moveY(-100);
+}
+
+//***************supply_1 Object: Mouse Button Up Event*************************//
+if($this.isTouching(rocket)) {
+    $this.scene.totalSupplies += 1; 
+    $this.remove();
+} else {
+    //return to original position
+    $this.x(44);
+    $this.y(436);
+}
+
+//***********************supply_2 Object: Mouse Button Up Event*******************//
+if($this.isTouching(rocket)) {
+    $this.scene.totalSupplies += 1; 
+    $this.remove();
+} else {
+    //return to original position
+    $this.x(182);
+    $this.y(412);
+}
+
+//**********************supply_3 Object: Mouse Button Up Event*******************//
+if($this.isTouching(rocket)) {
+    $this.scene.totalSupplies += 1; 
+    $this.remove();
+} else {
+    //return to original position
+    $this.x(254);
+    $this.y(446);
+}
+
+//************************supply_4 Object: Mouse Button Up Event*******************//
+if($this.isTouching(rocket)) {
+    $this.scene.totalSupplies += 1; 
+    $this.remove();
+} else {
+    //return to original position
+    $this.x(374);
+    $this.y(444);
+}

+ 39 - 0
02-yellow/05-07-py-bubbles.js

@@ -0,0 +1,39 @@
+/**
+Like the Rain Catcher games, this game uses a timer to release the bubbles so they 
+can float to the top. We’ll be using $this.scene.state() == “PLAY” so that the bubbles 
+do not continue to rise after the game has stopped. The bubble used in this game may 
+be hard to initially locate since it starts at the bottom of the screen. Use 
+GAME OBJECTS to select it if you’re having trouble.
+
+Decomposition: 
+* variable to keep track of score
+* bubbles are cloned at random x 
+* bubbles move up 
+* get a point when bubbles are clicked
+* lose a point when bubble moves off screen
+*/
+
+//*****************Scene Object - Initialize When Scene Starts*********************//
+// make variable for score
+$this.totalScore = 0;
+if($this.scene.state() == "PLAY") {
+    createTimer(1000, function() {
+        var nbubble = bubble.clone();
+        nbubble.x(random(720,80));
+        nbubble.y(600);
+    });
+}
+
+//*******************bubble Object - Update Every Frame Event**********************//
+if($this.y() > 0) { // move as long as it's on the screen
+    $this.moveY(-100);
+} else { // when it is off screen
+    $this.remove()
+    $this.scene.totalScore -= 1;
+    score.text($this.scene.totalScore)
+}
+
+//*********************bubble Object - Mouse Click Event***************************//
+$this.remove();
+$this.scene.totalScore += 1;
+score.text($this.scene.totalScore); // update score

+ 134 - 0
02-yellow/06-01-meteors-deluxe.js

@@ -0,0 +1,134 @@
+/**
+Ninjas are presented with a completely blank scene and will have to build an entire 
+activity from the ground up using everything that they’ve learned in Yellow Belt.
+*/
+
+//*********************Scene Object - Initialize When Scene Starts Event***********//
+if ($this.scene.state() == "PLAY") {
+    var nrock = rocks.clone();
+    nrock.x(random(800));
+    nrock.y(random(600));
+}
+
+//**************rock Object - Initialize When Scene Starts Event******************//
+if ($this.scene.state() == "PLAY") {
+    $this.speedX(random(50,-50));
+    $this.speedY(random(50,-50));
+    $this.rot = random(30,-30);
+}
+
+//******************rock Object - Update Every Frame Event*************************//
+moveX($this);
+moveY($this);
+$this.spin($this.rot);
+// keep rocks in the scene
+if($this.y() > 600) {
+    $this.y(0);
+}
+if($this.y() < 0) {
+    $this.y(600);
+}
+if($this.x() > 800) {
+    $this.x(0);
+}
+if($this.x() < 0) {
+    $this.x(800);
+}
+
+// collision check 
+//find the bullet on the scene
+var bullet = $this.scene.projectile;
+
+if(bullet && $this.isTouching(bullet)) {
+    //instead of making the variable, we add to the score directly
+    lblScore.text(parseInt(lblScore.text() + 10));
+
+    $this.scaleX($this.scaleX()/2); //start to reduce the rock by 1/2
+    $this.scaleY($this.scaleY()/2);
+    $this.offsetX($this.offsetX()/2);
+    $this.offsetY($this.offsetY()/2);
+
+    if($this.scaleX() >= 0.125) {
+        var nrock = $this.clone(); //split the rock as long as as it's bigger than 0.125
+    } else {
+        $this.remove();
+    }
+
+    $this.scene.projectile = null; //remove bullet and reseet value of scene projectile
+    bullet.remove();
+}
+
+//*******************rocket Group - Update Every Frame Event***********************//
+var leftPressed = isKeyPressed(Keys.leftArrow);
+var rightPressed = isKeyPressed(Keys.rightArrow);
+var upPressed = isKeyPressed(Keys.upArrow);
+
+if(upPressed) { // if pressed, move rocket forward
+    $this.moveForwardByRotation();
+}
+
+if(leftPressed) { // if pressed, rotate to the left
+    $this.spin(-40);
+}
+
+if(rightPressed) {
+    $this.spin(40);
+}
+
+// keep rocket in the scene
+if ($this.y() > 600) {
+    $this.y(0);
+}
+if ($this.y() < 0) {
+    $this.y(600);
+}
+if ($this.x()>800) {
+    $this.x(0);
+}
+if( $this.x()<0) {
+    $this.x(800);
+}
+// projectile functionality - rocket group talks to bullet, creates a 'moving' boolean
+//bullet is listening for moving to be true
+var spacePresssed = isKeyPressed(Keys.space)
+var bullet = $this.findName("bullet"); //find the active bullet on the scene
+
+if(spacePressed) {
+    if(!$this.scene.projectile) {
+        var b = bullet.clone(true, true, $this.scene); //cloning the bullet from bullet
+
+        b.x(bullet.getStagePos().x); //getting the x,y and rotation in the scene
+        b.y(bullet.getStagePos().y);
+        b.rotation($this.rotation());
+        b.moving = true; //set boolean to true so bullet will excecute the code when moving is true
+        b.z(1000); //ensure it's always on top of scene
+
+        $this.scene.projectile = b; 
+    }
+}
+
+//*****************spaceShip Object - Update Every Frame Event********************//
+// animation code
+var upPressed = isKeyPressed(Keys.upArrow);
+if (upPressed) { 
+    $this.animation("thrust"); 
+    $this.incrementAnimation(); 
+    
+} else { 
+    $this.animation("default"); 
+    
+}
+
+//******************bullet Object - Update Every Frame Event**********************//
+//the moving boolean created from rocket group and so it knows to shoot when the 
+//space bar is pressed
+if ($this.moving) { 
+    $this.moveForwardByRotation(); 
+    // condition here will prevent overloading the screen with bullets,
+    // it checks for current bullets on the screen
+    if ($this.y() > 600 || $this.y() < 0 || $this.x() < 0 || $this.x() > 800) { 
+        $this.scene.projectile = null; 
+        $this.remove(); // rock is removed when collision occurs
+    } 
+}
+

+ 67 - 0
02-yellow/06-02-py-bug-invaders.js

@@ -0,0 +1,67 @@
+/**
+In this game, bugs come down at random from the top of the screen and the player 
+has to zap them. We’ll be using keyboard controls to move the ninja, but using the 
+mouse is also acceptable.
+
+Decomposition:
+* bugs cloning from top at random x
+* keyboard controls to move ninja
+* bullet fired
+* collision with bugs adds to score
+
+*/
+
+//****************Scene Object - Initialize When Scene Starts Even***************//
+// game variables 
+$this.totalScore = 0;
+bullet.fired = false; // set up boolean to control shooting
+if($this.scene.state() == "PLAY") { //cloning of bugs
+    createTimer(1000, function() {
+        var nbug = bug.clone();
+        nbug.x(random(720, 80)); // set bug starting position
+        nbug.y(-80);
+    });
+}
+
+//******************ninja Object - Update Every Frame Event**********************//
+// set up controls
+var rightArrowPressed = isKeyPressed(Keys.rightArrow);
+var leftArrowPressed = isKeyPressed(Keys.leftArrow);
+var spacePressed = isKeyPressed(Keys.space);
+
+if(rightArrowPressed && this.x() < 777) {
+    $this.moveX(100);
+}
+
+if(leftArrowPressed && this.x() > 23) {
+    $this.moveX(-100);
+}
+
+if(spacePressed && bullet.fired === false) {
+    bullet.fired = true; //send true to bullet
+}
+
+//******************bug Object - Update Every Frame Event************************//
+if($this.y() < 600) {
+    $this.moveY(50);
+    $this.incrementAnimation();
+} else {
+    $this.remove();
+    $this.scene.totalScore -= 1;
+    score.text($this.scene.totalScore);
+}
+if($this.isTouching(bullet)) {
+    $this.remove();
+    $this.scene.totalScore += 1;
+    score.text($this.scene.totalScore);
+    bullet.fired = false;
+}
+
+//****************bullet Object - Update Every Frame****************************//
+if($this.fired && $this.y() > 0) { //bullet listening for fired = true 
+    $this.moveY(-250);
+} else {
+    $this.fired = false;
+    $this.x(ninja.x()); //reset bullet to ninja.x, y
+    $this.y(ninja.y()); 
+}

+ 58 - 0
03-orange/01-whack-a-ninja.js

@@ -0,0 +1,58 @@
+//*********************Scene - Initialize When Scene Starts Event******************//
+if ($this.scene.state() == "PLAY") { 
+    $this.peekSpeed = 100;
+    $this.peekDistance = 250;
+    $this.points = 0;
+
+    createTimer(2000, $this.activateNinja);
+}
+
+$this.activateNinja = function() {
+    //pick and find a random ninja
+    var randomNumber = random(1,5);
+    var chosenNinja = $this.findName("ninja" + randomNumber);
+
+    //activate the chosen ninja and move it up
+    chosenNinja.active = true;
+    chosenNinja.speedY(-$this.peekSpeed);
+};
+
+//*******************ninja Object - Initialize When Scene Starts Event**************//
+$this.startingY = $this.y();
+
+$this.stoppingY = $this.startingY - $this.scene.peekDistance; 
+
+//********************ninja Objects - Update Every Frame Event**********************//
+if($this.active) { // important that the closing brace is at the very end, otherwise,
+    //we'll lose score even when ninja is not active
+    //move ninja up if it's active
+    moveY($this);
+
+
+    //if ninja peeks all the way out, start going back down
+    if($this.y() <= $this.stoppingY) {
+        $this.speedY($this.scene.peekSpeed);
+    }
+
+    // stop ninja if it reaches its hiding spot
+    // subtract a point, deactivate ninja
+    if ($this.y() >= $this.startingY) {
+        $this.speedY(0);
+        $this.scene.points -= 1;
+        score.text($this.scene.points);
+        $this.active = false;
+    }
+}
+//***************************ninja Object - Mouse Click Event***********************//
+//if ninja is active
+if ($this.active) {
+    //deactivate
+    $this.active = false;
+
+    //move to starting location
+    $this.y($this.startingY);
+
+    //increase and update score 
+    $this.scene.points += 1;
+    score.text($this.scene.points);
+}

+ 1 - 0
03-orange/02-shuriken-dodge.js

@@ -0,0 +1 @@
+//**********************Scene Object - Initialize When Scene Starts*****************//

+ 0 - 5
03-orange/whack-a-ninja

@@ -1,5 +0,0 @@
-//Scene - Initialize When Scene Starts
-//Generate random number between 1 and 5;
-if($this.scene.state() == "PLAY"){
-    $this.ninjaNum = Math.round(random(5,1));
-}