Michael Tang 3 lat temu
commit
3d0828363d
13 zmienionych plików z 391 dodań i 0 usunięć
  1. 47 0
      white/04-03
  2. 0 0
      yellow/01-01
  3. 24 0
      yellow/01-02
  4. 15 0
      yellow/01-03
  5. 22 0
      yellow/01-04
  6. 27 0
      yellow/01-05
  7. 14 0
      yellow/01-06
  8. 55 0
      yellow/02-01
  9. 43 0
      yellow/02-02
  10. 11 0
      yellow/03-01
  11. 34 0
      yellow/03-02
  12. 58 0
      yellow/03-03
  13. 41 0
      yellow/PY-RollingDice

+ 47 - 0
white/04-03

@@ -0,0 +1,47 @@
+// Scene - Update Every Frame
+/**
+ * leftPaddle
+ * if the up arrow is pressed, move the leftPaddle up
+ * if the down arrow is pressed, move the leftPaddle down
+**/
+if ( isKeyPressed(Keys.upArrow) ) {
+    moveY(leftPaddle, -300);
+}
+
+if ( isKeyPressed(Keys.downArrow) ) {
+    moveY(leftPaddle, 300);
+}
+
+/**
+ * rightPaddle
+ * if the rightPaddle is below the mouse, move the rightPaddle up
+ * if the rightPaddle is above the mouse, move the rightPaddle down
+**/
+
+if ( rightPaddle.y() > getMouseY() ) {
+    moveY(rightPaddle, -300);
+}
+
+if ( rightPaddle.y() < getMouseY() ) {
+    moveY(rightPaddle, 300);
+}
+
+/**
+ * walls
+ * if the ball touches right wall, give player 1 a point and reset the ball
+ * if the ball touches left wall, give player 2 a point and reset the ball
+**/
+
+
+if (ball.isTouchingRightWall() ) {
+    leftPaddle.score += 1;
+    leftScoreLabel.text(leftPaddle.score);
+    ball.x(400);
+    ball.y(300);
+}
+if ( ball.isTouchingLeftWall() ) {
+    rightPaddle.score += 1;
+    rightScoreLabel.text(rightPaddle.score);
+    ball.x(400);
+    ball.y(300);
+}

+ 0 - 0
yellow/01-01


+ 24 - 0
yellow/01-02

@@ -0,0 +1,24 @@
+// turtle (group) - Update Every Frame
+/** 
+Set up vars to detect keypresses. 
+**/
+
+var rightArrowPressed = isKeyPressed(Keys.rightArrow);
+var leftArrowPressed = isKeyPressed(Keys.leftArrow);
+
+/**
+if statement used to code the actual key presses
+**/
+
+if ( rightArrowPressed ) {
+    moveX($this);
+    
+}
+/** 
+movement in the x direction needs to be negative to reflect moving left
+**/
+
+if ( leftArrowPressed ) {
+    moveX($this, -$this.speedX());
+
+}

+ 15 - 0
yellow/01-03

@@ -0,0 +1,15 @@
+//turtleSprite - Initialize When Scene Starts 
+//Careful with the capitalization of PLAY and the quotations
+//Sometimes, the quotation marks do not paste properly
+
+if($this.scene.state() == "PLAY") {
+    createTimer(1000,  function(){
+        var ndrop = drop.clone();
+        //add code for random function here
+        var rainX = random(760,40);
+
+        //add code for ndrop.x() here
+        ndrop.x(rainX);
+        ndrop.y(10);
+    });
+}

+ 22 - 0
yellow/01-04

@@ -0,0 +1,22 @@
+//Scene - Initialize When Scene Starts
+//Raindrop is from the last activity, we have
+//moved it to the scene 
+if($this.scene.state() == "PLAY"){
+    createTimer(1000, function(){
+        var ndrop = drop.clone();
+        var rainx = random(760,40);
+        ndrop.x(rainx);
+        ndrop.y(10);
+    });
+//Lightning bolt cloning is very much the same
+//as cloning the rain drop    
+    createTimer(5000, function(){
+        //insert clone code here
+        var nbolt = bolt.clone();
+        var boltX = random(760,40);
+        nbolt.x(boltX);
+        nbolt.y(10);
+        
+        
+    });
+}

+ 27 - 0
yellow/01-05

@@ -0,0 +1,27 @@
+//turtleSprite - Initialize When Scene Starts
+//raindrop cloning
+if($this.scene.state() == "PLAY"){
+    createTimer(1000,  function(){
+    var ndrop = drop.clone();
+    var rainX = random(760,40);
+    ndrop.x(rainX);
+    ndrop.y(10); 
+    });
+//lightning bolt cloning    
+    createTimer(5000, function(){
+        var nbolt = bolt.clone();
+        var boltx = random(760,40);
+        nbolt.x(boltx);
+        nbolt.y(10);
+    });
+//This code will be new - but still the same as the last 2 activities
+//snowflake cloning    
+    //Add createTimer function for snowflake here
+    createTimer(5000, function() {
+        var nflake = snowflake.clone();
+        var flakeX = random(760,40);
+        nflake.x(flakeX);
+        nflake.y(10);
+    });
+
+}

+ 14 - 0
yellow/01-06

@@ -0,0 +1,14 @@
+//bucket - Update Every Frame
+// if the bucket's powerup  equals "frozen" 
+// OR if the timer equals null
+if ( $this.powerup == "frozen" || $this.timer === null ) {
+    //change the color of the bucket to blue 
+    $this.fill("#0000FF");
+    $this.timer = createTimer(2000, function() { 
+        // after 2 seconds, powerup is null
+        $this.powerup = null;
+}, false );
+} else if ( $this.powerup === null) {
+    //change bucket color back to grey
+    $this.fill("#BBBBBB");
+}

+ 55 - 0
yellow/02-01

@@ -0,0 +1,55 @@
+//rocket - Update Every Frame
+//set up all keypress variables
+var leftPressed = isKeyPressed(Keys.leftArrow);
+var rightPressed = isKeyPressed(Keys.rightArrow);
+var upPressed = isKeyPressed(Keys.upArrow);
+var spacePressed = isKeyPressed(Keys.space);
+var bullet =  $this.findName("bullet");
+
+//keypress conditionals
+if(spacePressed){
+   //bullet.moving = true;
+   if(!$this.scene.projectile)
+   {
+       var b = bullet.clone(true, true, $this.scene);
+
+       b.x(bullet.getStagePos().x);
+       b.y(bullet.getStagePos().y);
+       b.rotation($this.rotation());
+       b.moving = true;
+       b.z(1000);
+       
+       $this.scene.projectile = b;
+   }
+   
+}
+
+if(upPressed){
+    $this.moveForwardByRotation();
+}
+if(leftPressed){
+    $this.spin(-40);
+}
+if(rightPressed){
+    $this.spin(40);
+}
+
+//
+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);
+}
+//meteor - Initialize When Scene Starts
+var rot = random(359);
+$this.rotation(rot);

+ 43 - 0
yellow/02-02

@@ -0,0 +1,43 @@
+//meteor - Update Every Frame
+moveX($this);
+moveY($this);
+
+var bullet = $this.scene.projectile;
+
+if(bullet && $this.isTouching(bullet)){
+    
+    $this.scaleX($this.scaleX()/2);
+    $this.scaleY($this.scaleY()/2);
+    $this.offsetX($this.offsetX()/2);
+    $this.offsetY($this.offsetY()/2);
+    
+    $this.scene.projectile = null;
+    bullet.remove();
+    
+    $this.scene.scoreValue++;
+    score.text("Score: "+$this.scene.scoreValue);
+    //this is where you add the code in step 3, inside the if ($this.isTouching(bullet)) statement
+    //Good place to have ninja explain what this code is doing
+    if (this.scaleX() >= 0.25) {
+        var ncircle = $this.clone();
+        ncircle.x($this.x()+100);
+    } else {
+        $this.remove();
+    }
+}
+
+if($this.y()>700){
+    $this.y(0);
+}
+
+if($this.y()<-100){
+    $this.y(600);
+}
+
+if($this.x()>900){
+    $this.x(0);
+}
+
+if($this.x()<-100){
+    $this.x(800);
+}

+ 11 - 0
yellow/03-01

@@ -0,0 +1,11 @@
+//Scene Object: Initialize When Scene Starts Event
+ninja.toggleVisible(); //we are exploring booleans, toggles are like light switches, it is either on or off
+
+if($this.scene.state()=="PLAY"){
+    var ninjaTime1=random(3000,1000);
+    createTimer(ninjaTime1,function(){
+        ninja.toggleVisible(); //since we are switching it off when we start the game, this timer is turning it off
+        
+    });
+    
+}

+ 34 - 0
yellow/03-02

@@ -0,0 +1,34 @@
+//ninja1 - Mouse Click Event
+//for the teaching, we want to ask ninjas what we want to happen
+//next we need to know when we want it to happen
+//and how will we make this happen -- try to ilicit if() 
+//should only happen IF ninja is visible
+if($this.visible()){
+    //if the ninja is visible, we'll do the following:
+    $this.toggleVisible();
+    $this.scene.score+=1;
+    lblScore.text($this.scene.score);
+    
+}
+
+//Scene - initialize when scene starts
+$this.score = 0;
+//following code is pre-populated:
+if($this.scene.state() == "PLAY"){
+    var ninjaTime1 = random(3000, 1000)
+  createTimer(ninjaTime1,  function(){
+        ninja_1.toggleVisible();
+    });  
+    var ninjaTime2 = random(3000, 1000)
+  createTimer(ninjaTime2,  function(){
+        ninja_2.toggleVisible();
+    });
+    var ninjaTime3 = random(3000, 1000)
+  createTimer(ninjaTime3,  function(){
+        ninja_3.toggleVisible();
+    });
+    var ninjaTime4 = random(3000, 1000)
+  createTimer(ninjaTime4,  function(){
+        ninja_4.toggleVisible();
+    });
+}

+ 58 - 0
yellow/03-03

@@ -0,0 +1,58 @@
+//Score decreases when background is clicked
+//Background Object - Mouse Click Event
+$this.scene.score -= 1;
+score.text($this.scene.score);
+
+//Scene - Initialize When Scene Starts
+if($this.scene.state() == "PLAY") {
+    ninja_1.visible(false);
+    ninja_2.visible(false);
+    ninja_3.visible(false);
+    ninja_4.visible(false);
+
+    var ninjaTime1 = random(3000,1000);
+    createTimer(ninjaTime1, function(){
+        if (ninja_1.visible()) {
+            ninja_1.visible(false);
+        } else {
+            ninja_1.visible(true);
+        }
+    });
+
+    var ninjaTime2 = random(3000,1000);
+    createTimer(ninjaTime1, function(){
+        if (ninja_2.visible()) {
+            ninja_2.visible(false);
+        } else {
+            ninja_2.visible(true);
+        }
+    });
+
+    var ninjaTime3 = random(3000,1000);
+    createTimer(ninjaTime1, function(){
+        if (ninja_3.visible()) {
+            ninja_3.visible(false);
+        } else {
+            ninja_3.visible(true);
+        }
+    });
+
+    var ninjaTime4 = random(3000,1000);
+    createTimer(ninjaTime4, function(){
+        if (ninja_4.visible()) {
+            ninja_4.visible(false);
+        } else {
+            ninja_4.visible(true);
+        }
+    });
+
+    var ninjaTime5 = random(3000,1000);
+    createTimer(ninjaTime5, function(){
+        if (ninja_5.visible()) {
+            ninja_5.visible(false);
+        } else {
+            ninja_5.visible(true);
+        }
+    });
+
+    }

+ 41 - 0
yellow/PY-RollingDice

@@ -0,0 +1,41 @@
+//Scene - Initialize when Scene Starts
+$this.dieClick=false;
+
+//totalText does not need to be called from $this.scene
+//We can access totalText just by totalText.text()  
+
+//Scene - Update Every Frame
+if($this.scene.dieClick){
+    var roll1=Math.round(random(5));
+    var roll2=Math.round(random(5));
+    die1.frameIndex(roll1);
+    die2.frameIndex(roll2);
+    //2 is added to the total since each die roll is off by 1. 
+    totalText.text(roll1+roll2+2);
+    $this.scene.dieClick=false;
+}
+
+//die1 and die2 Objects: Mouse Click Events
+if(!$this.scene.dieClick){
+    $this.scene.dieClick=true;
+}
+
+//alternate solution
+//die1 - Mouse Click Event
+//Use random() to generate numbers to simulate die roll. 
+//Good place to teach ninjas about the possible numbers when running random(5) - 0,1,2,3,4,5
+//This happens to coincide with the frame indexes for the die values 
+var roll1 = Math.round(random(5));
+var roll2 = Math.round(random(5));
+//Show ninjas how we will use the variables to make the numbers that we generated match
+die1.frameIndex(roll1);
+die2.frameIndex(roll2);
+
+var total = roll1+roll2+2; //good to show how to use another variable to store the total. Don't add 2 to start
+//Good place to start by showing how we can update the total by hard coding the number into the .text()
+//After we do the generation of values above and store the total into its own variable, we can use the 
+//total instead of hardcoding the number
+totalText.text(total);
+//Ask what is wrong with the game at the moment without adding 2 to the total
+//We're using index values so it includes 0, how do we fix this? 
+//We should +2 to the total