13-PY-circus-bounce.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //*************Scene Object - Initialize When Scene Starts Event *********************//
  2. if ($this.scene.state() == "PLAY") {
  3. // initialize points
  4. $this.points = 0;
  5. // spawn a ninja every few seconds
  6. createTimer(2000, function() {
  7. // clone the ninja and give it a random x velocity
  8. var clonedNinja = ninja.clone();
  9. clonedNinja.velocityX = random(80,200);
  10. clonedNinja.velocityY = -50;
  11. // spawn the ninja off the left of the scene
  12. clonedNinja.x(-60);
  13. // give it a random y position
  14. clonedNinja.y(random(100, 300));
  15. });
  16. // after the timer is created, remove the original ninja
  17. ninja.remove();
  18. }
  19. //*******************trampoline Object - Update Every Frame *************************//
  20. $this.x(getMouseX() -190 / 2 );
  21. //*******************ninja Object - Update Every Frame*******************************//
  22. // spin the ninja every frame
  23. $this.spin(60);
  24. // change the y velocity due to gravity
  25. $this.velocityY += 4;
  26. // move the ninja based on its velocity
  27. $this.moveX($this.velocityX);
  28. $this.moveY($this.velocityY);
  29. // bounce the ninja
  30. if ($this.isTouching(trampoline)) {
  31. $this.velocityY = -300;
  32. }
  33. if($this.x() > 800) {
  34. $this.remove();
  35. $this.scene.points += 1;
  36. pointsLabel.text($this.scene.points);
  37. }
  38. if($this.y() > 600) {
  39. $this.scene.cleanupTimers();
  40. $this.scene.stopCode();
  41. }
  42. //