Beispiel #1
0
  private BufferedImage figureOutDrawImage(Sprite[] imgs) {

    Sprite img;
    if (dead) {
      return imgs[5].getBuffer();
    }

    if (Math.abs((int) (vel.y * 100)) > 0 && !piped) {
      img = imgs[1];
    } else if (!(movingRight || movingLeft) && vel.x == 0) img = imgs[0];
    else {
      if (movingRight && vel.x < 0 || movingLeft && vel.x > 0) img = imgs[4];
      else {
        if (rightFoot) img = imgs[3];
        else img = imgs[2];
      }
    }

    if (star && (starTime < 8000 / 15 || System.currentTimeMillis() % 60 > 30)) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            limg.setPixel(
                x,
                y,
                new Color(
                    255 - pixel.getRed(),
                    255 - pixel.getGreen(),
                    255 - pixel.getBlue(),
                    pixel.getAlpha()));
          }
        }
      }
      img = limg;
    } else if (metal) {
      int width = img.getBuffer().getWidth(), height = img.getBuffer().getHeight();
      Sprite limg = new Sprite(img.getBuffer());
      for (int x = 0; x < width; x++) {
        for (int y = 0; y < height; y++) {
          Color pixel = limg.getPixel(x, y);
          if (pixel.getAlpha() != 0) {
            int gray = (pixel.getRed() + pixel.getBlue() + pixel.getGreen()) / 3;
            limg.setPixel(x, y, new Color(gray, gray, gray, pixel.getAlpha()));
          }
        }
      }
      img = limg;
    }

    if (facingRight) {
      return img.flipX();
    } else {
      return img.getBuffer();
    }
  }