Advertisement
Guest User

shooting game code: qwerty

a guest
Jul 1st, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.44 KB | None | 0 0
  1. //GAME
  2. package game;
  3.  
  4. import processing.core.PApplet;
  5. import processing.core.PImage;
  6.  
  7.  
  8. public class Spaceship extends PApplet
  9. {
  10. /**
  11. *
  12. */
  13. private static final long serialVersionUID = 1L;
  14. private static final char[] WOOOOOOOSH = null;
  15. public float distance;
  16. public float rotationAmount = 0;
  17. public boolean rotateLeft = false;
  18. public boolean rotateRight = false;
  19. public boolean shootBullet = false;
  20.  
  21. public float speed = 11;
  22.  
  23. public float x = 400;
  24. public float y = 350;
  25.  
  26. public boolean moveForward = false;
  27.  
  28. public boolean moving = false;
  29.  
  30. public void setup()
  31. {
  32. size(800, 700);
  33. }
  34.  
  35. public void draw()
  36. {
  37. background(142, 133, 133);
  38.  
  39. //Move and control the rocket ship.
  40. move();
  41. changeRotation();
  42. translate(x, y);
  43. rotate(rotationAmount);
  44. drawRocketShip();
  45. shoot();
  46.  
  47. }
  48.  
  49. //Set up and draw the rocket ship.
  50. public int rocketX = 0;
  51. public int rocketY = 0;
  52.  
  53.  
  54. public void drawRocketShip()
  55. {
  56. //Body color.
  57. stroke(0, 149, 185);
  58. fill(0, 149, 185);
  59.  
  60. //Body
  61. rect(rocketX, rocketY, -75/2, 50/2);
  62. rect(rocketX, rocketY, 75/2, -50/2);
  63. rect(rocketX, rocketY, -75/2, -50/2);
  64. rect(rocketX, rocketY, 75/2, 50/2);
  65.  
  66. //GunsRight
  67. fill(0, 149, 185);
  68. rect(-2, -2, 10, 45);
  69. rect(-10, 35, 55, 10);
  70. fill(180, 0, 0);
  71. rect(40, 35, 5, 10);
  72. rect(-15, 35, 5, 10);
  73.  
  74. //GunLeft
  75. fill(0, 149, 185);
  76. rect(-2, -45, 10, 45);
  77. fill(0, 149, 185);
  78. rect(-10, -45, 55, 10);
  79. fill(180, 0, 0);
  80. rect(40, -45, 5, 10);
  81. rect(-15, -45, 5, 10);
  82.  
  83. //front
  84. fill(170, 0, 0);
  85. rect(10, 0, 2, 2);
  86.  
  87. //window color
  88. fill(255, 255, 255);
  89.  
  90. //window
  91. fill(180, 0, 0);
  92. ellipse(rocketX + 0, rocketY + 0, 30, 25);
  93. //wings
  94.  
  95. if(moving)
  96. {
  97. //Fire trail
  98. fill(255, 0, 0);
  99. noStroke();
  100. //triangle( 0, 0, rocketX - 30, rocketY + 25, rocketX - 10, rocketY + 40);
  101. }
  102. }
  103.  
  104. public void keyPressed()
  105. {
  106. if(key == 'a')
  107. {
  108. rotateLeft = true;
  109. }
  110. if(key == 'd')
  111. {
  112. rotateRight = true;
  113. }
  114. if(key == 'w')
  115. {
  116. moveForward = true;
  117. moving = true;
  118. }
  119. if(key == ' ')
  120. {
  121. shootBullet = true;
  122. distance += 30;
  123. }
  124.  
  125. }
  126.  
  127. public void keyReleased()
  128. {
  129. if(key =='a')
  130. {
  131. rotateLeft = false;
  132. }
  133. if(key == 'd')
  134. {
  135. rotateRight = false;
  136. }
  137. if(key == 'w')
  138. {
  139. moveForward = false;
  140. moving = false;
  141. }
  142. if(key == ' ')
  143. {
  144. shootBullet = false;
  145. distance=0;
  146. }
  147. }
  148.  
  149. public void move()
  150. {
  151. if(moveForward)
  152. {
  153. x += speed * cos(rotationAmount);
  154. y += speed * sin(rotationAmount);
  155. }
  156. }
  157. public void shoot()
  158. {
  159. if(shootBullet)
  160. {
  161. shot bullet = new shot(rocketX, rocketY);
  162. bullet.drawShot();
  163.  
  164.  
  165. fill(255, 128, 0);
  166.  
  167.  
  168.  
  169. ellipse(bullet.getXofShot() +60 + distance, bullet.getYofShot() +40, 10f, 10f);
  170. ellipse(bullet.getXofShot() +60 + distance, bullet.getYofShot() -40, 10f, 10f);
  171.  
  172. if(distance>50)
  173. {
  174. ellipse(bullet.getXofShot() +10 + distance, bullet.getYofShot() +40, 10f, 10f);
  175. ellipse(bullet.getXofShot() +10 + distance, bullet.getYofShot() -40, 10f, 10f);
  176. }
  177.  
  178. }
  179. }
  180. public void bullet()
  181. {
  182.  
  183. }
  184. public void changeRotation()
  185. {
  186. if(rotateLeft)
  187. {
  188. rotationAmount -= .08;
  189. if(rotationAmount < 0)
  190. {
  191. rotationAmount = 2 * PI;
  192. }
  193. }
  194. if(rotateRight)
  195. {
  196. rotationAmount += .08;
  197. if(rotationAmount > 2 * PI)
  198. {
  199. rotationAmount = 0;
  200. }
  201. }
  202. }
  203.  
  204.  
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement