コード例 #1
0
  /**
   * This utility function makes it easy to check whether the coordinates of the user's mouse click
   * (px,py) are on (or very close to) the ellipse defined by the bounding box with corners at
   * (x1,y1) and (x2,y2).
   *
   * @param px x coordinate of mouse click
   * @param py y coordinate of mouse click
   * @param x1 x point of the first coordinate of object to check for mouse click proximity
   * @param y1 y point of the first coordinate of object to check for mouse click proximity
   * @param x2 x point of the second coordinate of object to check for mouse click proximity
   * @param y2 y point of the second coordinate of object to check for mouse click proximity
   * @return true if the coordinates of the user's mouse click (px,py) are on close to the ellipse
   *     defined by the bounding box with corners at (x1,y1) and (x2,y2).
   */
  public static boolean clickHitEllipse(int px, int py, int x1, int y1, int x2, int y2) {
    int minX = (x1 < x2 ? x1 : x2);
    int minY = (y1 < y2 ? y1 : y2);
    int maxX = (x1 > x2 ? x1 : x2);
    int maxY = (y1 > y2 ? y1 : y2);

    Ellipse2D.Float innerEllipse =
        new Ellipse2D.Float(
            minX + SELECTION_DISTANCE,
            minY + SELECTION_DISTANCE,
            maxX - minX - 2 * SELECTION_DISTANCE,
            maxY - minY - 2 * SELECTION_DISTANCE);

    Ellipse2D.Float outerEllipse =
        new Ellipse2D.Float(
            minX - SELECTION_DISTANCE,
            minY - SELECTION_DISTANCE,
            maxX - minX + 2 * SELECTION_DISTANCE,
            maxY - minY + 2 * SELECTION_DISTANCE);

    return outerEllipse.contains(px, py) && !innerEllipse.contains(px, py);
  }
コード例 #2
0
ファイル: Bullet.java プロジェクト: michaelatremblay/school
 /** sets the bullet's location by taking in two floats */
 public void setPosition(float x, float y) {
   changedPosition.x = x;
   changedPosition.y = y;
   if (changedPosition.x > Game.width || changedPosition.y > Game.height) expired = true;
   super.setFrame((double) x, (double) y, (double) size, (double) size);
 }
コード例 #3
0
 protected void ellipseImpl(float x, float y, float w, float h) {
   ellipse.setFrame(x, y, w, h);
   drawShape(ellipse);
 }