|
|
@@ -0,0 +1,92 @@
|
|
|
+//****************** Scene Object - Initialize When Scene Starts Event*********//
|
|
|
+$this.resetShuriken = function () {
|
|
|
+ // deactivate and hide the shuriken
|
|
|
+ shuriken.active = false;
|
|
|
+ shuriken.visible(false);
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+$this.generateCloud = function() {
|
|
|
+ // clone the cloud object
|
|
|
+ var cloudClone = cloud.clone();
|
|
|
+ // position it off the screen
|
|
|
+ // with a random x
|
|
|
+ cloudClone.x(random(100, 700));
|
|
|
+ cloudClone.y(0);
|
|
|
+};
|
|
|
+
|
|
|
+$this.throwShuriken = function() {
|
|
|
+ // move the shuriken to the ninja
|
|
|
+ shuriken.x(ninja.x());
|
|
|
+ shuriken.y(ninja.y());
|
|
|
+ // activate it and make it visible
|
|
|
+ shuriken.active = true;
|
|
|
+ shuriken.visible(true);
|
|
|
+};
|
|
|
+
|
|
|
+if ($this.scene.state() == "PLAY") {
|
|
|
+ // set up score varible
|
|
|
+ $this.score = 0;
|
|
|
+ // initialize the shuriken
|
|
|
+ $this.resetShuriken();
|
|
|
+ // every 3 seconds, generate new cloud
|
|
|
+ createTimer(3000, function() {
|
|
|
+ $this.generateCloud();
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+//********************* ninja Object - Update Every Frame Event*******************//
|
|
|
+$this.incrementAnimation();
|
|
|
+
|
|
|
+// move the ninja left
|
|
|
+if (isKeyPressed(Keys.leftArrow)) {
|
|
|
+ $this.moveX(-100);
|
|
|
+}
|
|
|
+
|
|
|
+// move the ninja right
|
|
|
+if (isKeyPressed(Keys.rightArrow)) {
|
|
|
+ $this.moveX(100);
|
|
|
+}
|
|
|
+
|
|
|
+// if the spacebar is pressed
|
|
|
+// and if the shuriken is not active
|
|
|
+if (isKeyPressed(Keys.space) && !shuriken.active) {
|
|
|
+ $this.scene.throwShuriken();
|
|
|
+}
|
|
|
+
|
|
|
+//*********************shuriken Object - Update Every Frame Event*****************//
|
|
|
+// move the shuriken if it's active
|
|
|
+if ($this.active) {
|
|
|
+ $this.moveY();
|
|
|
+}
|
|
|
+
|
|
|
+// if it flies off the screen
|
|
|
+// reset it
|
|
|
+if ($this.y() <= 0) {
|
|
|
+ $this.scene.resetShuriken();
|
|
|
+}
|
|
|
+
|
|
|
+//**********************cloud Object - Update Every Frame Event ******************//\
|
|
|
+// always move the cloud
|
|
|
+$this.moveY();
|
|
|
+
|
|
|
+// remove the cloud if it reaches the top of the screen
|
|
|
+if ($this.y() < 0) {
|
|
|
+ // increase the score after every cleared cloud
|
|
|
+ $this.scene.score += 10;
|
|
|
+ scoreLabel.text($this.scene.score);
|
|
|
+ $this.remove();
|
|
|
+}
|
|
|
+
|
|
|
+// end game if the cloud reaches the bottom of the screen
|
|
|
+if (this.y() >= 500) {
|
|
|
+ $this.scene.stopCode();
|
|
|
+}
|
|
|
+
|
|
|
+// if the cloud touches an active shuriken
|
|
|
+if (shuriken.active && $this.isTouching(shuriken)) {
|
|
|
+ // push cloud up
|
|
|
+ $this.y($this.y() - 200);
|
|
|
+ // reset the shuriken
|
|
|
+ $this.scene.resetShuriken();
|
|
|
+}
|