Ejemplo n.º 1
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and ellipse.
  *
  * @return Returns true, if the circle is inside of the image bounds.
  */
 private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType() &&
             ellipse.width == ellipse.height
             ) {
         
         Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y);
         Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height);
         t.transform(start, start);
         t.transform(end, end);
         ellipse.x = Math.min(start.x, end.x);
         ellipse.y = Math.min(start.y, end.y);
         ellipse.width = Math.abs(start.x - end.x);
         ellipse.height = Math.abs(start.y - end.y);
         
         elem.setAttribute("shape", "circle");
         elem.setAttribute("coords",
                 (int) (ellipse.x + ellipse.width / 2d)+","+
                 (int) (ellipse.y + ellipse.height / 2d)+","+
                 (int) (ellipse.width / 2d)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(ellipse.getBounds());
     } else {
         return writePolyAttributes(elem, f, (Shape) ellipse);
     }
 }
  public Point getEmptyPosition(Dimension spriteSize) {
    Rectangle trialSpaceOccupied = new Rectangle(0, 0, spriteSize.width, spriteSize.height);
    Random rand = new Random(System.currentTimeMillis());
    boolean empty = false;
    int numTries = 0;

    // Search for an empty position
    while (!empty && numTries++ < 100) {
      // Get a trial position
      trialSpaceOccupied.x = Math.abs(rand.nextInt() % backgroundImage.getSize().width);
      trialSpaceOccupied.y = Math.abs(rand.nextInt() % backgroundImage.getSize().height);
      // Iterate through existing
      // sprites, checking if position
      // is empty
      boolean collision = false;
      for (int cnt = 0; cnt < size(); cnt++) {
        Rectangle testSpaceOccupied = ((Sprite) elementAt(cnt)).getSpaceOccupied();
        if (trialSpaceOccupied.intersects(testSpaceOccupied)) {
          collision = true;
        } // end if
      } // end for loop
      empty = !collision;
    } // end while loop
    return new Point(trialSpaceOccupied.x, trialSpaceOccupied.y);
  } // end getEmptyPosition()
Ejemplo n.º 3
0
 public boolean isCollidingWith(SolidObject what) {
   // Test whether the collision between two solid objex is happening
   compileHull();
   what.compileHull();
   if (collisionHull.intersects(what.collisionHull)) return true;
   return false;
 }
Ejemplo n.º 4
0
 public boolean checkSpawn(Rectangle object) {
   for (Rectangle i : rectList) {
     if (object.intersects(i)) {
       return false;
     }
   }
   return true;
 }
 public boolean testCollision(Sprite testSprite) {
   // Check for collision with
   // another sprite
   if (testSprite != this) {
     return spaceOccupied.intersects(testSprite.getSpaceOccupied());
   } // end if
   return false;
 } // end testCollision
Ejemplo n.º 6
0
 /** Finds a top level Figure that intersects the given rectangle. */
 public Figure findFigure(Rectangle r) {
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     Rectangle fr = figure.displayBox();
     if (r.intersects(fr)) return figure;
   }
   return null;
 }
Ejemplo n.º 7
0
 /**
  * Finds a top level Figure that intersects the given rectangle. It supresses the passed in
  * figure. Use this method to ignore a figure that is temporarily inserted into the drawing.
  */
 public Figure findFigure(Rectangle r, Figure without) {
   if (without == null) return findFigure(r);
   FigureEnumeration k = figuresReverse();
   while (k.hasMoreElements()) {
     Figure figure = k.nextFigure();
     Rectangle fr = figure.displayBox();
     if (r.intersects(fr) && !figure.includes(without)) return figure;
   }
   return null;
 }
Ejemplo n.º 8
0
  public boolean hitbox(Rectangle enemyRect) {
    Rectangle rectum = new Rectangle(1, 1, 1, 1);
    if (this.face == 1) {
      if (this.combo[1] == 0) {
        rectum = new Rectangle((int) (this.xPos), (int) (this.yPos), 64, 64);
      } else if (this.combo[1] == 1) {
        rectum = new Rectangle((int) (this.xPos - 16), (int) (this.yPos - 16), 64, 32);
      } else if (this.combo[1] == 2) {
        rectum = new Rectangle((int) (this.xPos), (int) (this.yPos - 16), 32, 48);
      }
    } else if (this.face == 2) {
      if (this.combo[2] == 0) {
        rectum = new Rectangle((int) (this.xPos), (int) (this.yPos + 32), 64, 50);
      } else if (this.combo[2] == 1) {
        rectum = new Rectangle((int) (this.xPos + 16), (int) (this.yPos), 32, 80);
      } else if (this.combo[2] == 2) {
        rectum = new Rectangle((int) (this.xPos), (int) (this.yPos + 32), 32, 48);
      }
    } else if (this.face == 3) {
      if (this.combo[3] == 0) {
        rectum = new Rectangle((int) (this.xPos - 8), (int) (this.yPos + 48), 32, 32);
      } else if (this.combo[3] == 1) {
        rectum = new Rectangle((int) (this.xPos - 16), (int) (this.yPos), 32, 64);
      } else if (this.combo[3] == 2) {
        rectum = new Rectangle((int) (this.xPos - 16), (int) (this.yPos), 32, 72);
      }
    } else if (this.face == 4) {
      if (this.combo[4] == 0) {
        rectum = new Rectangle((int) (this.xPos + 32), (int) (this.yPos + 48), 32, 32);
      } else if (this.combo[4] == 1) {
        rectum = new Rectangle((int) (this.xPos + 32), (int) (this.yPos), 32, 64);
      } else if (this.combo[4] == 2) {
        rectum = new Rectangle((int) (this.xPos + 32), (int) (this.yPos), 32, 64);
      }
    }

    if (rectum.intersects(enemyRect)) {
      return true;
    }

    return false;
  }
Ejemplo n.º 9
0
 /**
  * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>,
  * <code>nohref</code> Attribute for the specified figure and rectangle.
  *
  * @return Returns true, if the rect is inside of the image bounds.
  */
 private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) {
     AffineTransform t = TRANSFORM.getClone(f);
     if (t == null) {
         t = drawingTransform;
     } else {
         t.preConcatenate(drawingTransform);
     }
     
     if ((t.getType() &
             (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) ==
             t.getType()
             ) {
         
         Point2D.Double start = new Point2D.Double(rect.x, rect.y);
         Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height);
         t.transform(start, start);
         t.transform(end, end);
         Rectangle r = new Rectangle(
                 (int) Math.min(start.x, end.x),
                 (int) Math.min(start.y, end.y),
                 (int) Math.abs(start.x - end.x),
                 (int) Math.abs(start.y - end.y)
                 );
         
         elem.setAttribute("shape", "rect");
         elem.setAttribute("coords",
                 r.x + ","+
                 r.y + ","+
                 (r.x + r.width) + ","+
                 (r.y + r.height)
                 );
         writeHrefAttribute(elem, f);
         return bounds.intersects(r);
     } else {
         return writePolyAttributes(elem, f, (Shape) rect);
     }
 }
Ejemplo n.º 10
0
 public boolean isCollidingWith(Rectangle hull, SolidObject what) {
   // Same, but with raw rectangles
   what.compileHull();
   if (hull.intersects(what.collisionHull)) return true;
   return false;
 }