Pārlūkot izejas kodu

Fix Shuriken Dodge

michtang 3 gadi atpakaļ
vecāks
revīzija
f74eb47034

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

@@ -132,3 +132,137 @@ if ($this.moving) {
     } 
 }
 
+/**
+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
+    } 
+}
+

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

@@ -1 +1,44 @@
+/**
+Initial Set up:
+* Add shuriken from assets
+* Add Label - pointsLabel and set text to 0
+*/
 //**********************Scene Object - Initialize When Scene Starts*****************//
+// start the game with 0 points
+$this.points = 0 ; //set points variable to 0
+$this.spawnShuriken = function () {
+    // clone the original shuriken object
+    var clonedShuriken = shuriken. clone ();
+    // create a random number
+    // change the clone's x position
+    var randomX = random (0 , 800 );
+    clonedShuriken.x (randomX);
+    // set the clone's y position to 0
+    clonedShuriken.y (0);
+    // change the speed based on points
+    clonedShuriken. speedY (40 + $this.points * 5);
+} ;
+
+if ($this.scene.state () == "PLAY" ) {
+    createTimer (1000 , $this.spawnShuriken);
+}
+
+//*********************shuriken Object - Update Every Frame Event********************//
+moveY($this);
+// if the shuriken touches the ground
+if ($this.isTouching(ground)) {
+    // add one point and update the label
+    $this.scene.points += 1;
+    pointsLabel.text($this.scene.points);
+    // remove the shuriken
+    $this.remove();
+}
+// if the shuriken touches the avatar ninja
+if ($this.isTouching (avatar)) {
+    // stop the game's code execution
+    $this.scene.stopCode();
+}
+
+
+//************************shuriken Object - Initialize When Scene Starts Event**********//
+$this.speedY(50);

+ 87 - 0
03-orange/03-ninja-race.js

@@ -0,0 +1,87 @@
+//***********************Scene Object - Initialize When Scene Starts Event****************//
+if($this. scene. state () == "PLAY" ) {
+    // place both the road images
+    road1.x(0);
+    roadl.y(0);
+    road2.x(0);
+    road2.y(-1200);
+}
+
+//**********************road Object - Update Every Frame Event***************************//
+// move the road down
+$this.moveY();
+// check to see if the road is off the screen
+if ($this.y() > 1200) {
+// move it back to the top of the screen
+$this.y(-1200);
+}
+
+//**********************cycleRed Object - Update Every Frame Event***********************//
+// move the cycle left
+if (isKeyPressed(Keys.a)) {
+    $this.moveX(-100);
+}
+    // move the cycle right
+    if (isKeyPressed(Keys.d)) {
+    $this.moveX(l00);
+}
+    // if the cycle touches the boost
+    // move the cycle up
+    if ($this.isTouching(boost)) {
+    $this.moveY (-50);
+}
+    // if the cycle touches the mud
+    // move the cycle down
+    if ($this.isTouching(mud)) {
+    $this.moveY(50);
+}
+
+//************************cycleBlue Object - Update Every Frame Event*********************//
+// move the cycle left
+if (isKeyPressed(Keys.leftArrow)) {
+    $this.moveX(-100);
+}
+// move the cycle right
+if (isKeyPressed (Keys.rightArrow)) {
+    $this.moveX(l00);
+}
+// if the cycle touches the boost
+// move the cycle up
+if ($this.isTouching (boost)) {
+    $this.moveY(-50);
+}
+// if the cycle touches the mud
+// move the cycle down
+if ($this.isTouching (mud)) {
+    $this.moveY(50);
+}
+
+//**************************mud and boost Objects - Update Every Frame Event***************//
+// move it down
+$this.moveY();
+
+// if the it moves off the bottom of the screen
+if ($this.y() >= 600) {
+    // pick a random x within the screen
+    $this.x(random(l00, 700));
+    // pick a random y above the screen
+    $this.y(random(-200 , -600));
+}
+
+//**************************message Object - Update Every Frame Event***********************//
+// store they values
+var redY = cycleRed.y();
+var blueY = cycleBlue.y();
+
+// determine a winner or who is in the lead
+if (redY <= 50) {
+    message.text("Red wins!");
+} else if (blueY <= 50) {
+    message.text("Blue wins!");
+} else if (redY < blueY) {
+    message.text("Red is in the lead!");
+} else if (blueY < redY) {
+    message.text("Blue is in the lead!");
+} else {
+    message.text("Tied!");
+}