コード例 #1
0
  public void checkCollisions() {

    Rectangle r3 = link.getBounds();

    for (int j = 0; j < enemies.size(); j++) {
      Enemy en = (Enemy) enemies.get(j);
      Rectangle r2 = en.getBounds();

      if (r3.intersects(r2)) {
        link.setVisible(false);
        en.setVisible(false);
        ingame = false;
        gamewin = false;
      } // end if
    } // end for loop

    ArrayList as = link.getArrows();

    for (int i = 0; i < as.size(); i++) {
      Arrow aa = (Arrow) as.get(i);

      Rectangle r1 = aa.getBounds();

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

        if (r1.intersects(r2)) {
          aa.setVisible(false);
          a.setVisible(false);
        } // end of if
      } // end inner for loop
    } // end outer for loop
  } // end checkCollisions
コード例 #2
0
ファイル: DisplayPanel.java プロジェクト: schambersnh/school
  /** draw the arrows between items */
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (_glist != null && _glist.size() > 1) {
      Graphics2D g2 = (Graphics2D) g;
      Arrow leftArrow = new Arrow();
      leftArrow.setColor(Color.BLACK);

      Arrow rightArrow = new Arrow();
      rightArrow.setColor(Color.RED);

      Iterator<GNode> iter = _glist.iterator();

      while (iter.hasNext()) {
        GNode nCur = iter.next();
        if (nCur.left != null) {
          leftArrow.setLine(nCur.getStart(), nCur.left.getEnd());
          leftArrow.draw(g2);
        }
        if (nCur.right != null) {
          rightArrow.setLine(nCur.getStart(), nCur.right.getEnd());
          rightArrow.draw(g2);
        }
      }
    }
  }
コード例 #3
0
ファイル: CellArrow.java プロジェクト: DarwinNE/FidoCadJ
  /**
   * Paint the arrow in the panel, using the current style.
   *
   * @param g the graphic context.
   */
  public void paintComponent(Graphics g) {
    g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground());

    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(isSelected ? list.getSelectionForeground() : list.getForeground());

    g.drawLine(getWidth() / 3, getHeight() / 2, 2 * getWidth() / 3, getHeight() / 2);
    Arrow arrowDummy = new Arrow();

    arrowDummy.drawArrowPixels(
        new Graphics2DSwing(g),
        getWidth() / 3,
        getHeight() / 2,
        2 * getWidth() / 3,
        getHeight() / 2,
        10,
        4,
        arrow.style);
  }
コード例 #4
0
  public void actionPerformed(ActionEvent e) {

    if (enemies.isEmpty()) {
      newWave = true;

      waveNum++;
      incEnemies += 2;

      if (waveNum == 14) {
        ingame = false;
        gamewin = true;
      } // end if
      else initEnemies();
    } // end if

    ArrayList as = link.getArrows();

    for (int i = 0; i < as.size(); i++) {
      Arrow a = (Arrow) as.get(i);
      if (a.isVisible()) {
        a.move();
      } else {
        as.remove(i);
      }
    } // end for

    for (int i = 0; i < enemies.size(); i++) {
      Enemy en = (Enemy) enemies.get(i);
      if (en.isVisible()) {
        en.move();
      } else {
        enemies.remove(i);
      }
    } // end for

    link.move();
    checkCollisions();
    repaint();
  } // end actionPerformed
コード例 #5
0
ファイル: Arrow.java プロジェクト: simonhjsong/drawfbp
 Arrow makeCopy(Diagram d) {
   Arrow arr = new Arrow(d);
   arr.fromX = this.fromX;
   arr.fromY = this.fromY;
   arr.toX = this.toX;
   arr.toY = this.toY;
   arr.lastX = this.lastX;
   arr.lastY = this.lastY;
   arr.fromId = this.fromId;
   arr.toId = this.toId;
   arr.id = this.id;
   arr.endsAtBlock = this.endsAtBlock;
   arr.endsAtLine = this.endsAtLine;
   if (this.bends != null) {
     arr.bends = new LinkedList<Bend>();
     for (Bend b : this.bends) {
       Bend b2 = new Bend(b.x, b.y);
       arr.bends.add(b2);
     }
   }
   arr.upStreamPort = this.upStreamPort;
   arr.downStreamPort = this.downStreamPort;
   arr.fromSide = this.fromSide;
   arr.toSide = this.toSide;
   arr.diag = d;
   return arr;
 }
コード例 #6
0
  public void paint(Graphics g) {
    super.paint(g);

    if (ingame) {

      Graphics2D g2d = (Graphics2D) g;

      if (link.isVisible()) {
        g2d.drawImage(link.getImage(), link.getX(), link.getY(), this);
      } // end inner if

      ArrayList as = link.getArrows();

      for (int i = 0; i < as.size(); i++) {
        Arrow a = (Arrow) as.get(i);
        g.setColor(new Color(96, 64, 32));
        g.fillRect(a.getX(), a.getY(), a.width, a.height);

        g.setColor(Color.GRAY);
        int[] xPoints = {a.getX() + a.width, a.getX() + a.width + 10, a.getX() + a.width};
        int[] yPoints = {a.getY() + a.height + 2, a.getY() + (a.height / 2), a.getY() - 2};
        g.fillPolygon(xPoints, yPoints, 3);
      } // end for

      for (int i = 0; i < enemies.size(); i++) {
        Enemy en = (Enemy) enemies.get(i);
        if (en.isVisible()) {
          g2d.drawImage(en.getImage(), en.getX(), en.getY(), this);
        } // end inner if
      } // end for

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

      if (waveNum < 13) {
        g2d.setColor(Color.WHITE);
        g2d.drawString("Wave: " + waveNum, 5, 30);
      } else {
        g2d.setColor(Color.WHITE);
        g2d.drawString("Final Wave!", 5, 30);
      }

    } else if (gamewin) {
      String msg = "You Win!";
      Font small = new Font("Helvetica", Font.BOLD, 14);
      FontMetrics metr = this.getFontMetrics(small);

      g.setColor(Color.white);
      g.setFont(small);
      g.drawString(msg, (600 - metr.stringWidth(msg)) / 2, 600 / 2);
    } 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, (600 - metr.stringWidth(msg)) / 2, 600 / 2);
    } // end outter if

    Toolkit.getDefaultToolkit().sync();
    g.dispose();
  } // end paint