浏览代码

Add Yellow Belt games

Michael Tang 3 年之前
父节点
当前提交
a7818b99a4

+ 11 - 0
02-yellow/04-01-bumper-car.js

@@ -0,0 +1,11 @@
+/**
+A new function, flipDirection(), is introduced to simplify code that students used in their early activities, 
+during their first lesson in moveX.
+**/
+
+//**********************Car Object: Update Every Frame Event********************//
+if ($this.x() >= 700 || $this.x() <= 100) { //go over what || means, and make sure
+    //that ninja can explain the conditions of the if() statement
+    $this.flipDirection(); //have ninjas explain what the following code is doing.
+    $this.scaleX(-$this.scaleX()); 
+}

+ 31 - 0
02-yellow/04-02-ballon-protect.js

@@ -0,0 +1,31 @@
+/**
+This activity is a simple extension of the previous lesson in flipDirection, adding the moveForward() function.
+ */
+
+//**************circle_1 Object - Update Every Frame*****************//
+$this.moveForward(1); // move forward at a speed of 1 
+if ($this.isTouching(balloon)) { 
+    // if the circle touches the balloon 
+    balloon.remove(); // remove the balloon. 
+} 
+if ($this.x() < 30) { 
+    // if the circle is too far left 
+    $this.flipDirection(); // flip its direction. 
+}
+
+//***************circle_1 Object 0 Mouse Button Up Event************//
+$this.flipDirection();
+
+//*****************circle_2 Object - Update Every Frame**************//
+$this.moveForward(1);
+
+if($this.isTouching(balloon)){
+    balloon.remove();    
+}
+
+if($this.x() > 770){ //review x , y so ninja knows the coordinates referenced
+    $this.flipDirection();
+}
+
+//***************circle_2 Object 0 Mouse Button Up Event************//
+$this.flipDirection();

+ 20 - 0
02-yellow/04-03-ninja-snacks.js

@@ -0,0 +1,20 @@
+/**
+This activity further reinforces the logic that objects don’t need to be visible 
+to be detected for collision purposes.
+**/
+
+//*******************Apple Object - Mouse Click Event******************//
+//When apple is click, move to target x and y
+$this.moveTo(400,285);
+$this.moveTo(mouth.x, mouth.y);
+
+//********************Apple Object - Update Every Frame***************//
+if($this.isTouching(mouth)){ //check if apple is touching mouth
+    $this.remove();
+}
+
+//****************Ninja Object - Update Every Frame*******************//
+$this.moveForward(5); 
+if ($this.y() <= -130 || $this.y() >= 50) { 
+    $this.flipDirection(); 
+}

+ 7 - 0
02-yellow/04-04-shuriken-toss-pt-1.js

@@ -0,0 +1,7 @@
+/** This lesson is an extension of the previous activities - instead of a simple moveTo function, 
+ * ninjas will now be using a moveToObject() function. But be careful, with a more complex function 
+ * comes more complex ways for it to be used!
+**/
+
+//***********Target Object - Mouse Click Event************//
+star.moveToObject($this);

+ 7 - 0
02-yellow/04-05-space-tour.js

@@ -0,0 +1,7 @@
+/**
+More moveToObject() function uses. This time, it’s not a new object that will be moving but the original object itself. Additionally, ninjas will have to use the pointToObject() function to keep the activity visually consistent.
+ */
+
+//******************Meteor Object [1-3] - Mouse Click Event****************//
+rocket.pointToObject($this); 
+rocket.moveToObject($this);

+ 22 - 0
02-yellow/04-06-shuriken-toss-pt-2.js

@@ -0,0 +1,22 @@
+/**
+This lesson combines some of the more complex functions ninjas have learned so far
+like pointToCursor(),rotation() and moveForwardByRotation(). 
+They will also create and manipulate object properties.
+ */
+
+//********************Star Object - Update Every Frame******************//
+if($this.thrown && $this.x() > 0 && $this.y() > 0 && $this.x() < 800 && $this.y() < 600  ){
+    $this.moveForwardByRotation();
+}else{
+    $this.thrown = false;
+    $this.x(454);
+    $this.y(462);
+}
+
+//*********************Background Object - Mouse Click Event************//
+if(!star.thrown){
+    star.pointToCursor();
+    star.rotation(star.rotation() -90);
+    star.thrown=true;
+    
+}

+ 51 - 0
02-yellow/04-07-ninja-battle.js

@@ -0,0 +1,51 @@
+/** 
+This activity teaches the ninjas a new application of the pointToObject() function.
+**/
+
+//****************pcninja Object - Update Every Frame***************//
+var downArrowPressed = isKeyPressed(Keys.downArrow);
+
+if(downArrowPressed && $this.y() < 460){
+    moveY($this);
+}
+
+var upArrowPressed = isKeyPressed(Keys.upArrow);
+
+if(upArrowPressed && $this.y() > 0){
+    moveY($this, -$this.speedY());
+}
+
+//******************star Object - Update Every Frame***************//
+if($this.thrown){
+    $this.moveForward(10);
+}
+
+// Bonus
+if ($this.isTouching(pcninja) || $this.x() > 800 || $this.y() < 0 || $this.y() > 600) { 
+    $this.remove(); 
+} else if ($this.x() < 0) { 
+    $this.remove(); 
+    $this.scene.score++; 
+}
+
+//****************pcninja - Initialize When Scene Starts***********//
+if($this.scene.state() == "PLAY"){
+    createTimer(5000, function(){
+        var nstar = star.clone();
+        nstar.x(682);
+        nstar.y(304);
+        nstar.thrown=true;
+        nstar.pointToObject(pcninja);
+        nstar.rotatoion(nstar.rotation()-90);
+    });
+}
+
+//**********Scene Object - Initialize When Scene Starts**************//
+// BONUS
+if ($this.scene.state() == "PLAY") { 
+    $this.scene.score = 0; 
+}
+
+//***************Scene Object - Update Every Frame******************//
+// BONUS 
+score.text($this.scene.score);

+ 24 - 0
02-yellow/04-08-PY-candy-sort.js

@@ -0,0 +1,24 @@
+/**
+One of 3 random candies drops down the chute onto the conveyor belt and 
+into one of the bins. The player uses the arrow keys to shift the bins so 
+that the candy drops into the matching colored bin. There is already a Boolean 
+key check (bins.keyDown) to detect if either of the arrows has been pressed. 
+The code for moving the bins is already attached to the group. Ninjas should 
+reference the timer code from Rain Catcher and Whack a Ninja. 
+
+Decomposition
+* Candy move down the chute
+* Candy changes direction to moves along belt
+* Arrow keys control chutes
+* Timer is used to spawn new candies
+* Check if the correct color dropped in bins
+
+*/
+
+//*************Scene Object - Initialize When Scene Starts***********//
+//Create score variable
+$this.totalScore = 0;
+//Create variable to match binColor with candyColor
+$this.binColor = 0;
+//boolean used to check which arrow is pressed
+bins.keyDown = false;