예제 #1
0
파일: Hero.java 프로젝트: rweichler/wuigi
  private void drawAWP(Graphics g, int x, int y) {
    if (System.currentTimeMillis() < shotTime + TAWP.SHOOT_TIME) {
      // System.out.println(true);
      double multi = 1.0 * (System.currentTimeMillis() - shotTime) / TAWP.SHOOT_TIME;
      g.setColor(new Color(255, 255, 255, 255 - (int) (multi * 256)));
      g.fillRect(0, 0, Wuigi.screenWidth, Wuigi.screenHeight);
    }
    if (numBullets <= 0) return;

    BufferedImage img = TAWP.IMAGE.getBuffer();
    AffineTransform xform = new AffineTransform();
    // g2d.setPaint(new TexturePaint(figureOutDrawImage(),
    //		new Rectangle2D.Float(0, 0, 32, 32)));
    // g2d.drawImage(figureOutDrawImage(),0,0,null);
    xform.setToIdentity();
    xform.translate(x - 5, y);

    double diffY = y + height / 2 - ScreenManager.mouse.y;
    double diffX = ScreenManager.mouse.x - x - width / 2;

    double angle;

    if (diffY > 0 && diffX > 0) {
      angle = Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX > 0) {
      angle = Math.PI / 2;
    } else if (diffY < 0 && diffX > 0) {
      angle = Math.PI / 2 + Math.atan(-diffY / diffX);
    } else if (diffY < 0 && diffX == 0) {
      angle = Math.PI;
    } else if (diffY < 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 - Math.atan(diffY / diffX);
    } else if (diffY == 0 && diffX < 0) {
      angle = 3 * Math.PI / 2;
    } else if (diffY > 0 && diffX < 0) {
      angle = 3 * Math.PI / 2 + Math.atan(-diffY / diffX);
    } else {
      angle = 0;
    }
    angle -= Math.PI / 2;

    if (angle > Math.PI / 2 && angle < 3 * Math.PI / 2) {
      xform.scale(1, -1);
      xform.translate(0, -TAWP.IMAGE.getHeight());
      angle = -angle;
    }
    // xform.scale(/*width/img.getWidth(),height/img.getHeight()*/);
    xform.rotate(angle, 27, 13);

    ((Graphics2D) g).drawImage(img, xform, null);
    ammo.setPos(x + 10, y - 20);
    ammo.draw(g);
  }
예제 #2
0
  protected void transformInverse(int x, int y, float[] out) {
    float theta, t;
    float m, xmax, ymax;
    float r = 0;

    switch (type) {
      case RECT_TO_POLAR:
        theta = 0;
        if (x >= centreX) {
          if (y > centreY) {
            theta =
                ImageMath.PI - (float) Math.atan(((float) (x - centreX)) / ((float) (y - centreY)));
            r = (float) Math.sqrt(sqr(x - centreX) + sqr(y - centreY));
          } else if (y < centreY) {
            theta = (float) Math.atan(((float) (x - centreX)) / ((float) (centreY - y)));
            r = (float) Math.sqrt(sqr(x - centreX) + sqr(centreY - y));
          } else {
            theta = ImageMath.HALF_PI;
            r = x - centreX;
          }
        } else if (x < centreX) {
          if (y < centreY) {
            theta =
                ImageMath.TWO_PI
                    - (float) Math.atan(((float) (centreX - x)) / ((float) (centreY - y)));
            r = (float) Math.sqrt(sqr(centreX - x) + sqr(centreY - y));
          } else if (y > centreY) {
            theta =
                ImageMath.PI + (float) Math.atan(((float) (centreX - x)) / ((float) (y - centreY)));
            r = (float) Math.sqrt(sqr(centreX - x) + sqr(y - centreY));
          } else {
            theta = 1.5f * ImageMath.PI;
            r = centreX - x;
          }
        }
        if (x != centreX) m = Math.abs(((float) (y - centreY)) / ((float) (x - centreX)));
        else m = 0;

        if (m <= ((float) height / (float) width)) {
          if (x == centreX) {
            xmax = 0;
            ymax = centreY;
          } else {
            xmax = centreX;
            ymax = m * xmax;
          }
        } else {
          ymax = centreY;
          xmax = ymax / m;
        }

        out[0] = (width - 1) - (width - 1) / ImageMath.TWO_PI * theta;
        out[1] = height * r / radius;
        break;
      case POLAR_TO_RECT:
        theta = x / width * ImageMath.TWO_PI;
        float theta2;

        if (theta >= 1.5f * ImageMath.PI) theta2 = ImageMath.TWO_PI - theta;
        else if (theta >= ImageMath.PI) theta2 = theta - ImageMath.PI;
        else if (theta >= 0.5f * ImageMath.PI) theta2 = ImageMath.PI - theta;
        else theta2 = theta;

        t = (float) Math.tan(theta2);
        if (t != 0) m = 1.0f / t;
        else m = 0;

        if (m <= ((float) (height) / (float) (width))) {
          if (theta2 == 0) {
            xmax = 0;
            ymax = centreY;
          } else {
            xmax = centreX;
            ymax = m * xmax;
          }
        } else {
          ymax = centreY;
          xmax = ymax / m;
        }

        r = radius * (float) (y / (float) (height));

        float nx = -r * (float) Math.sin(theta2);
        float ny = r * (float) Math.cos(theta2);

        if (theta >= 1.5f * ImageMath.PI) {
          out[0] = (float) centreX - nx;
          out[1] = (float) centreY - ny;
        } else if (theta >= Math.PI) {
          out[0] = (float) centreX - nx;
          out[1] = (float) centreY + ny;
        } else if (theta >= 0.5 * Math.PI) {
          out[0] = (float) centreX + nx;
          out[1] = (float) centreY + ny;
        } else {
          out[0] = (float) centreX + nx;
          out[1] = (float) centreY - ny;
        }
        break;
      case INVERT_IN_CIRCLE:
        float dx = x - centreX;
        float dy = y - centreY;
        float distance2 = dx * dx + dy * dy;
        out[0] = centreX + centreX * centreX * dx / distance2;
        out[1] = centreY + centreY * centreY * dy / distance2;
        break;
    }
  }