02-02-meteors-pt2.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //meteor - Update Every Frame
  2. //Code below is given up to the next comment where ninjas add to code to "make the game more interesting"
  3. //Should also talk about where in the game the score is being added.
  4. moveX($this);
  5. moveY($this);
  6. var bullet = $this.scene.projectile;
  7. if(bullet && $this.isTouching(bullet)){
  8. $this.scaleX($this.scaleX()/2);
  9. $this.scaleY($this.scaleY()/2);
  10. $this.offsetX($this.offsetX()/2);
  11. $this.offsetY($this.offsetY()/2);
  12. $this.scene.projectile = null;
  13. bullet.remove();
  14. $this.scene.scoreValue++;
  15. score.text("Score: "+$this.scene.scoreValue);
  16. //this is where you add the code in step 3, inside the if ($this.isTouching(bullet)) statement
  17. //Good place to have ninja explain what this code is doing
  18. //Review conditionals and comparison operators
  19. //Remember that this section is all about Math
  20. //Draw the connections between math and computer science - math is definitely important in game dev!
  21. if (this.scaleX() >= 0.25) {
  22. var ncircle = $this.clone();
  23. ncircle.x($this.x()+100);
  24. } else {
  25. $this.remove();
  26. }
  27. }
  28. //Ask the ninja what this code is doing
  29. //It is given to us but we should know what it is doing.
  30. //They've seen this code in Hungry Ninja,
  31. //The follow code resets the position of the meteor when he flies off the screen.
  32. if($this.y()>700){
  33. $this.y(0);
  34. }
  35. if($this.y()<-100){
  36. $this.y(600);
  37. }
  38. if($this.x()>900){
  39. $this.x(0);
  40. }
  41. if($this.x()<-100){
  42. $this.x(800);
  43. }