| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //*********************Scene - Initialize When Scene Starts Event******************//
- if ($this.scene.state() == "PLAY") {
- $this.peekSpeed = 100;
- $this.peekDistance = 250;
- $this.points = 0;
- createTimer(2000, $this.activateNinja);
- }
- $this.activateNinja = function() {
- //pick and find a random ninja
- var randomNumber = random(1,5);
- var chosenNinja = $this.findName("ninja" + randomNumber);
- //activate the chosen ninja and move it up
- chosenNinja.active = true;
- chosenNinja.speedY(-$this.peekSpeed);
- };
- //*******************ninja Object - Initialize When Scene Starts Event**************//
- $this.startingY = $this.y();
- $this.stoppingY = $this.startingY - $this.scene.peekDistance;
- //********************ninja Objects - Update Every Frame Event**********************//
- if($this.active) { // important that the closing brace is at the very end, otherwise,
- //we'll lose score even when ninja is not active
- //move ninja up if it's active
- moveY($this);
- //if ninja peeks all the way out, start going back down
- if($this.y() <= $this.stoppingY) {
- $this.speedY($this.scene.peekSpeed);
- }
- // stop ninja if it reaches its hiding spot
- // subtract a point, deactivate ninja
- if ($this.y() >= $this.startingY) {
- $this.speedY(0);
- $this.scene.points -= 1;
- score.text($this.scene.points);
- $this.active = false;
- }
- }
- //***************************ninja Object - Mouse Click Event***********************//
- //if ninja is active
- if ($this.active) {
- //deactivate
- $this.active = false;
- //move to starting location
- $this.y($this.startingY);
- //increase and update score
- $this.scene.points += 1;
- score.text($this.scene.points);
- }
|