02-01-meteors-pt-1.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. //rocket - Update Every Frame
  2. //set up all keypress variables
  3. var leftPressed = isKeyPressed(Keys.leftArrow);
  4. var rightPressed = isKeyPressed(Keys.rightArrow);
  5. var upPressed = isKeyPressed(Keys.upArrow);
  6. var spacePressed = isKeyPressed(Keys.space);
  7. var bullet = $this.findName("bullet");
  8. //keypress conditionals\
  9. //The following control the shooting and up arrow
  10. //controls which are pre-loaded.
  11. //The only code required is the code in the meteor
  12. if(spacePressed){
  13. //bullet.moving = true;
  14. if(!$this.scene.projectile)
  15. {
  16. var b = bullet.clone(true, true, $this.scene);
  17. b.x(bullet.getStagePos().x);
  18. b.y(bullet.getStagePos().y);
  19. b.rotation($this.rotation());
  20. b.moving = true;
  21. b.z(1000);
  22. $this.scene.projectile = b;
  23. }
  24. }
  25. if(upPressed){
  26. $this.moveForwardByRotation();
  27. }
  28. if(leftPressed){
  29. $this.spin(-40);
  30. }
  31. if(rightPressed){
  32. $this.spin(40);
  33. }
  34. //
  35. if($this.y()>600){
  36. $this.y(0);
  37. }
  38. if($this.y()<0){
  39. $this.y(600);
  40. }
  41. if($this.x()>800){
  42. $this.x(0);
  43. }
  44. if($this.x()<0){
  45. $this.x(800);
  46. }
  47. //meteor - Initialize When Scene Starts
  48. //Part 1 explores random() and this is a good
  49. //place to talk to the ninja about the random()
  50. //function as well as review how variables are used.
  51. var rot = random(359);
  52. $this.rotation(rot);