示例#1
0
  public void paint(Graphics g) {
    super.paint(g);

    Graphics2D g2 = (Graphics2D) g;
    int size =
        Math.min(
            MAX_SIZE,
            Math.min(
                getWidth() - imagePadding.left - imagePadding.right,
                getHeight() - imagePadding.top - imagePadding.bottom));

    g2.translate(getWidth() / 2 - size / 2, getHeight() / 2 - size / 2);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

    Shape shape;

    if (mode == ColorPicker.SAT || mode == ColorPicker.BRI) {
      shape = new Ellipse2D.Float(0, 0, size, size);
    } else {
      Rectangle r = new Rectangle(0, 0, size, size);
      shape = r;
    }

    if (hasFocus()) {
      PaintUtils.paintFocus(g2, shape, 5);
    }

    if (!(shape instanceof Rectangle)) {
      // paint a circular shadow
      g2.translate(2, 2);
      g2.setColor(new Color(0, 0, 0, 20));
      g2.fill(new Ellipse2D.Float(-2, -2, size + 4, size + 4));
      g2.setColor(new Color(0, 0, 0, 40));
      g2.fill(new Ellipse2D.Float(-1, -1, size + 2, size + 2));
      g2.setColor(new Color(0, 0, 0, 80));
      g2.fill(new Ellipse2D.Float(0, 0, size, size));
      g2.translate(-2, -2);
    }

    g2.drawImage(image, 0, 0, size, size, 0, 0, size, size, null);

    if (shape instanceof Rectangle) {
      Rectangle r = (Rectangle) shape;
      PaintUtils.drawBevel(g2, r);
    } else {
      g2.setColor(new Color(0, 0, 0, 120));
      g2.draw(shape);
    }

    g2.setColor(Color.white);
    g2.setStroke(new BasicStroke(1));
    g2.draw(new Ellipse2D.Float(point.x - 3, point.y - 3, 6, 6));
    g2.setColor(Color.black);
    g2.draw(new Ellipse2D.Float(point.x - 4, point.y - 4, 8, 8));

    g.translate(-imagePadding.left, -imagePadding.top);
  }
示例#2
0
 @Override
 protected void drawFill(Graphics2D g) {
   if (isClosed() || get(UNCLOSED_PATH_FILLED)) {
     double grow = AttributeKeys.getPerpendicularFillGrowth(this);
     if (grow == 0d) {
       g.fill(path);
     } else {
       GrowStroke gs =
           new GrowStroke(grow, AttributeKeys.getStrokeTotalWidth(this) * get(STROKE_MITER_LIMIT));
       g.fill(gs.createStrokedShape(path));
     }
   }
 }
示例#3
0
  /** Draws the game */
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    final Graphics2D g2 = (Graphics2D) g;

    /** Draw all the non-falling blocks on the board. Non-OUTSIDE blocks have rounded corners. */
    for (int row = 0; row < board.getHeight(); row++) {
      for (int column = 0; column < board.getWidth(); column++) {
        if (board.getSquareType(row, column) != SquareType.OUTSIDE) {
          Shape tetrominoBlock =
              new RoundRectangle2D.Double(
                  column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT, 5, 5);
          g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column)));
          g2.fill(tetrominoBlock);
          g2.draw(tetrominoBlock);
        } else {
          Shape tetrominoBlock =
              new Rectangle2D.Double(
                  column * SQUARE_WIDTH, row * SQUARE_HEIGHT, SQUARE_WIDTH, SQUARE_HEIGHT);
          g2.setColor(SQUARE_COLOR.get(board.getSquareType(row, column)));
          g2.fill(tetrominoBlock);
          g2.draw(tetrominoBlock);
        }
      }
    }

    Poly tempPoly = board.getFalling();
    if (tempPoly != null) {

      for (int row = 0; row < tempPoly.getSize(); row++) {
        for (int column = 0; column < tempPoly.getSize(); column++) {
          if (tempPoly.getSquareType(row, column) != SquareType.EMPTY) {
            Shape tetrominoBlock =
                new RoundRectangle2D.Double(
                    (column + board.getFallingPosX()) * SQUARE_WIDTH,
                    (row + board.getFallingPosY()) * SQUARE_HEIGHT,
                    SQUARE_WIDTH,
                    SQUARE_HEIGHT,
                    5,
                    5);
            g2.setColor(SQUARE_COLOR.get(tempPoly.getSquareType(row, column)));
            g2.fill(tetrominoBlock);
            g2.draw(tetrominoBlock);
          }
        }
      }
    }
  }
    @Override
    public void paint(Graphics2D g2, State s, float cWidth, float cHeight) {

      float domainXScale = this.dwidth;
      float domainYScale = this.dheight;

      // determine then normalized width
      float width = (1.0f / domainXScale) * cWidth;
      float height = (1.0f / domainYScale) * cHeight;

      // pass through each cell of the map and if it is a wall, draw it
      for (int i = 0; i < this.dwidth; i++) {
        for (int j = 0; j < this.dheight; j++) {

          if (this.map[i][j] > 0) {

            float rx = i * width;
            float ry = cHeight - height - j * height;

            // draw the walls; make them black
            g2.setColor(this.cols[this.map[i][j] - 1]);

            g2.fill(new Rectangle2D.Float(rx, ry, width, height));
          }
        }
      }
    }
 /** Erase the whole canvas. (Does not repaint.) */
 private void erase() {
   Color original = graphic.getColor();
   graphic.setColor(backgroundColor);
   Dimension size = canvas.getSize();
   graphic.fill(new Rectangle(0, 0, size.width, size.height));
   graphic.setColor(original);
 }
示例#6
0
 public void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Rectangle2D rect = new Rectangle2D.Double(0, 0, getWidth() - 1, getHeight() - 1);
   g2.setPaint(Color.YELLOW);
   g2.fill(rect);
   g2.setPaint(Color.BLUE);
   g2.draw(rect);
 }
示例#7
0
 public void paint(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   g2.setPaint(BACKGROUND);
   g2.fill(
       new Rectangle2D.Float(
           0f, 0f, (float) g2.getClipBounds().width, (float) g2.getClipBounds().height));
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   canvas.paint(g2);
 }
  private void drawBlock(Graphics2D g, double x, GraphBlock gb) {
    double y0 = getTimeY(gb.getStartTime());
    double y1 = getTimeY(gb.getEndTime());

    double x0 = x - active_width / 2;
    Color c = getThreadBlockColor(gb.getThread());
    Rectangle2D r = new Rectangle2D.Double(x0, y0, active_width, y1 - y0);
    g.setColor(c);
    g.fill(r);
  }
示例#9
0
  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D) g;
    int i, j, k;
    System.out.println("Starting painting");
    // draw sets

    if (firstTimeAround) {
      drawSet(g2);
      render();
      viewer.save("final_product_full.png");
      firstTimeAround = false;
    }
    // render();
    /* for(i=0;i<viewer.getWidth();i++){
        for(j=0;j<viewer.getHeight();j++){
            viewer.setPixel(i,j,Color3.BLACK);
        }
    }
    */

    g2.setBackground(Color.BLACK);

    //        if(newRender){
    for (i = minX; i < maxX; i++) {
      // System.out.println("line "+i);
      for (j = minY; j < maxY; j++) {

        g2.setColor(
            new Color(
                (float) viewer.getPixel(i, j).getR(),
                (float) viewer.getPixel(i, j).getG(),
                (float) viewer.getPixel(i, j).getB()));
        // g2.drawLine(i,j,1,1);
        Ellipse2D.Double node_circ = new Ellipse2D.Double(i, j, 1, 1);
        g2.fill(node_circ);

        g2.setColor(Color.BLACK);

        // if(j*scale<viewer.getHeight()){
        //       j=0;//viewer.getHeight();
        // }

      }
      // if(i*scale<viewer.getWidth()){
      //    i=0;//viewer.getWidth();
      //  }
    }

    //  g2.drawImage(viewer.1)
    newRender = false;
    // }
    System.out.println("end painting");
  }
示例#10
0
 public void draw(Graphics2D graphic) {
   setForegroundColor(colorString);
   graphic.fill(shape);
   if (text != null) {
     setForegroundColor("black");
     java.awt.Rectangle bounds = shape.getBounds();
     int x = bounds.x + bounds.width / 2;
     int y = bounds.y + bounds.height / 2;
     graphic.drawString(text, x, y);
   }
 }
示例#11
0
 public synchronized void paintComponent(Graphics g) // Called on the event dispatch thread
     {
   if (values == null) return;
   Graphics2D g2 = (Graphics2D) g;
   int width = getWidth() / values.length;
   for (int i = 0; i < values.length; i++) {
     double height = values[i] * getHeight();
     Rectangle2D bar = new Rectangle2D.Double(width * i, 0, width, height);
     if (values[i] == marked1 || values[i] == marked2) g2.fill(bar);
     else g2.draw(bar);
   }
 }
示例#12
0
  void renderer(Graphics2D g2d) {
    height = window.getHeight() - 20;
    width = window.getWidth();

    lastTime = curTime;
    curTime = System.currentTimeMillis();
    totalTime += curTime - lastTime;
    if (totalTime > 1000) {
      totalTime -= 1000;
      fps = frames;
      frames = 0;
    }
    ++frames;

    delta = 16.0 / (curTime - lastTime);
    if (delta < 0) delta = 0;

    g2d.setColor(Color.white);
    if (removeMode) g2d.fill(new Rectangle(0, 0, width, height));

    if (eventHandeler(g2d)) {
      renderBackground(g2d);
      return;
    }

    Graphics2D map = (Graphics2D) g2d.create();
    playerHandeler();
    xOffset = -player.body.getCenterX() + width / 2;
    yOffset = -player.body.getCenterY() + height / 2;

    if (-xOffset < bounds.getBounds2D().getX()) xOffset = -bounds.getBounds2D().getX();
    else if (-xOffset > bounds.getBounds2D().getMaxX() - width)
      xOffset = -bounds.getBounds2D().getMaxX() + width;

    if (-yOffset < bounds.getBounds2D().getY()) yOffset = -bounds.getBounds2D().getY();
    else if (-yOffset > bounds.getBounds2D().getMaxY() - height + 3)
      yOffset = -bounds.getBounds2D().getMaxY() + height - 3;

    map.translate(xOffset, yOffset);

    renderBackground(map);
    itemHandeler(map);
    enemieHandeler();
    characterHandeler(map);

    map.setColor(Color.black);
    map.draw(bounds);

    renderUI(g2d);
  }
示例#13
0
    void draw(Graphics2D g) {

      // toX/toY is tip of arrow and fx/fy is a point on the line -
      // fx/fy is used to determine direction & angle

      AffineTransform at = AffineTransform.getTranslateInstance(toX, toY);
      int b = 9;
      double theta = Math.toRadians(20);
      // The idea of using a GeneralPath is so we can
      // create the (three lines that make up the) arrow
      // (only) one time and then use AffineTransform to
      // place it anywhere we want.
      GeneralPath path = new GeneralPath();

      // distance between line and the arrow mark <** not **
      // Start a new line segment from the position of (0,0).
      path.moveTo(0, 0);
      // Create one of the two arrow head lines.
      int x = (int) (-b * Math.cos(theta));
      int y = (int) (b * Math.sin(theta));
      path.lineTo(x, y);

      // distance between line and the arrow mark <** not **
      // Make the other arrow head line.
      int x2 = (int) (-b * Math.cos(-theta));
      int y2 = (int) (b * Math.sin(-theta));
      // path.moveTo(0,0);
      path.lineTo(x2, y2);
      path.closePath();

      // theta is in radians
      double s, t;
      s = toY - fy; // calculate slopes.
      t = toX - fx;
      if (t != 0) {
        s = s / t;
        theta = Math.atan(s);
        if (t < 0) theta += Math.PI;
      } else if (s < 0) theta = -(Math.PI / 2);
      else theta = Math.PI / 2;

      at.rotate(theta);
      // at.rotate(theta,toX,toY);
      Shape shape = at.createTransformedShape(path);
      if (checkStatus == Status.UNCHECKED) g.setColor(Color.BLACK);
      else if (checkStatus == Status.COMPATIBLE) g.setColor(FOREST_GREEN);
      else g.setColor(ORANGE_RED);
      g.fill(shape);
      g.draw(shape);
    }
示例#14
0
  // draws the tree, starting from the given node, in the region with x values
  // ranging
  // from minX to maxX, with y value beginning at y, and next level at y +
  // yIncr.
  private void drawTree(Graphics2D g2, TreeNode<E> t, int minX, int maxX, int y, int yIncr) {
    // skip if empty
    if (t == null) return;

    // compute useful coordinates
    int x = (minX + maxX) / 2;
    int nextY = y + yIncr;

    // draw black lines
    g2.setPaint(Color.black);
    if (t.left != null) {
      int nextX = (minX + x) / 2;
      g2.draw(new Line2D.Double(x, y, nextX, nextY));
    }
    if (t.right != null) {
      int nextX = (x + maxX) / 2;
      g2.draw(new Line2D.Double(x, y, nextX, nextY));
    }

    // measure text
    FontMetrics font = g2.getFontMetrics();
    String text = t.data + "";
    int textHeight = font.getHeight();
    int textWidth = font.stringWidth(text);

    // draw the box around the node
    Rectangle2D.Double box =
        new Rectangle2D.Double(
            x - textWidth / 2 - ARC_PAD,
            y - textHeight / 2 - ARC_PAD,
            textWidth + 2 * ARC_PAD,
            textHeight + 2 * ARC_PAD);
    Color c = new Color(187, 224, 227);
    g2.setPaint(c);
    g2.fill(box);
    // draw black border
    g2.setPaint(Color.black);
    g2.draw(box);

    // draw text
    g2.drawString(text, x - textWidth / 2, y + textHeight / 2);

    // draw children
    drawTree(g2, t.left, minX, x, nextY, yIncr);
    drawTree(g2, t.right, x, maxX, nextY, yIncr);
  }
示例#15
0
 @Override
 public void paintIcon(Component c, Graphics g, int x, int y) {
   Graphics2D g2 = (Graphics2D) g.create();
   g2.setPaint(Objects.nonNull(c) ? c.getBackground() : Color.WHITE);
   g2.fillRect(x, y, getIconWidth(), getIconHeight());
   g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   g2.setColor(ELLIPSE_COLOR);
   g2.translate(x, y);
   int size = list.size();
   for (int i = 0; i < size; i++) {
     float alpha = isRunning ? (i + 1) / (float) size : .5f;
     g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, alpha));
     g2.fill(list.get(i));
   }
   // g2.translate(-x, -y);
   g2.dispose();
 }
示例#16
0
文件: IMTree.java 项目: Kisssky/iqq
 /**
  * 选中时画背景
  *
  * @param g2d
  */
 @Override
 protected void paintSelection(Graphics2D g2d) {
   if (tree.getSelectionCount() > 0) {
     // Draw final selections
     final java.util.List<Rectangle> selections = getSelectionRects();
     for (final Rectangle rect : selections) {
       g2d.setPaint(selectedBg);
       g2d.fill(
           new RoundRectangle2D.Double(
               rect.x + selectionShadeWidth,
               rect.y + selectionShadeWidth,
               rect.width - selectionShadeWidth * 2 - 1,
               rect.height - selectionShadeWidth * 2 - 1,
               0,
               0));
     }
   }
 }
示例#17
0
  /** Draw vertices on top of the edge structure */
  public void drawNodes(Graphics2D gg) {
    Enumeration nodeList = argument.getBreadthFirstTraversal().elements();
    // Run through the traversal and draw each vertex
    // using an Ellipse2D
    // The draw point has been determined previously in
    // calcNodeCoords()
    while (nodeList.hasMoreElements()) {
      TreeVertex vertex = (TreeVertex) nodeList.nextElement();
      // Don't draw virtual nodes
      if (vertex.isVirtual()) continue;

      // If tree is incomplete and we're on the top layer, skip it
      if (argument.isMultiRoots() && vertex.getLayer() == 0) continue;

      Point corner = vertex.getDrawPoint();
      Shape node = new Ellipse2D.Float(corner.x, corner.y, NODE_DIAM, NODE_DIAM);
      vertex.setShape(node, this);

      // Fill the interior of the node with vertex's fillPaint
      gg.setPaint(vertex.fillPaint);
      gg.fill(node);

      // Draw the outline with vertex's outlinePaint; bold if selected
      gg.setPaint(vertex.outlinePaint);
      if (vertex.isSelected()) {
        gg.setStroke(selectStroke);
      } else {
        gg.setStroke(solidStroke);
      }
      gg.draw(node);

      // Draw the short label on top of the vertex
      gg.setPaint(vertex.textPaint);
      String shortLabelString = new String(vertex.getShortLabel());
      if (shortLabelString.length() == 1) {
        gg.setFont(labelFont1);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 4, corner.y + 3 * NODE_DIAM / 4);
      } else if (shortLabelString.length() == 2) {
        gg.setFont(labelFont2);
        gg.drawString(shortLabelString, corner.x + NODE_DIAM / 5, corner.y + 3 * NODE_DIAM / 4);
      }
    }
  }
 /**
  * method to draw the tail of the balloon
  *
  * @param ellipseHeight the height of the ellipse
  * @param fillColor the color to bill the balloon with
  * @param outlineColor the color to outline the balloon with
  * @param g2 the 2d graphics context
  */
 protected void drawTail(int ellipseHeight, Color fillColor, Color outlineColor, Graphics2D g2) {
   Point tailEnd = getTailEnd();
   Point upperLeft = getUpperLeft();
   int margin = getMargin();
   int halfWidth = getWidth() / 2;
   int topY = upperLeft.y + ellipseHeight;
   int startX = upperLeft.x + halfWidth - margin;
   int endX = upperLeft.x + halfWidth + margin;
   GeneralPath triangle = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 3);
   triangle.moveTo(startX, topY);
   triangle.lineTo(endX, topY);
   triangle.lineTo(tailEnd.x, tailEnd.y);
   triangle.lineTo(startX, topY);
   g2.setColor(fillColor);
   g2.fill(triangle);
   g2.setColor(outlineColor);
   g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, startX, topY));
   g2.draw(new Line2D.Double(tailEnd.x, tailEnd.y, endX, topY));
 }
 public void draw(Graphics2D g) {
   g.setColor(fillColor);
   g.fill(gp);
   g.setColor(Color.black);
   g.draw(gp);
   for (int i = 0; i < points.size(); i++) {
     GlyphPoint p = points.get(i);
     g.setColor(Color.red);
     g.draw(p.gp);
     g.setColor(Color.blue);
     g.setFont(gfont);
     g.drawString(String.valueOf(i), p.x + 3, p.y + 3);
   }
   g.setColor(Color.black);
   //	    System.out.println("Advance: "+advance);
   g.draw(advp);
   if (name != null) {
     g.setFont(gfont);
     g.drawString(name, 0, -40);
   }
 }
示例#20
0
文件: IMTree.java 项目: Kisssky/iqq
 /**
  * 鼠标经过画背景
  *
  * @param g2d
  */
 @Override
 protected void paintRolloverNodeHighlight(Graphics2D g2d) {
   if (tree.isEnabled()
       && highlightRolloverNode
       && rolloverRow != -1
       && !tree.isRowSelected(rolloverRow)) {
     final Rectangle rect =
         isFullLineSelection() ? getFullRowBounds(rolloverRow) : tree.getRowBounds(rolloverRow);
     if (rect != null) {
       // final Composite old = LafUtils.setupAlphaComposite ( g2d, 0.35f );
       g2d.setPaint(rolloverBg);
       g2d.fill(
           new RoundRectangle2D.Double(
               rect.x + selectionShadeWidth,
               rect.y + selectionShadeWidth,
               rect.width - selectionShadeWidth * 2 - 1,
               rect.height - selectionShadeWidth * 2 - 1,
               0,
               0));
       // LafUtils.restoreComposite ( g2d, old );
     }
   }
 }
  private void drawObject(Graphics2D g, int idx, GraphObject go) {
    double x0 = left_right_margin + (object_width + object_hspacing) * idx;
    Rectangle2D r = new Rectangle2D.Double(x0, top_bottom_margin, object_width, object_height);
    graph_locations.put(go, x0 + object_width / 2);

    g.setColor(Color.WHITE);
    g.fill(r);
    g.setColor(Color.BLACK);
    g.draw(r);
    g.setColor(Color.RED);
    SwingText.drawText(go.getName(), g, r);

    double x1 = x0 + object_width / 2;
    double y1 = top_bottom_margin + object_height;
    double y2 = time_end;
    Line2D tl = new Line2D.Double(x1, y1, x1, y2);
    g.setColor(Color.BLACK);
    g.draw(tl);

    for (GraphBlock gb : go.getBlocks()) {
      drawBlock(g, x1, gb);
    }
  }
示例#22
0
  // called whenever the TreeDisplay must be drawn on the screen
  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    Dimension d = getSize();

    // draw white background
    g2.setPaint(Color.white);
    g2.fill(new Rectangle2D.Double(0, 0, d.width, d.height));

    int depth = h();

    if (root == null)
      // no tree to draw
      return;

    // hack to avoid division by zero, if only one level in tree
    if (depth == 1) depth = 2;

    // compute the size of the text
    FontMetrics font = g2.getFontMetrics();
    TreeNode<E> leftmost = root;
    while (leftmost.left != null) leftmost = leftmost.left;
    TreeNode<E> rightmost = root;
    while (rightmost.right != null) rightmost = rightmost.right;
    int leftPad = font.stringWidth(leftmost.data + "") / 2;
    int rightPad = font.stringWidth(rightmost.data + "") / 2;
    int textHeight = font.getHeight();

    // draw the actual tree
    drawTree(
        g2,
        root,
        leftPad + ARC_PAD,
        d.width - rightPad - ARC_PAD,
        textHeight / 2 + ARC_PAD,
        (d.height - textHeight - 2 * ARC_PAD) / (depth - 1));
  }
示例#23
0
 // also clip, transform, composite,
 // public boolean isOpaque(){return false;}//theOpaque!=null&&theOpaque;}
 // ---------------------------------------------------------
 private void doPaint(Graphics2D g, int s, Object o) {
   // process an operation from the buffer
   // System.out.println(s);
   Object o1 = null,
       o2 = null,
       o3 = null,
       o4 = null,
       o5 = null,
       o6 = null,
       o7 = null,
       o8 = null,
       o9 = null,
       o10 = null,
       o11 = null;
   if (o instanceof Object[]) {
     Object[] a = (Object[]) o;
     if (a.length > 0) o1 = a[0];
     if (a.length > 1) o2 = a[1];
     if (a.length > 2) o3 = a[2];
     if (a.length > 3) o4 = a[3];
     if (a.length > 4) o5 = a[4];
     if (a.length > 5) o6 = a[5];
     if (a.length > 6) o7 = a[6];
     if (a.length > 7) o8 = a[7];
     if (a.length > 8) o9 = a[8];
     if (a.length > 9) o10 = a[9];
     if (a.length > 10) o11 = a[10];
   }
   switch (s) {
     case clear:
       paintBackground(g, theBackground);
       break;
       // public void addRenderingHints(Map<?,?> hints)
       // {toBuffer("addRenderingHints",hints );}
     case addRenderingHints:
       g.addRenderingHints((Map<?, ?>) o);
       break;
     case clip1:
       g.clip((Shape) o);
       break;
     case draw1:
       g.draw((Shape) o);
       break;
     case draw3DRect:
       g.draw3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case drawGlyphVector:
       g.drawGlyphVector((GlyphVector) o1, (Float) o2, (Float) o3);
       break;
     case drawImage1:
       g.drawImage((BufferedImage) o1, (BufferedImageOp) o2, (Integer) o3, (Integer) o4);
       break;
     case drawImage2:
       g.drawImage((Image) o1, (AffineTransform) o2, (ImageObserver) o3);
       break;
     case drawRenderableImage:
       g.drawRenderableImage((RenderableImage) o1, (AffineTransform) o2);
       break;
     case drawRenderedImage:
       g.drawRenderedImage((RenderedImage) o1, (AffineTransform) o2);
       break;
     case drawString1:
       g.drawString((AttributedCharacterIterator) o1, (Float) o2, (Float) o3);
       break;
     case drawString2:
       g.drawString((AttributedCharacterIterator) o1, (Integer) o2, (Integer) o3);
       break;
     case drawString3:
       g.drawString((String) o1, (Float) o2, (Float) o3);
       break;
     case drawString4:
       g.drawString((String) o1, (Integer) o2, (Integer) o3);
       break;
     case fill:
       g.fill((Shape) o);
       break;
     case fill3DRect:
       g.fill3DRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Boolean) o5);
       break;
     case rotate1:
       g.rotate((Double) o);
       break;
     case rotate2:
       g.rotate((Double) o1, (Double) o2, (Double) o3);
       break;
     case scale1:
       g.scale((Double) o1, (Double) o2);
       break;
     case setBackground:
       g.setBackground(
           (Color) o); // paintBackground(g,(Color)o); /*super.setBackground((Color)o) ;*/
       break;
     case setComposite:
       g.setComposite((Composite) o);
       break;
     case setPaint:
       g.setPaint((Paint) o);
       break;
     case setRenderingHint:
       g.setRenderingHint((RenderingHints.Key) o1, o2);
       break;
     case setRenderingHints:
       g.setRenderingHints((Map<?, ?>) o);
       break;
     case setStroke:
       g.setStroke((Stroke) o);
       break;
     case setTransform:
       g.setTransform(makeTransform(o));
       break;
     case shear:
       g.shear((Double) o1, (Double) o2);
       break;
     case transform1:
       g.transform(makeTransform(o));
       break;
     case translate1:
       g.translate((Double) o1, (Double) o2);
       break;
     case translate2:
       g.translate((Integer) o1, (Integer) o2);
       break;
     case clearRect:
       g.clearRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case copyArea:
       g.copyArea(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawArc:
       g.drawArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case drawBytes:
       g.drawBytes((byte[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawChars:
       g.drawChars((char[]) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5);
       break;
     case drawImage4:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (Color) o4, (ImageObserver) o5);
       break;
     case drawImage5:
       g.drawImage((Image) o1, (Integer) o2, (Integer) o3, (ImageObserver) o4);
       break;
     case drawImage6:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Color) o6,
           (ImageObserver) o7);
       break;
     case drawImage7:
       g.drawImage(
           (Image) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (ImageObserver) o6);
       break;
     case drawImage8:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (Color) o10,
           (ImageObserver) o11);
       break;
     case drawImage9:
       g.drawImage(
           (Image) o1,
           (Integer) o2,
           (Integer) o3,
           (Integer) o4,
           (Integer) o5,
           (Integer) o6,
           (Integer) o7,
           (Integer) o8,
           (Integer) o9,
           (ImageObserver) o10);
       break;
     case drawLine:
       g.drawLine((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawOval:
       g.drawOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawPolygon1:
       g.drawPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawPolygon2:
       g.drawPolygon((Polygon) o);
       break;
     case drawPolyline:
       g.drawPolyline((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case drawRect:
       g.drawRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case drawRoundRect:
       g.drawRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillArc:
       g.fillArc(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case fillOval:
       g.fillOval((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
       // {toBuffer("fillPolygon",mkArg(xPoints,  yPoints, nPoints) );}
     case fillPolygon1:
       g.fillPolygon((int[]) o1, (int[]) o2, (Integer) o3);
       break;
     case fillPolygon2:
       g.fillPolygon((Polygon) o);
       break;
     case fillRect:
       g.fillRect((Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4);
       break;
     case fillRoundRect:
       g.fillRoundRect(
           (Integer) o1, (Integer) o2, (Integer) o3, (Integer) o4, (Integer) o5, (Integer) o6);
       break;
     case setClip1:
       g.setClip((Shape) o);
       break;
     case setColor:
       g.setColor((Color) o);
       break;
     case setFont:
       g.setFont((Font) o);
       break;
     case setPaintMode:
       g.setPaintMode();
       break;
     case setXORMode:
       g.setXORMode((Color) o);
       break;
     case opaque:
       super.setOpaque((Boolean) o);
       break;
     case drawOutline: // g.drawString((String)o1, (Integer)o2, (Integer)o3) ;break;
       {
         FontRenderContext frc = g.getFontRenderContext();
         TextLayout tl = new TextLayout((String) o1, g.getFont(), frc);
         Shape s1 = tl.getOutline(null);
         AffineTransform af = g.getTransform();
         g.translate((Integer) o2, (Integer) o3);
         g.draw(s1);
         g.setTransform(af);
       }
       ;
       break;
     default:
       System.out.println("Unknown image operation " + s);
   }
 }
示例#24
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public boolean animate(int sAt, boolean forward) {

    int x;
    LinkedList lt = null;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in aborted attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }

    // First capture the new image in a buffer called image2
    SnapAt = sAt;
    BufferedImage image2 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) image2.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Next capture the image we are coming from in a buffer called image1
    SnapAt = (forward ? sAt - 1 : sAt + 1);
    BufferedImage image1 = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g1 = (Graphics2D) image1.getGraphics(); // need a separate object each time?
    g1.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g1.setColor(Color.WHITE);
    g1.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    list_of_snapshots.reset();
    x = 0;
    lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g1 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    // Now slide from image1 to image2

    // From the gaff Visualizer by Chris Gaffney
    //        double step = 4;	// Adjust this for more/less granularity between images
    double step = 40; // Adjust this for more/less granularity between images

    Image buffer = getGraphicsConfiguration().createCompatibleVolatileImage(my_width, my_height);
    Graphics2D g2d = (Graphics2D) buffer.getGraphics();

    AffineTransform trans = AffineTransform.getTranslateInstance(step * (forward ? -1 : 1), 0);
    //        AffineTransform orig = g2d.getTransform();

    Shape mask = createMask(my_width, my_height);

    for (double i = 0; i < my_width; i += step) {
      if (i + step > my_width) // last time through loop, so adjust transform
      trans =
            AffineTransform.getTranslateInstance(((double) (my_width - i)) * (forward ? -1 : 1), 0);
      g2d.transform(trans);
      g2d.drawImage(image1, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      AffineTransform last = g2d.getTransform();
      g2d.transform(AffineTransform.getTranslateInstance(my_width * (-1 * (forward ? -1 : 1)), 0));
      g2d.drawImage(image2, 0, 0, this);
      g2d.setColor(Color.BLACK);
      g2d.fill(mask);

      g2d.setTransform(last);

      this.my_image = buffer;
      repaint();

      try {
        Thread.sleep(10);
      } catch (InterruptedException e) {

      }
    }
    Image b = getGraphicsConfiguration().createCompatibleImage(my_width, my_height);
    b.getGraphics().drawImage(buffer, 0, 0, null);
    this.my_image = b;

    return animation_done;
  }
示例#25
0
  // Although it presently returns a boolean, that was only needed
  // during my aborted attempted at animated graphics primitives.
  // Until those become a reality the boolean value returned by this
  // routine is unnecessary
  public /*synchronized*/ boolean execute(int sAt) {

    // The commented-out variables below are remnants from legacy
    // code -- they appear to be no longer needed.

    //         String urlTemp="";
    //         int z=0;
    //         int idx;
    //         int urlid;
    //         boolean showURL=false;
    animation_done =
        true; // May be re-set in paintComponent via indirect paintImmediately call at end

    // Was used in abored attempted to
    // introduce animated primitives.  Now
    // it's probably excess baggage that
    // remains because I still have hopes
    // of eventually having animated
    // primitives
    SnapAt = sAt;

    if (getSize().width != 0 && getSize().height != 0) {
      my_width = getSize().width; // set dimensions
      my_height = getSize().height;
    } else {
      my_width = GaigsAV.preferred_width; // set dimensions
      my_height = GaigsAV.preferred_height;
    }
    BufferedImage buff = new BufferedImage(my_width, my_height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = (Graphics2D) buff.getGraphics(); // need a separate object each time?
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setColor(Color.WHITE);
    g2.fillRect(0, 0, my_width, my_height);
    // Set horizoff and vertoff to properly center the visualization in the
    // viewing window. This is not quite perfect because visualizations
    // that are not properly centered within their [0,1] localized
    // coordinates will not be perfectly centered, but it is much better
    // than it was previously.

    // 	if(no_mouse_drag){
    // 	    if(first_paint_call){
    // // 		horizoff = (my_width - (int)(0.25 * my_width) -
    // // 			    GaigsAV.preferred_width) / 2;
    // 		horizoff = (my_width - GaigsAV.preferred_width) / 2;
    // 		first_paint_call = false;
    // 	    }else{
    // 		horizoff = (my_width - GaigsAV.preferred_width) / 2;
    // 		no_mouse_drag = false;
    // 	    }
    // 	}

    if (no_mouse_drag) {
      horizoff = (my_width - GaigsAV.preferred_width) / 2;
      vertoff = (my_height - GaigsAV.preferred_height) / 2;
    }

    int x;

    list_of_snapshots.reset();
    x = 0;
    LinkedList lt = new LinkedList();
    while (x < SnapAt && list_of_snapshots.hasMoreElements()) {
      lt = (LinkedList) list_of_snapshots.nextElement();
      x++;
    }
    lt.reset();
    animation_done = true;
    //        System.out.println("before loop " + horizoff);
    while (lt.hasMoreElements()) {
      obj tempObj = (obj) lt.nextElement();
      animation_done =
          animation_done && (tempObj.execute(g2 /*offscreen*/, zoom, vertoff, horizoff));
      //  System.out.println("in loop");
    }

    Shape mask = createMask(buff.getWidth(), buff.getHeight());

    g2.setColor(Color.BLACK);
    g2.fill(mask);

    my_image = buff;
    repaint();

    return animation_done;
  }
示例#26
0
  /**
   * Creates new frame image from current data (and previous frames as specified by their
   * disposition codes).
   */
  protected void setPixels() {
    // expose destination image's pixels as int array
    int[] dest = ((DataBufferInt) image.getRaster().getDataBuffer()).getData();

    // fill in starting image contents based on last image's dispose code
    if (lastDispose > 0) {
      if (lastDispose == 3) {
        // use image before last
        int n = frameCount - 2;
        if (n > 0) {
          lastImage = getFrame(n - 1);
        } else {
          lastImage = null;
        }
      }

      if (lastImage != null) {
        int[] prev = ((DataBufferInt) lastImage.getRaster().getDataBuffer()).getData();
        System.arraycopy(prev, 0, dest, 0, width * height);
        // copy pixels

        if (lastDispose == 2) {
          // fill last image rect area with background color
          Graphics2D g = image.createGraphics();
          Color c = null;
          if (transparency) {
            c = new Color(0, 0, 0, 0); // assume background is transparent

          } else {
            c = new Color(lastBgColor); // use given background color
          }
          g.setColor(c);
          g.setComposite(AlphaComposite.Src); // replace area

          g.fill(lastRect);
          g.dispose();
        }
      }
    }

    // copy each source line to the appropriate place in the destination
    int pass = 1;
    int inc = 8;
    int iline = 0;
    for (int i = 0; i < ih; i++) {
      int line = i;
      if (interlace) {
        if (iline >= ih) {
          pass++;
          switch (pass) {
            case 2:
              iline = 4;
              break;
            case 3:
              iline = 2;
              inc = 4;
              break;
            case 4:
              iline = 1;
              inc = 2;
          }
        }
        line = iline;
        iline += inc;
      }
      line += iy;
      if (line < height) {
        int k = line * width;
        int dx = k + ix; // start of line in dest

        int dlim = dx + iw; // end of dest line

        if ((k + width) < dlim) {
          dlim = k + width; // past dest edge
        }
        int sx = i * iw; // start of line in source

        while (dx < dlim) {
          // map color and insert in destination
          int index = ((int) pixels[sx++]) & 0xff;
          int c = act[index];
          if (c != 0) {
            dest[dx] = c;
          }
          dx++;
        }
      }
    }
  }
示例#27
0
  public synchronized void paint(Graphics graphics) {

    Graphics2D g = (Graphics2D) graphics;

    Image water = Toolkit.getDefaultToolkit().getImage("catanui/water.jpg");
    g.drawImage(water, 0, 0, this);

    for (Hex o : _hexes) {
      o.paint(g, _display_offset[0], _display_offset[1]);
    }

    g.translate(_display_offset[0] + 2, _display_offset[1] - 1);
    synchronized (portContents) {
      for (Pair c : portContents.keySet()) {

        int lowx =
            hexleft
                + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                    / 2
                    * intervalSide[0]
                + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                    / 2
                    * intervalSide[1]
                + (((CoordPair) c.getA()).getX() % 2) * intervalSide[0];
        int lowy = hextop + ((CoordPair) c.getA()).getY() * intervalUp;
        int highx =
            hexleft
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[0]
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[1]
                + (((CoordPair) c.getB()).getX() % 2) * intervalSide[0];
        int highy = hextop + ((CoordPair) c.getB()).getY() * intervalUp;

        int dx = highx - lowx;
        int dy = highy - lowy;
        double rad = Math.atan((1.0) * dy / dx);

        if (dx < 0) rad += Math.PI;

        g.translate(lowx, lowy);
        g.rotate(rad);
        g.drawImage(
            BoardObject.images.get(BoardObject.type2port.get(portContents.get(c))), 0, -75, null);
        g.rotate(-rad);
        g.translate((-1) * lowx, (-1) * lowy);
      }
    }
    g.translate((-1) * _display_offset[0], (-1) * _display_offset[1]);

    synchronized (roadContents) {
      for (Pair c : roadContents.keySet()) {

        Road r =
            new Road(
                hexleft
                    + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                        / 2
                        * intervalSide[0]
                    + (((CoordPair) c.getA()).getX() - (((CoordPair) c.getA()).getX() % 2))
                        / 2
                        * intervalSide[1]
                    + (((CoordPair) c.getA()).getX() % 2) * intervalSide[0],
                hextop + ((CoordPair) c.getA()).getY() * intervalUp);

        r.setX2(
            hexleft
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[0]
                + (((CoordPair) c.getB()).getX() - (((CoordPair) c.getB()).getX() % 2))
                    / 2
                    * intervalSide[1]
                + (((CoordPair) c.getB()).getX() % 2) * intervalSide[0]);
        r.setY2(hextop + ((CoordPair) c.getB()).getY() * intervalUp);

        r.setColor(roadContents.get(c));
        r.paint(g, _display_offset[0], _display_offset[1]);
      }
    }

    synchronized (vertexContents) {
      for (CoordPair c : vertexContents.keySet()) {
        int newx =
            hexleft
                + ((c._x - (c._x % 2)) / 2 * intervalSide[0]
                    + (c._x - (c._x % 2)) / 2 * intervalSide[1]
                    + (c._x % 2) * intervalSide[0])
                - 20;
        int newy = hextop + c._y * intervalUp - 20;

        if ((BoardObject.type) (vertexContents.get(c).getA()) == BoardObject.type.SETTLEMENT) {
          Settlement s = new Settlement(newx, newy, (Integer) (vertexContents.get(c).getB()));
          s.paint(g, _display_offset[0], _display_offset[1]);
        } else if ((BoardObject.type) (vertexContents.get(c).getA()) == BoardObject.type.CITY) {
          City s = new City(newx, newy, (Integer) (vertexContents.get(c).getB()));
          s.paint(g, _display_offset[0], _display_offset[1]);
        } else System.out.println("neither -_-");
      }
    }

    g.setColor(Color.GRAY);
    g.fill(new Rectangle(0, 0, 110, 60));
    g.setColor(Color.LIGHT_GRAY);
    g.fill(new Rectangle(3, 3, 104, 56));
    if (_dieRoll > 0) {
      BufferedImage r1img =
          diceImage.getSubimage((int) (Math.floor((twoDice[0] - 1) * 94.7)), 0, 94, 93);
      g.drawImage(r1img, 5, 7, 48, 47, null);
      BufferedImage r2img =
          diceImage.getSubimage((int) (Math.floor((twoDice[1] - 1) * 94.7)), 0, 94, 93);
      g.drawImage(r2img, 55, 7, 48, 47, null);
    }

    if (_up != null) _up.paint(g);

    if (!_gameOver.equals("") && !_dismiss) {
      _currAlpha += 0.007;
    }
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, _currAlpha));
    g.setColor(Color.GRAY);
    g.fill(new Rectangle(-20, 0, 1020, 650));
    g.setColor(Color.BLACK);
    g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) 1.0));
    if (!_gameOver.equals("")) {

      if (_currAlpha >= 0.8) {
        if (_gameOver.equals(gameLogic._name)) {
          g.drawString("Congratulations, you won!", 350, 200);
        } else {
          g.drawString(_gameOver + " has won!", 350, 200);
        }
        _dismiss = true;
      } else repaint();
    }
  }
示例#28
0
  boolean eventHandeler(Graphics2D g2d) {

    if (keyboard.keyDownOnce(KeyEvent.VK_Q)) {
      window.setState(Frame.ICONIFIED);
      paused = true;
    }

    if (firstStartup) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));

      g2d.setFont(new Font("Courier New", Font.PLAIN, 20));
      g2d.setColor(Color.black);
      switch (startupPage) {
        case 1:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 2;

          g2d.drawString("The goal of this game is to kill as", 100, 170);
          g2d.drawString("many *zombies* as possible. You are", 100, 200);
          g2d.drawString("given weapons and power-ups to help", 100, 230);
          g2d.drawString("you succeed. Good luck.", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("Ø O O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Story", 265, 110);
          break;
        case 2:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) startupPage = 3;

          g2d.drawString("Use A,S,D,W to stear", 100, 170);
          g2d.drawString("Use 1,2,3,4 to change weapon", 100, 200);
          g2d.drawString("Use the MOUSE to aim", 100, 230);
          g2d.drawString("Use the LEFT MOUSE BUTTON to fire", 100, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to continue", 150, 330);
          g2d.drawString("O Ø O", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Controlls", 230, 110);
          break;
        case 3:
          if (keyboard.keyDownOnce(KeyEvent.VK_SPACE)) firstStartup = false;

          g2d.setColor(Color.black);
          g2d.draw(new Ellipse2D.Double(100, 170 - 15, 20, 20));
          g2d.setColor(Color.red);
          g2d.draw(new Ellipse2D.Double(100, 200 - 15, 20, 20));
          g2d.setColor(Color.blue);
          g2d.draw(new Ellipse2D.Double(100, 230 - 15, 20, 20));
          g2d.setColor(Color.green);
          g2d.draw(new Ellipse2D.Double(100, 260 - 15, 20, 20));

          g2d.setColor(Color.black);
          g2d.drawString("Is you", 130, 170);
          g2d.drawString("Heals you", 130, 200);
          g2d.drawString("Unlocks / upgrades a weapon", 130, 230);
          g2d.drawString("Causes an explosion around you", 130, 260);

          g2d.setColor(Color.gray);
          g2d.drawString("Press SPACE to start", 150, 330);
          g2d.drawString("O O Ø", 280, 290);

          g2d.setColor(Color.black);
          g2d.setFont(new Font("Courier New", Font.PLAIN, 34));
          g2d.drawString("Power-ups", 230, 110);
          break;
      }
      return true;
    }

    if (player.isDead) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_R)) restart();

      if (newHighscore) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 320, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("New Highscore"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record was " + oldHighScore + " kills", 210, 260);
      } else if (cheated) {
        int x = 20;
        int y = 130;
        g2d.rotate(-.4, x, y);
        g2d.setFont(new Font("Comic Sans MS", Font.PLAIN, 40));
        g2d.setColor(Color.black);
        Stroke oldStroke = g2d.getStroke();
        float dash[] = {40.0f};
        g2d.setStroke(
            new BasicStroke(
                4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 0.0f, dash, 40.0f));
        g2d.drawRoundRect(x, y, 270, 75, 20, 20);
        g2d.setColor(Color.red);
        g2d.drawString(String.format("You cheated"), x + 20, y + 50);
        g2d.rotate(.4, x, y);
        g2d.setStroke(oldStroke);

        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Highscore not saved", 210, 260);
      } else {
        g2d.setColor(Color.lightGray);
        g2d.setFont(new Font("Courier", Font.PLAIN, 20));
        g2d.drawString("Your record is " + oldHighScore + " kills", 210, 260);
      }

      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));

      if (player.score == 1) g2d.drawString(String.format(player.score + " kill"), 200, 230);
      else g2d.drawString(String.format(player.score + " kills"), 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press R to restart"), 150, 330);
      return true;
    }

    if (window.isFocused() == false) paused = true;

    if (paused) {
      g2d.setColor(Color.white);
      g2d.fill(new Rectangle(0, 0, width, height));
      if (keyboard.keyDownOnce(KeyEvent.VK_ESCAPE)) paused = false;
      g2d.setColor(Color.black);
      g2d.setFont(new Font("Courier", Font.PLAIN, 50));
      g2d.drawString("Paused", 200, 230);
      g2d.setFont(new Font("Courier New", Font.PLAIN, 30));
      g2d.setColor(Color.gray);
      g2d.drawString(String.format("Press ESC to resume"), 150, 330);
      return true;
    }

    return false;
  }
示例#29
0
 public void draw(Graphics2D graphic) {
   setForegroundColor(colorString);
   graphic.fill(shape);
 }
示例#30
0
 protected void drawFill(Graphics2D g) {
   g.fill(getTextShape());
 }