04-07-ninja-battle.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /**
  2. This activity teaches the ninjas a new application of the pointToObject() function.
  3. **/
  4. //****************pcninja Object - Update Every Frame***************//
  5. var downArrowPressed = isKeyPressed(Keys.downArrow);
  6. if(downArrowPressed && $this.y() < 460){
  7. moveY($this);
  8. }
  9. var upArrowPressed = isKeyPressed(Keys.upArrow);
  10. if(upArrowPressed && $this.y() > 0){
  11. moveY($this, -$this.speedY());
  12. }
  13. //******************star Object - Update Every Frame***************//
  14. if($this.thrown){
  15. $this.moveForward(10);
  16. }
  17. // Bonus
  18. if ($this.isTouching(pcninja) || $this.x() > 800 || $this.y() < 0 || $this.y() > 600) {
  19. $this.remove();
  20. } else if ($this.x() < 0) {
  21. $this.remove();
  22. $this.scene.score++;
  23. }
  24. //****************pcninja - Initialize When Scene Starts***********//
  25. if($this.scene.state() == "PLAY"){
  26. createTimer(5000, function(){
  27. var nstar = star.clone();
  28. nstar.x(682);
  29. nstar.y(304);
  30. nstar.thrown=true;
  31. nstar.pointToObject(pcninja);
  32. nstar.rotatoion(nstar.rotation()-90);
  33. });
  34. }
  35. //**********Scene Object - Initialize When Scene Starts**************//
  36. // BONUS
  37. if ($this.scene.state() == "PLAY") {
  38. $this.scene.score = 0;
  39. }
  40. //***************Scene Object - Update Every Frame******************//
  41. // BONUS
  42. score.text($this.scene.score);