02-01 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. if(spacePressed){
  10. //bullet.moving = true;
  11. if(!$this.scene.projectile)
  12. {
  13. var b = bullet.clone(true, true, $this.scene);
  14. b.x(bullet.getStagePos().x);
  15. b.y(bullet.getStagePos().y);
  16. b.rotation($this.rotation());
  17. b.moving = true;
  18. b.z(1000);
  19. $this.scene.projectile = b;
  20. }
  21. }
  22. if(upPressed){
  23. $this.moveForwardByRotation();
  24. }
  25. if(leftPressed){
  26. $this.spin(-40);
  27. }
  28. if(rightPressed){
  29. $this.spin(40);
  30. }
  31. //
  32. if($this.y()>600){
  33. $this.y(0);
  34. }
  35. if($this.y()<0){
  36. $this.y(600);
  37. }
  38. if($this.x()>800){
  39. $this.x(0);
  40. }
  41. if($this.x()<0){
  42. $this.x(800);
  43. }
  44. //meteor - Initialize When Scene Starts
  45. var rot = random(359);
  46. $this.rotation(rot);