Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. PImage alienImg;
  2. PImage explodeImg;
  3. int x = 0;
  4. int count = 0;
  5. int y = 0;
  6. int direction = 0;
  7. Alien theAlien[];
  8. Player thePlayer;
  9. int speed = millis()/500;
  10. ArrayList<Bullet> theBullets;
  11. ArrayList<Bomb> theBomb;
  12.  
  13. void setup() {
  14. size(400, 400);
  15. alienImg= loadImage("spacer.gif");
  16. explodeImg= loadImage("exploding.gif");
  17. thePlayer = new Player(SCREENY-MARGIN-PADDLEHEIGHT);
  18. theAlien = new Alien[10];
  19. init_aliens(theAlien, alienImg, explodeImg);
  20. theBullets = new ArrayList<Bullet>();
  21. theBomb = new ArrayList<Bomb>();
  22. }
  23. void init_aliens ( Alien aliens[], PImage spaceImage, PImage expImage )
  24. {
  25. for (int i =0; i < aliens.length; i++)
  26. {
  27. aliens[i] = new Alien(i*(spaceImage.width), 0, spaceImage, expImage);
  28. }
  29. }
  30.  
  31. void draw() {
  32. background(255);
  33. noStroke();
  34. for (int i=0; i < theBomb.size(); i++)
  35. {
  36. Bomb thisBomb = theBomb.get(i);
  37. thisBomb.move();
  38. thisBomb.draw();
  39. }
  40. for (int i=0; i < theBomb.size(); i++)
  41. {
  42. Bomb thatBomb = theBomb.get(i);
  43. if (thatBomb.checkCollision(thatBomb.x, thatBomb.y, thatBomb.x + BOMBDIMENSIONS, thatBomb.y + BOMBDIMENSIONS, int(thePlayer.xpos), thePlayer.ypos, int(thePlayer.xpos + PADDLEWIDTH), thePlayer.ypos + PADDLEHEIGHT))
  44. {
  45. text("Game Over", 150, 150, 100);
  46. noLoop();
  47. }
  48. }
  49. for (int i=0; i < theBomb.size(); i++)
  50. {
  51. Bomb aBomb = theBomb.get(i);
  52. if(aBomb.offScreen(aBomb.y))
  53. {
  54. theBomb.remove(i);
  55. println(theBomb.size());
  56. }
  57. }
  58. speed = millis()/10000;
  59. thePlayer.draw();
  60. thePlayer.move(mouseX);
  61. for (int i=0; i < theAlien.length; i++) {
  62. theAlien[i].move();
  63. theAlien[i].draw();
  64. //if (random(0, 400)<1)theAlien[i].die();
  65. }
  66.  
  67. for (int i = 0; i < theBullets.size(); i++)
  68. {
  69. Bullet thisBullet = theBullets.get(i);
  70. thisBullet.move();
  71. thisBullet.draw();
  72.  
  73. for (int j = 0; j < theAlien.length; j++)
  74. {
  75. if (rectsCollide(thisBullet.x, thisBullet.y, thisBullet.x+5, thisBullet.y+5, theAlien[j].x, theAlien[j].y, theAlien[j].x+25, theAlien[j].y+25))
  76. {
  77. theAlien[j].die();
  78. }
  79. }
  80. //for(int k = -1; i < theAlien.length;k++)
  81. //{
  82. // int counter = 0;
  83. // if(theAlien[k].currentStatus == DEAD)
  84. // {
  85. // counter++;
  86. // if(counter == 10)
  87. // {
  88. // text("you win", 150, 150, 50);
  89. // noLoop();
  90. // }
  91. // }
  92. // counter = 0;
  93. //}
  94. }
  95. }
  96.  
  97. boolean rectsCollide(int tl1x, int tl1y, int br1x, int br1y, int tl2x, int tl2y, int br2x, int br2y)
  98. {
  99. if (tl1x > br2x || br1x < tl2x)
  100. {
  101. return false;
  102. }
  103. if (tl1y > br2y || br1y < tl2y)
  104. {
  105. return false;
  106. }
  107. return true;
  108. }
  109.  
  110. void mouseClicked()
  111. {
  112. theBullets.add(new Bullet(int(thePlayer.xpos+PADDLEWIDTH/2), thePlayer.ypos));
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement