02-shuriken-dodge.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /**
  2. Initial Set up:
  3. * Add shuriken from assets
  4. * Add Label - pointsLabel and set text to 0
  5. */
  6. //**********************Scene Object - Initialize When Scene Starts*****************//
  7. // start the game with 0 points
  8. $this.points = 0 ; //set points variable to 0
  9. $this.spawnShuriken = function () {
  10. // clone the original shuriken object
  11. var clonedShuriken = shuriken. clone ();
  12. // create a random number
  13. // change the clone's x position
  14. var randomX = random (0 , 800 );
  15. clonedShuriken.x (randomX);
  16. // set the clone's y position to 0
  17. clonedShuriken.y (0);
  18. // change the speed based on points
  19. clonedShuriken. speedY (40 + $this.points * 5);
  20. } ;
  21. if ($this.scene.state () == "PLAY" ) {
  22. createTimer (1000 , $this.spawnShuriken);
  23. }
  24. //*********************shuriken Object - Update Every Frame Event********************//
  25. moveY($this);
  26. // if the shuriken touches the ground
  27. if ($this.isTouching(ground)) {
  28. // add one point and update the label
  29. $this.scene.points += 1;
  30. pointsLabel.text($this.scene.points);
  31. // remove the shuriken
  32. $this.remove();
  33. }
  34. // if the shuriken touches the avatar ninja
  35. if ($this.isTouching (avatar)) {
  36. // stop the game's code execution
  37. $this.scene.stopCode();
  38. }
  39. //************************shuriken Object - Initialize When Scene Starts Event**********//
  40. $this.speedY(50);