示例#1
0
 /**
  * Returns a bounding rectangle of this element. Bounding rectangles are used for a simple
  * algorithm of collision detection.
  *
  * @return the bounding rectangle of this element
  * @see #getRelativeRect()
  */
 public final Rectangle getAbsoluteRect() {
   Rectangle rel = getRelativeRect();
   Vector2D location = getLocation();
   return new Rectangle(
       location.getX() + rel.getX(),
       location.getY() + rel.getY(),
       rel.getWidth(),
       rel.getHeight());
 }
示例#2
0
 public void move(Game game, double dt) {
   boolean xMoved = game.tryMoveBy(this, new Vector2D(velocity.getX() * dt, 0));
   boolean yMoved = game.tryMoveBy(this, new Vector2D(0, velocity.getY() * dt));
   Vector2D possibleV = velocity.add(acceleration.multiply(dt));
   velocity = new Vector2D(xMoved ? possibleV.getX() : 0, yMoved ? possibleV.getY() : 0);
 }
示例#3
0
 public static double distance(Element a, Element b) {
   return Vector2D.distance(a.getLocation(), b.getLocation());
 }