02-02-meteors-pt2.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. /**
  17. This is where you add the code in step 3, inside the if ($this.isTouching(bullet)) statement
  18. Good place to have ninja explain what this code is doing
  19. Review conditionals and comparison operators
  20. Remember that this section is all about Math
  21. Draw the connections between math and computer science - math is definitely important in game dev!
  22. **/
  23. if (this.scaleX() >= 0.25) {
  24. var ncircle = $this.clone();
  25. ncircle.x($this.x()+100);
  26. } else {
  27. $this.remove();
  28. }
  29. }
  30. //Ask the ninja what this code is doing
  31. //It is given to us but we should know what it is doing.
  32. //They've seen this code in Hungry Ninja,
  33. //The follow code resets the position of the meteor when he flies off the screen.
  34. if($this.y()>700){
  35. $this.y(0);
  36. }
  37. if($this.y()<-100){
  38. $this.y(600);
  39. }
  40. if($this.x()>900){
  41. $this.x(0);
  42. }
  43. if($this.x()<-100){
  44. $this.x(800);
  45. }