Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage alienImg;
- PImage explodeImg;
- int x = 0;
- int count = 0;
- int y = 0;
- int direction = 0;
- Alien theAlien[];
- Player thePlayer;
- int speed = millis()/500;
- ArrayList<Bullet> theBullets;
- ArrayList<Bomb> theBomb;
- void setup() {
- size(400, 400);
- alienImg= loadImage("spacer.gif");
- explodeImg= loadImage("exploding.gif");
- thePlayer = new Player(SCREENY-MARGIN-PADDLEHEIGHT);
- theAlien = new Alien[10];
- init_aliens(theAlien, alienImg, explodeImg);
- theBullets = new ArrayList<Bullet>();
- theBomb = new ArrayList<Bomb>();
- }
- void init_aliens ( Alien aliens[], PImage spaceImage, PImage expImage )
- {
- for (int i =0; i < aliens.length; i++)
- {
- aliens[i] = new Alien(i*(spaceImage.width), 0, spaceImage, expImage);
- }
- }
- void draw() {
- background(255);
- noStroke();
- for (int i=0; i < theBomb.size(); i++)
- {
- Bomb thisBomb = theBomb.get(i);
- thisBomb.move();
- thisBomb.draw();
- }
- for (int i=0; i < theBomb.size(); i++)
- {
- Bomb thatBomb = theBomb.get(i);
- 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))
- {
- text("Game Over", 150, 150, 100);
- noLoop();
- }
- }
- for (int i=0; i < theBomb.size(); i++)
- {
- Bomb aBomb = theBomb.get(i);
- if(aBomb.offScreen(aBomb.y))
- {
- theBomb.remove(i);
- println(theBomb.size());
- }
- }
- speed = millis()/10000;
- thePlayer.draw();
- thePlayer.move(mouseX);
- for (int i=0; i < theAlien.length; i++) {
- theAlien[i].move();
- theAlien[i].draw();
- //if (random(0, 400)<1)theAlien[i].die();
- }
- for (int i = 0; i < theBullets.size(); i++)
- {
- Bullet thisBullet = theBullets.get(i);
- thisBullet.move();
- thisBullet.draw();
- for (int j = 0; j < theAlien.length; j++)
- {
- 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))
- {
- theAlien[j].die();
- }
- }
- //for(int k = -1; i < theAlien.length;k++)
- //{
- // int counter = 0;
- // if(theAlien[k].currentStatus == DEAD)
- // {
- // counter++;
- // if(counter == 10)
- // {
- // text("you win", 150, 150, 50);
- // noLoop();
- // }
- // }
- // counter = 0;
- //}
- }
- }
- boolean rectsCollide(int tl1x, int tl1y, int br1x, int br1y, int tl2x, int tl2y, int br2x, int br2y)
- {
- if (tl1x > br2x || br1x < tl2x)
- {
- return false;
- }
- if (tl1y > br2y || br1y < tl2y)
- {
- return false;
- }
- return true;
- }
- void mouseClicked()
- {
- theBullets.add(new Bullet(int(thePlayer.xpos+PADDLEWIDTH/2), thePlayer.ypos));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement