public void moveLayerThree(Graphics g) {
   backy += (int) (player1.getVelocity() * 0.1);
   midy += (int) (player1.getVelocity() * 0.5);
   drawEnemy(g);
   drawCoin(g);
   drawBox(g);
   drawPoof(g);
   drawStar(g);
   drawJumper(g);
   drawSpike(g);
   drawPup(g);
   if (backy <= dieHeight) {
     // System.out.println(die);
     g.drawImage(player1.move(2), player1.getX(), player1.getY(), this);
     if (player1.animationComplete()) {
       die = true;
     }
   } else {
     if (backy <= dieHeight) {
       player1.resetCounter();
     }
     if (keys[KeyEvent.VK_RIGHT]) {
       g.drawImage(player1.move(1), player1.getX(), player1.getY(), this);
     } else if (keys[KeyEvent.VK_LEFT]) {
       g.drawImage(player1.move(-1), player1.getX(), player1.getY(), this);
     } else {
       g.drawImage(player1.move(0), player1.getX(), player1.getY(), this);
     }
   }
 }
示例#2
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);
    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }
    if (gameOver) return;
    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    for (int index = 0; index < missile.length; index++) {
      if (missile[index].active) {
        g.setColor(Color.red);
        drawCircle(getX(missile[index].xPos), getYNormal(missile[index].yPos), 90, .3, 1.5);
      }
    }
    if (rocketRight) {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, 2.0, 2.0);
    } else {
      drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0.0, -2.0, 2.0);
    }
    for (int index = 0; index < numStars; index++) {
      g.setColor(Color.yellow);
      if (starActive[index])
        drawCircle(getX(starXPos[index]), getYNormal(starYPos[index]), 0, 1.5, 1.5);
    }
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Score: " + score, 10, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("HighScore: " + highScore, 300, 45);
    g.setColor(Color.magenta);
    g.setFont(new Font("Impact", Font.BOLD, 15));
    g.drawString("Lives: " + rocketLife, 150, 45);
    if (rocketLife == 0) {
      g.setColor(Color.red);
      g.setFont(new Font("Impact", Font.BOLD, 60));
      g.drawString("GAME OVER", getX(getWidth2() / 6), getYNormal(getHeight2() / 2));
    }
    gOld.drawImage(image, 0, 0, null);
  }
 public void gameOverMenu(
     Graphics g) { // CHANGE THIS TO INCLUDE HIGHSCORES AND STUFF AFTER TEXTFILES ARE MADE
   // Menu that shows up when user gets Game Over
   if (pause == true && die == true) {
     g.drawImage(
         new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // Graphics stuff
     g.setFont(scoreFont);
     g.setColor(Color.BLACK);
     g.drawImage(new ImageIcon("InGameMenu/GameOver.png").getImage(), 10, 200, this);
     displayScore2(g, 115, 350, 185, 385, 110, 440, 110, 490); // Shows stats
     g.drawImage(menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws menu button
   }
 }
 public void lvlClearMenu(Graphics g) {
   // Menu that shows up after a level has been cleared
   if (pause == true && lvlClear == true) {
     g.drawImage(
         new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // <Graphics stuff
     g.drawImage(new ImageIcon("InGameMenu/stageClearPic.png").getImage(), 100, 0, this);
     displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats
     g.drawImage(
         resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws resume button
     g.drawImage(
         menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button
   }
 }
 public void moveLayerOne(
     Graphics g) { // drawing the background, we have to make this into percentage afterwards
   g.drawImage(
       gameBckgrnd,
       0,
       (((int) (backy * 0.1)) % 23080) - 23080,
       this); // makes it continues and i have an extra image on top just to be safe
 }
示例#6
0
文件: LJ3MDApp.java 项目: eskilj/mvp
  /**
   * Draw a ball at screen coordinate (x, y) with a ball index `id' (0, 0) represents the top-left
   * corner `x', `y', `radius' are given in pixels the ball index (gray code) `id' can be 0 to 15
   */
  void paint(Graphics gc, int x, int y, int id, double radius) {
    if (balls == null) makeBalls();
    Image img = balls[id]; // id = [0..15]

    int size = (int) (radius * 2 + .5);
    gc.drawImage(img, x - size / 2, y - size / 2, size, size, null);
    // System.out.println("" + x + " " + y + " " + id + " " + radius);
  }
 public void drawStar(Graphics g) {
   // draws the stars
   for (Star i : starList) {
     g.drawImage(
         i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
     i.count();
   }
 }
 public void displayScore2(
     Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) {
   g.setFont(scoreFont);
   g.setColor(Color.WHITE);
   g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this);
   g.drawString("" + coins, sx1, sy1);
   g.drawString("Score:  " + score, sx2, sy2);
   g.drawString("Height:  " + height + " m", sx3, sy3);
 }
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Drawing
 public void drawCoin(Graphics g) {
   // draws the coins
   for (Coin i : coinList) {
     g.drawImage(
         i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
     i.count();
     i.setDirection();
   }
 }
示例#10
0
 // Use double buffer to reduce flicker when drawing complex ROIs.
 // Author: Erik Meijering
 void paintDoubleBuffered(Graphics g) {
   final int srcRectWidthMag = (int) (srcRect.width * magnification);
   final int srcRectHeightMag = (int) (srcRect.height * magnification);
   if (offScreenImage == null
       || offScreenWidth != srcRectWidthMag
       || offScreenHeight != srcRectHeightMag) {
     offScreenImage = createImage(srcRectWidthMag, srcRectHeightMag);
     offScreenWidth = srcRectWidthMag;
     offScreenHeight = srcRectHeightMag;
   }
   Roi roi = imp.getRoi();
   try {
     if (imageUpdated) {
       imageUpdated = false;
       imp.updateImage();
     }
     Graphics offScreenGraphics = offScreenImage.getGraphics();
     Java2.setBilinearInterpolation(offScreenGraphics, Prefs.interpolateScaledImages);
     Image img = imp.getImage();
     if (img != null)
       offScreenGraphics.drawImage(
           img,
           0,
           0,
           srcRectWidthMag,
           srcRectHeightMag,
           srcRect.x,
           srcRect.y,
           srcRect.x + srcRect.width,
           srcRect.y + srcRect.height,
           null);
     if (overlay != null) drawOverlay(offScreenGraphics);
     if (showAllROIs) drawAllROIs(offScreenGraphics);
     if (roi != null) drawRoi(roi, offScreenGraphics);
     if (srcRect.width < imageWidth || srcRect.height < imageHeight)
       drawZoomIndicator(offScreenGraphics);
     if (IJ.debugMode) showFrameRate(offScreenGraphics);
     g.drawImage(offScreenImage, 0, 0, null);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory("Paint");
   }
 }
示例#11
0
 @Override
 public void paintComponent(Graphics g) {
   g.setColor(getBackground());
   g.fillRect(0, 0, getWidth(), getHeight());
   int w = bufferedImage.getWidth(this);
   int h = bufferedImage.getHeight(this);
   if (mode == Flip.NONE) {
     g.drawImage(bufferedImage, 0, 0, w, h, this);
   } else if (mode == Flip.VERTICAL) {
     AffineTransform at = AffineTransform.getScaleInstance(1d, -1d);
     at.translate(0, -h);
     Graphics2D g2 = (Graphics2D) g.create();
     g2.drawImage(bufferedImage, at, this);
     g2.dispose();
   } else if (mode == Flip.HORIZONTAL) {
     AffineTransform at = AffineTransform.getScaleInstance(-1d, 1d);
     at.translate(-w, 0);
     AffineTransformOp atOp = new AffineTransformOp(at, null);
     g.drawImage(atOp.filter(bufferedImage, null), 0, 0, w, h, this);
   }
 }
示例#12
0
  // ------------------------------------------------------------------------------------------------------------------------------------
  // In game menus
  public void pauseMenu(Graphics g) {
    // Pause menu
    if (pause == true && lvlClear == false) {
      g.setFont(scoreFont);
      g.setColor(Color.BLACK);
      g.drawImage(new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this);
      g.drawString("P A U S E D", 155, 200);
      displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats
      g.drawImage(
          resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws the resume button
      g.drawImage(
          menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button

      if (musicOn == true) { // Draws the mute or unmute button (based on if music is on or not)
        g.drawImage(muteB.getPic(mx, my), muteB.getX(), muteB.getY(), this);
      }
      if (musicOn == false) {
        g.drawImage(unmuteB.getPic(mx, my), unmuteB.getX(), unmuteB.getY(), this);
      }
    }
  }
示例#13
0
  // draws the current snapshot
  public void paintComponent(Graphics g) {

    // System.out.println("In paint in draw");
    super.paintComponent(g);
    my_width = getSize().width;
    my_height = getSize().height;
    if (my_image != null) g.drawImage(my_image, 0, 0, my_width, my_height, this);

    setBackground(new Color(1.0f, 1.0f, 1.0f));
    //         g.setColor(Color.black);
    //         g.drawRect(0,0,my_width-1,my_height-1);

  }
示例#14
0
文件: Hero.java 项目: rweichler/wuigi
  // CONSTANT METHODS
  public void draw(Graphics g, ImageObserver o) {

    boolean transparent =
        invulerable && (invulerableTime < 3000 / 15 || System.currentTimeMillis() % 60 > 30);
    if (transparent)
      ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.5f));
    int x = Wuigi.scaleW(Wuigi.screenWidth / 2.0 + xOffset - 4);
    int y = Wuigi.scaleH(Wuigi.screenHeight - yOffset);
    if (cape) {
      if (facingRight)
        g.drawImage(
            TCape.IMAGE.getBuffer(),
            x - 5,
            y,
            Wuigi.scaleW(WIDTH + 8),
            Wuigi.scaleH(HEIGHT + 2),
            o);
      else
        g.drawImage(
            TCape.IMAGE.flipX(), x + 5, y, Wuigi.scaleW(WIDTH + 8), Wuigi.scaleH(HEIGHT + 2), o);
    }

    drawAWP(g, x, y);

    g.drawImage(
        figureOutDrawImage(IMAGE),
        x,
        // (int)(Global.H-H-pos.y-Global.GROUND_LEVEL),
        y,
        Wuigi.scaleW(WIDTH + 8),
        Wuigi.scaleH(HEIGHT + 2),
        o);
    if (transparent)
      ((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));

    // g.setColor(Color.WHITE);
    // g.drawRect((int)(Wuigi.W/2 - X_OFFSET), (int)(Wuigi.H - Y_OFFSET), (int)X_OFFSET*2 + width,
    // (int)(Y_OFFSET*2) - Wuigi.H);
  }
示例#15
0
 public void drawPowerUpEffect(Graphics g) {
   if (player1.getPower().equals("Magnet")) {
     Image magpic = magnetList.get((int) count % 6);
     g.drawImage(
         magpic,
         player1.getX() - ((magpic.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((magpic.getHeight(null) - player1.getHeight()) / 2),
         magpic.getWidth(null),
         magpic.getHeight(null),
         this);
     count += 0.1;
   } else if (player1.getPower().equals("Ball")) {
     g.drawImage(
         ballPower,
         player1.getX() - ballPower.getWidth(null) / 2 + 17,
         player1.getY() + player1.getHeight() - 20,
         ballPower.getWidth(null),
         ballPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Sheild")) {
     g.drawImage(
         sheildPower,
         player1.getX() - ((sheildPower.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((sheildPower.getHeight(null) - player1.getHeight()) / 2),
         sheildPower.getWidth(null),
         sheildPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Umbrella")) {
     g.drawImage(
         umbrellaPower,
         player1.getX() - (umbrellaPower.getWidth(null) / 2) + 20,
         player1.getY() - umbrellaPower.getHeight(null) + 40,
         umbrellaPower.getWidth(null),
         umbrellaPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("")) {
   }
 }
示例#16
0
  @Override
  public void paintIcon(Component c, Graphics g, int x, int y) {
    if (image == null) {
      image = new BufferedImage(getIconWidth(), getIconHeight(), BufferedImage.TYPE_INT_ARGB);
      double coef = Math.min((double) width / (double) 68, (double) height / (double) 81);

      Graphics2D g2d = image.createGraphics();
      g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2d.scale(coef, coef);
      paint(g2d);
      g2d.dispose();
    }

    g.drawImage(image, x, y, null);
  }
示例#17
0
  public void paint(Graphics g) {
    if (offg == null) {
      initScreen();
      // initObjects();
      return;
    }

    // offg.setColor(getBackground());
    offg.setColor(new Color(128, 0, 0));
    offg.fillRect(0, 0, getWidth(), getHeight());

    // IGCore.paint(offg);

    g.drawImage(offscreen, 0, 0, getWidth(), getHeight(), this);
  }
示例#18
0
文件: LJ3MDApp.java 项目: eskilj/mvp
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (model != null) {
     newImgBuf(); // refresh the image buffer if necessary
     // compute the real-to-screen ratio, this variable differs
     // from model.real2Screen by zoomScale
     Dimension sz = getSize();
     double real2Screen0 = model.getScaleFromSpan(realSpan, sz.width, sz.height);
     model.setMatrix(viewMatrix, real2Screen0 * zoomScale, sz.width / 2, sz.height / 2);
     imgG.setColor(Color.BLACK);
     imgG.fillRect(0, 0, sz.width, sz.height);
     model.paint(imgG);
     g.drawImage(img, 0, 0, this);
   }
 }
示例#19
0
 public void moveLayerTwo(Graphics g) { // making it look fancy and shit
   Graphics2D g2d = (Graphics2D) g;
   for (Decorations i : decoList) {
     if (i.isFlipped() == true) { // if its flipped then flip the image or don't
       g2d.drawImage(
           i.getImage(),
           479,
           i.getYTop(),
           -i.getImage().getWidth(null),
           i.getImage().getHeight(null),
           null);
     } else {
       g.drawImage(i.getImage(), 0, i.getYTop(), this);
     }
   }
 }
示例#20
0
 public void drawEnemy(Graphics g) {
   Graphics2D g2d = (Graphics2D) g;
   for (Enemy i : enemyList) {
     if (i.getFlip()) {
       g2d.drawImage(
           i.getPics().get(i.getCounter()),
           i.getX() + i.getWidth(),
           i.getY(),
           -i.getWidth(),
           i.getHeight(),
           null); // flips the image if the flip is true
     } else {
       g.drawImage(
           i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
     }
     i.count();
     i.setDirection();
     i.move();
   }
 }
示例#21
0
    public void doPaint(Graphics g) {
      Graphics2D g2 = (Graphics2D) g;

      g2.setColor(Color.black);

      BufferedImage bimg = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB);
      Graphics ig = bimg.getGraphics();
      Color alphared = new Color(255, 0, 0, 128);
      Color alphagreen = new Color(0, 255, 0, 128);
      Color alphablue = new Color(0, 0, 255, 128);
      ig.setColor(alphared);
      ig.fillRect(0, 0, 200, 200);
      ig.setColor(alphagreen);
      ig.fillRect(25, 25, 150, 150);
      ig.setColor(alphablue);
      ig.fillRect(75, 75, 125, 125);
      g.drawImage(bimg, 10, 25, this);

      GradientPaint gp = new GradientPaint(10.0f, 10.0f, alphablue, 210.0f, 210.0f, alphared, true);
      g2.setPaint(gp);
      g2.fillRect(10, 240, 200, 200);
    }
示例#22
0
 public void paint(Graphics g) {
   Roi roi = imp.getRoi();
   if (roi != null || showAllROIs || overlay != null) {
     if (roi != null) roi.updatePaste();
     if (!IJ.isMacOSX() && imageWidth != 0) {
       paintDoubleBuffered(g);
       return;
     }
   }
   try {
     if (imageUpdated) {
       imageUpdated = false;
       imp.updateImage();
     }
     Java2.setBilinearInterpolation(g, Prefs.interpolateScaledImages);
     Image img = imp.getImage();
     if (img != null)
       g.drawImage(
           img,
           0,
           0,
           (int) (srcRect.width * magnification),
           (int) (srcRect.height * magnification),
           srcRect.x,
           srcRect.y,
           srcRect.x + srcRect.width,
           srcRect.y + srcRect.height,
           null);
     if (overlay != null) drawOverlay(g);
     if (showAllROIs) drawAllROIs(g);
     if (roi != null) drawRoi(roi, g);
     if (srcRect.width < imageWidth || srcRect.height < imageHeight) drawZoomIndicator(g);
     if (IJ.debugMode) showFrameRate(g);
   } catch (OutOfMemoryError e) {
     IJ.outOfMemory("Paint");
   }
 }
示例#23
0
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Graphics
 public void paintComponent(Graphics g) {
   if (pause
       == false) { // if the pause screen is paused then don't move anything and go to the pause
     // screen
     DrawEveryThing(g);
     displayScore(g, 10, 10, 80, 42, 300, 60, 300, 32); // shows the score
     drawPowerUpIcon(g); // draws the powerup icon
     g.drawImage(
         pauseB.getPic(mx, my),
         pauseB.getX(),
         pauseB.getY(),
         this); // Pause button in bottom right-head corner
     changeHeight(); // changes the height
     if (die) {
       showDieMenu();
     }
   } else {
     pauseMenu(
         g); // draws the pause menu , lvlClearmenu or gameOverMenu  depending what screen the user
     // wants to go to
     lvlClearMenu(g);
     gameOverMenu(g);
   }
 }
示例#24
0
 public void drawPowerUpIcon(Graphics g) {
   // draws the powerup the player has on the top
   if (player1.getPower().equals("Umbrella")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/UmbrellaSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Ball")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/BallSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Boost")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/BoostSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Balloon")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/BalloonSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Sheild")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/SheildSymbol.png").getImage(), 200, 10, this);
   } else if (player1.getPower().equals("Magnet")) {
     g.drawImage(
         new ImageIcon("gamelayerstuff/powerups/MagnetSymbol.png").getImage(), 200, 10, this);
   } else {
     g.drawImage(new ImageIcon("gamelayerstuff/powerupbox.png").getImage(), 200, 10, this);
   }
 }
示例#25
0
  /*@Override*/ public void paintIcon(Component c, Graphics g, int x, int y) {
    final boolean expandToFit = (mWidth < 1);

    if (DEBUG.IMAGE && DEBUG.META)
      out(
          "paintIcon; onto="
              + GUI.name(c)
              + " painter="
              + GUI.name(mPainter)
              + "@"
              + Integer.toHexString((mPainter.hashCode())));

    if (mPainter == null) {
      // note this means repaint updates would stop in a new parent,
      // tho assuming it's loaded by then, regular paints would work fine.
      mPainter = c;
    }

    if (DrawBorder && !expandToFit) {
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
    }

    if (mImage == null) {

      if (!isLoading /*&& mPreviewData != null*/) {
        synchronized (this) {
          if (!isLoading /*&& mPreviewData != null*/)
            VUE.invokeAfterAWT(ResourceIcon.this); // load the preview
        }
      }
      g.setColor(Color.gray);
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      return;
    }

    int fitWidth, fitHeight;
    final Dimension maxImageSize;

    if (expandToFit) {
      // fill the given component
      fitWidth = c.getWidth();
      fitHeight = c.getHeight();
      maxImageSize = c.getSize();
    } else {
      // paint at our fixed size
      fitWidth = mWidth;
      fitHeight = mHeight;

      if (DrawBorder)
        maxImageSize = new Dimension(fitWidth - BorderSpace * 2, fitHeight - BorderSpace * 2);
      else maxImageSize = new Dimension(fitWidth, fitHeight);

      if (DEBUG.IMAGE && DEBUG.META) out("paintIcon; into " + GUI.name(maxImageSize));
    }

    double zoomFit;
    if (mImage == NoImage && expandToFit) {
      zoomFit = 1;
    } else {
      Rectangle2D imageBounds;
      if (CropToSquare) {
        // square off image, then fit in icon (todo: better; crop to icon)
        int smallestAxis = mImageWidth > mImageHeight ? mImageHeight : mImageWidth;
        imageBounds = new Rectangle2D.Float(0, 0, smallestAxis, smallestAxis);
      } else {
        // fit entire image in icon
        imageBounds = new Rectangle2D.Float(0, 0, mImageWidth, mImageHeight);
      }
      zoomFit = ZoomTool.computeZoomFit(maxImageSize, 0, imageBounds, null, false);
      if (zoomFit > MaxZoom) zoomFit = MaxZoom;
    }

    final int drawW = (int) (mImageWidth * zoomFit + 0.5);
    final int drawH = (int) (mImageHeight * zoomFit + 0.5);

    int xoff = x;
    int yoff = y;

    // center if drawable area is bigger than image
    if (drawW != fitWidth) xoff += (fitWidth - drawW) / 2;
    if (drawH != fitHeight) yoff += (fitHeight - drawH) / 2;

    Shape oldClip = null;
    if (CropToSquare && !expandToFit) {
      oldClip = g.getClip();
      g.clipRect(x, y, mWidth, mHeight);
    }

    if (DEBUG.IMAGE && DEBUG.META)
      out("paintIcon; " + Util.tag(mImage) + " as " + drawW + "x" + drawH);
    g.drawImage(mImage, xoff, yoff, drawW, drawH, null);

    if (DEBUG.BOXES) {
      g.setColor(Color.green);
      ((Graphics2D) g)
          .setComposite(
              java.awt.AlphaComposite.getInstance(java.awt.AlphaComposite.SRC_OVER, 0.2f));
      g.drawRect(x, y, mWidth - 1, mHeight - 1);
      ((Graphics2D) g).setComposite(java.awt.AlphaComposite.SrcOver);
    }

    if (CropToSquare && !expandToFit) g.setClip(oldClip);
  }
  public void paintComponent(Graphics screen) {
    if (inactive == null) {
      inactive = new Image[BUTTON_COUNT];
      rollover = new Image[BUTTON_COUNT];
      active = new Image[BUTTON_COUNT];

      int IMAGE_SIZE = 33;

      for (int i = 0; i < BUTTON_COUNT; i++) {
        inactive[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        Graphics g = inactive[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -2 * IMAGE_SIZE, null);

        rollover[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = rollover[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -1 * IMAGE_SIZE, null);

        active[i] = createImage(BUTTON_WIDTH, BUTTON_HEIGHT);
        g = active[i].getGraphics();
        g.drawImage(buttons, -(i * IMAGE_SIZE) - 3, -0 * IMAGE_SIZE, null);
      }

      state = new int[buttonCount];
      stateImage = new Image[buttonCount];
      for (int i = 0; i < buttonCount; i++) {
        setState(i, INACTIVE, false);
      }
    }
    Dimension size = getSize();
    if ((offscreen == null) || (size.width != width) || (size.height != height)) {
      offscreen = createImage(size.width, size.height);
      width = size.width;
      height = size.height;

      y1 = 0;
      y2 = BUTTON_HEIGHT;

      x1 = new int[buttonCount];
      x2 = new int[buttonCount];

      int offsetX = 3;
      for (int i = 0; i < buttonCount; i++) {
        x1[i] = offsetX;
        if (i == 2) x1[i] += BUTTON_GAP;
        x2[i] = x1[i] + BUTTON_WIDTH;
        offsetX = x2[i];
      }
    }
    Graphics g = offscreen.getGraphics();
    g.setColor(bgcolor); // getBackground());
    g.fillRect(0, 0, width, height);

    for (int i = 0; i < buttonCount; i++) {
      g.drawImage(stateImage[i], x1[i], y1, null);
    }

    g.setColor(statusColor);
    g.setFont(statusFont);

    /*
    // if i ever find the guy who wrote the java2d api, i will hurt him.
    Graphics2D g2 = (Graphics2D) g;
    FontRenderContext frc = g2.getFontRenderContext();
    float statusW = (float) statusFont.getStringBounds(status, frc).getWidth();
    float statusX = (getSize().width - statusW) / 2;
    g2.drawString(status, statusX, statusY);
    */
    // int statusY = (BUTTON_HEIGHT + statusFont.getAscent()) / 2;
    int statusY = (BUTTON_HEIGHT + g.getFontMetrics().getAscent()) / 2;
    g.drawString(status, buttonCount * BUTTON_WIDTH + 2 * BUTTON_GAP, statusY);

    screen.drawImage(offscreen, 0, 0, null);
  }
示例#27
0
  static void paintShadowTitle(
      Graphics g,
      String title,
      int x,
      int y,
      Color frente,
      Color shadow,
      int desp,
      int tipo,
      int orientation) {

    // Si hay que rotar la fuente, se rota
    Font f = g.getFont();
    if (orientation == SwingConstants.VERTICAL) {
      AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2);
      f = f.deriveFont(rotate);
    }

    // Si hay que pintar sombra, se hacen un monton de cosas
    if (shadow != null) {
      int matrix = (tipo == THIN ? MATRIX_THIN : MATRIX_FAT);

      Rectangle2D rect = g.getFontMetrics().getStringBounds(title, g);

      int w, h;
      if (orientation == SwingConstants.HORIZONTAL) {
        w = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        h = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      } else {
        h = (int) rect.getWidth() + 6 * matrix; // Hay que dejar espacio para las sombras y el borde
        w = (int) rect.getHeight() + 6 * matrix; // que ConvolveOp ignora por el EDGE_NO_OP
      }

      // La sombra del titulo
      BufferedImage iTitulo = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
      BufferedImage iSombra = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

      Graphics2D g2 = iTitulo.createGraphics();
      g2.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

      g2.setFont(f);
      g2.setColor(shadow);
      g2.drawString(title, 3 * matrix, 3 * matrix); // La pintamos en el centro

      ConvolveOp cop =
          new ConvolveOp((tipo == THIN ? kernelThin : kernelFat), ConvolveOp.EDGE_NO_OP, null);
      cop.filter(iTitulo, iSombra); // A ditorsionar

      // Por fin, pintamos el jodio titulo
      g.drawImage(
          iSombra,
          x - 3 * matrix + desp, // Lo llevamos a la posicion original y le sumamos 1
          y - 3 * matrix + desp, // para que la sombra quede pelin desplazada
          null);
    }

    // Si hay que pintar el frente, se pinta
    if (frente != null) {
      g.setFont(f);
      g.setColor(frente);
      g.drawString(title, x, y);
    }
  }
示例#28
0
  public void paint(Graphics gOld) {
    if (image == null || xsize != getSize().width || ysize != getSize().height) {
      xsize = getSize().width;
      ysize = getSize().height;
      image = createImage(xsize, ysize);
      g = (Graphics2D) image.getGraphics();
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    }
    // fill background
    g.setColor(Color.cyan);
    g.fillRect(0, 0, xsize, ysize);

    int x[] = {getX(0), getX(getWidth2()), getX(getWidth2()), getX(0), getX(0)};
    int y[] = {getY(0), getY(0), getY(getHeight2()), getY(getHeight2()), getY(0)};
    // fill border
    g.setColor(Color.black);
    g.fillPolygon(x, y, 4);
    // draw border
    g.setColor(Color.red);
    g.drawPolyline(x, y, 5);

    if (animateFirstTime) {
      gOld.drawImage(image, 0, 0, null);
      return;
    }

    g.drawImage(outerSpaceImage, getX(0), getY(0), getWidth2(), getHeight2(), this);
    g.setColor(Color.yellow);
    for (int i = 0; i < starNum; i++) {
      if (!GameOver)
        drawStar(getX(star[i].getXPos()), getYNormal(star[i].getYPos()), 0.0, 1.0, 1.0);
    }

    g.setColor(Color.white);
    for (int i = 0; i < missle.length; i++) {
      if (missle[i].getActive() && !GameOver) {

        drawCircle(
            getX(missle[i].getXPos()),
            getYNormal(missle[i].getYPos()),
            0.0,
            1.0,
            1.0,
            missle[i].getWidth());
      }
    }
    if (!GameOver) {
      if (!rocketRight)
        drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0, 1.0, 1.0);
      else drawRocket(rocketImage, getX(rocketXPos), getYNormal(rocketYPos), 0, -1.0, 1.0);
    }
    if (ff) {
      drawCircle(getX(rocketXPos), getYNormal(rocketYPos), 0, ffsize, ffsize, ffwidth);
    }

    g.setColor(Color.BLACK);
    g.drawString("Lives: " + lives, 115, 43);
    g.drawString("Score: " + score, 50, 43);

    if (GameOver) {
      g.setColor(Color.WHITE);
      g.drawString("GAMEOVER", getWidth2() / 2, getHeight2() / 2);
      g.drawString("HighScore: " + highscore, getWidth2() / 2, getHeight2() / 2 - 20);
    }

    gOld.drawImage(image, 0, 0, null);
  }
示例#29
0
 public void drawJumper(Graphics g) {
   for (Jumper i : jumperList) {
     g.drawImage(i.getImage(), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
   }
 }
示例#30
0
 public void drawPoof(Graphics g) {
   for (Poof i : poofList) {
     g.drawImage(i.getImage(), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
     i.count();
   }
 }