Exemple #1
0
  public void checkCollisions() {

    Rectangle r3 = craft.getBounds();

    for (int j = 0; j < aliens.size(); j++) {
      Alien a = (Alien) aliens.get(j);
      Rectangle r2 = a.getBounds();

      if (r3.intersects(r2)) {
        craft.setVisible(false);
        a.setVisible(false);
        ingame = false;
      }
    }

    ArrayList ms = craft.getMissiles();

    for (int i = 0; i < ms.size(); i++) {
      Missile m = (Missile) ms.get(i);

      Rectangle r1 = m.getBounds();

      for (int j = 0; j < aliens.size(); j++) {
        Alien a = (Alien) aliens.get(j);
        Rectangle r2 = a.getBounds();

        if (r1.intersects(r2)) {
          m.setVisible(false);
          a.setVisible(false);
        }
      }
    }
  }
Exemple #2
0
  private void doDrawing(Graphics g) {

    Graphics2D g2d = (Graphics2D) g;
    g2d.drawImage(craft.getImage(), craft.getX(), craft.getY(), this);
    ArrayList<Missile> ms = craft.getMissiles();
    for (Missile missible : ms) {
      g2d.drawImage(missible.getImage(), missible.getX(), missible.getY(), this);
    }
  }
 public boolean addActiveVessel(Craft aActiveVessel) {
   boolean wasAdded = false;
   if (activeVessels.contains(aActiveVessel)) {
     return false;
   }
   CanalNetwork existingCanalNetwork = aActiveVessel.getCanalNetwork();
   if (existingCanalNetwork == null) {
     aActiveVessel.setCanalNetwork(this);
   } else if (!this.equals(existingCanalNetwork)) {
     existingCanalNetwork.removeActiveVessel(aActiveVessel);
     addActiveVessel(aActiveVessel);
   } else {
     activeVessels.add(aActiveVessel);
   }
   wasAdded = true;
   return wasAdded;
 }
 public boolean removeActiveVessel(Craft aActiveVessel) {
   boolean wasRemoved = false;
   if (activeVessels.contains(aActiveVessel)) {
     activeVessels.remove(aActiveVessel);
     aActiveVessel.setCanalNetwork(null);
     wasRemoved = true;
   }
   return wasRemoved;
 }
Exemple #5
0
  public void paint(Graphics g) {
    super.paint(g);

    if (ingame) {

      Graphics2D g2d = (Graphics2D) g;

      if (craft.isVisible()) g2d.drawImage(craft.getImage(), craft.getX(), craft.getY(), this);

      ArrayList ms = craft.getMissiles();

      for (int i = 0; i < ms.size(); i++) {
        Missile m = (Missile) ms.get(i);
        g2d.drawImage(m.getImage(), m.getX(), m.getY(), this);
      }

      for (int i = 0; i < aliens.size(); i++) {
        Alien a = (Alien) aliens.get(i);
        if (a.isVisible()) g2d.drawImage(a.getImage(), a.getX(), a.getY(), this);
      }

      g2d.setColor(Color.WHITE);
      g2d.drawString("Aliens left: " + aliens.size(), 5, 15);

    } else {
      String msg = "Game Over";
      Font small = new Font("Helvetica", Font.BOLD, 14);
      FontMetrics metr = this.getFontMetrics(small);

      g.setColor(Color.white);
      g.setFont(small);
      g.drawString(msg, (B_WIDTH - metr.stringWidth(msg)) / 2, B_HEIGHT / 2);
    }

    Toolkit.getDefaultToolkit().sync();
    g.dispose();
  }
Exemple #6
0
  public void actionPerformed(ActionEvent e) {

    if (aliens.size() == 0) {
      ingame = false;
    }

    ArrayList ms = craft.getMissiles();

    for (int i = 0; i < ms.size(); i++) {
      Missile m = (Missile) ms.get(i);
      if (m.isVisible()) m.move();
      else ms.remove(i);
    }

    for (int i = 0; i < aliens.size(); i++) {
      Alien a = (Alien) aliens.get(i);
      if (a.isVisible()) a.move();
      else aliens.remove(i);
    }

    craft.move();
    checkCollisions();
    repaint();
  }
Exemple #7
0
  private void updateMissible() {

    ArrayList ms = craft.getMissiles();

    for (int i = 0; i < ms.size(); i++) {

      Missile m = (Missile) ms.get(i);

      if (m.isVisible()) {

        m.move();
      } else {

        ms.remove(i);
      }
    }
  }
Exemple #8
0
  private void updateCraft() {

    craft.move();
  }