joemckay

Untitled

Apr 5th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. Cannon c = new Cannon(400.0);
  2. ArrayList<CannonLaser> lasers = new ArrayList(5);
  3. int laserCount=5;
  4. void setup() {
  5. size(600, 800);
  6. smooth();
  7. }
  8.  
  9. void draw() {
  10. background(255);
  11. c.show();
  12. for (int i = lasers.size()-1; i >= 0; i--) {
  13. CannonLaser dLaser = lasers.get(i);
  14. dLaser.show();
  15. }
  16. }
  17. void keyPressed() {
  18. if (keyCode==LEFT)
  19. c.move(0);
  20. else if (keyCode==RIGHT) c.move(1);
  21. else if (keyCode==32) {
  22. lasers.add(new CannonLaser(c.px, c.py, 20));
  23. }
  24. }
  25.  
  26. class Cannon {
  27. float turret=85;
  28. float position;
  29. float px;
  30. float py;
  31. int moveSpeed = 5;
  32. CannonLaser l;
  33.  
  34. public Cannon(float p) {
  35. position = p;
  36. }
  37.  
  38. void show() {
  39. ellipseMode(CENTER);
  40. fill(0);
  41. stroke(128);
  42. ellipse(position, height, 100, 100);
  43. strokeWeight(20);
  44. stroke(0);
  45. py = height-turret;
  46. px = position;
  47. line(position, height, px, py);
  48. }
  49.  
  50. void move(int direction) {
  51. if (direction == 0)
  52. position = position-moveSpeed;
  53. else if (direction==1)
  54. position = position+moveSpeed;
  55. }
  56. }
  57.  
  58. class CannonLaser {
  59. boolean fired = false;
  60. float px;
  61. float py;
  62. float velocity;
  63.  
  64. CannonLaser(float x, float y, float v) {
  65. px = x;
  66. py = y;
  67. velocity = v;
  68. fired=true;
  69. }
  70.  
  71. // Move the Ball vertically up the screen
  72. void move() {
  73. py = py-velocity;
  74. }
  75.  
  76. // Make the Ball visable
  77. void show() {
  78. move();
  79. ellipse(px, py, 5, 5);
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment