Quellcode durchsuchen

Add What's Inside

michtang vor 3 Jahren
Ursprung
Commit
0a267eb9f9
2 geänderte Dateien mit 84 neuen und 0 gelöschten Zeilen
  1. 21 0
      02-yellow/03-04-ninja-supplies.js
  2. 63 0
      02-yellow/03-05-PY-whats-inside.js

+ 21 - 0
02-yellow/03-04-ninja-supplies.js

@@ -1,5 +1,6 @@
 //Multiple toggle effects and mouse click events 
 //so game could be buggy
+//Buggy on Brave Browser, use Chrome
 
 //Sword Object - Mouse Button Up Event
 if ($this.isTouching(ninja)) { 
@@ -9,4 +10,24 @@ if ($this.isTouching(ninja)) {
 } else { 
     // otherwise, return sword to pile. 
     $this.x(672); $this.y(314); 
+}
+
+//Star Object - Mouse Button Up Event
+if ($this.isTouching(ninja)) { 
+    $this.remove(); // remove the original star 
+    staff.toggleDraggable(); // make the star draggable 
+    starIcon.toggleVisible(); // make the star icon visible 
+} else { 
+    // otherwise, return the star to the pile 
+    $this.x(492); $this.y(372); 
+}
+
+//Staff Object - Mouse Button Up Event
+if ($this.isTouching(ninja)) { 
+    $this.remove(); // remove the original staff 
+    staff.toggleDraggable(); // make the staff dragable 
+    staffIcon.toggleVisible(); // makes the staff icon visible 
+} else { 
+    // otherwise, return the staff to the pile 
+    $this.x(650); $this.y(346); 
 }

+ 63 - 0
02-yellow/03-05-PY-whats-inside.js

@@ -0,0 +1,63 @@
+//Core solution - simplified
+//Scene - Initialize When Scene Starts 
+//Open doors need to be set to invisible
+openDoor1.visible(false);
+openDoor2.visible(false);
+openDoor3.visible(false);
+openDoor4.visible(false);
+
+//Door should open when clicked
+//We should talk the logic out with the ninja before we code
+//pseudo code is a great idea
+
+//open doors don't have underscores but closed doors have it
+
+//door_1 - Mouse Click Event
+//Check if it's closed, if it is, the sprite is visible
+if ($this.visible()) {
+    $this.visible(false); //we'll hide it when it's clicked
+    openDoor1.visible(true); //show the openDoor sprite
+    //card image generation - should be consistent with how 
+    //Rolling Dice is taught even though it is possible to do 
+    //this in one line, Math.round() isn't needed
+    var randomImage = random(1,8); //pick a number between 1 and 8 
+    card_1.frameIndex(randomImage); //update the card with the image
+} else { //don't need else 
+    // Otherwise the door is somehow already open 
+    // it would be showing the card so we can't click it.
+}
+
+//openDoor1 - Mous Click Event
+//Check if it's open, if it is, this sprite is visible
+if($this.visible()) {
+    $this.visible(false); //hide openDoor when clicked
+    door_1.visible(true); //show the door_1 sprite
+} else { //don't need else
+    //Otherwise, the openDoor is alredy hidden, 
+    //so we wouldn't be able to click it anyways.
+}
+
+//Above should be the base code, after that we can tackle the objective 
+//to only allow one door open at a time
+
+//CN Sensei Guide Solution
+
+// door_x - Mouse Click Events
+if ($this.visible()) { 
+    //reset all the doors 
+    openDoor1.visible(false); 
+    openDoor2.visible(false); 
+    openDoor3.visible(false); 
+    openDoor4.visible(false); 
+    door_1.visible(true); 
+    door_2.visible(true); 
+    door_3.visible(true); 
+    door_4.visible(true); 
+    $this.visible(false); //this is the code from base code above
+    //New part of this solution is the reset code
+    //this part is unique for each door 
+    //openDoor1 and card_1 are changed to their corresponding 
+    //door number, so openDoor3 and card_3 are on door_3 
+    openDoor1.visible(true); 
+    card_1.frameIndex(random(1, 8)); 
+}