| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- /**
- 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);
|