Example #1
0
 @Override
 public void keyPressed(int k) {
   if (k == KeyEvent.VK_SPACE) {
     if (textEventListener.isPlaying()) {
       textEventListener.keyPressed(k);
     } else if (fire.intersects(
         new Rectangle(player.getX(), player.getY(), player.getWidth(), player.getHeight()))) {
       gsm.setState(GameStateManager.FIRESTATE);
     } else if (earth.intersects(
         new Rectangle(player.getX(), player.getY(), player.getWidth(), player.getHeight()))) {
       gsm.setState(GameStateManager.EARTHSTATE);
     } else if (water.intersects(
         new Rectangle(player.getX(), player.getY(), player.getWidth(), player.getHeight()))) {
       gsm.setState(GameStateManager.WATERSTATE);
     } else if (air.intersects(
         new Rectangle(player.getX(), player.getY(), player.getWidth(), player.getHeight()))) {
       gsm.setState(GameStateManager.AIRSTATE);
     }
   }
   if (paused) {
     pauseMenu.keyPressed(k);
   }
   if (k == KeyEvent.VK_ESCAPE) {
     pauseMenu.init();
     paused = !paused;
   }
   player.keyPressed(k);
 }
Example #2
0
  boolean checkTileCollision(Tile t) {
    Rectangle r1 = new Rectangle(getX(), getY(), WIDTH, HEIGHT);
    if (t.getCollisionType() != 0) {
      Rectangle r2Whole = new Rectangle(t.getX(), t.getY(), 32, 32);
      return (r1.intersects(r2Whole) || r2Whole.intersects(r1));
    } else {
      Rectangle r2p1 = new Rectangle(t.getX(), t.getY(), 16, 16);
      Rectangle r2p2 = new Rectangle(t.getX() + 16, t.getY(), 16, 16);
      Rectangle r2p3 = new Rectangle(t.getX(), t.getY() + 16, 16, 16);
      Rectangle r2p4 = new Rectangle(t.getX() + 16, t.getY() + 16, 16, 16);

      // check collision on the first quadrant if the byte is 1
      if (t.getTileByte(0) == 1) {
        return (r1.intersects(r2p1) || r2p1.intersects(r1));
        // check collision on the second quadrant if the byte is 1
      } else if (t.getTileByte(1) == 1) {
        return (r1.intersects(r2p2) || r2p2.intersects(r1));
        // check collision on the third quadrant if the byte is 1
      } else if (t.getTileByte(2) == 1) {
        return (r1.intersects(r2p3) || r2p3.intersects(r1));
        // check collision on the fourth quadrant if the byte is 1
      } else if (t.getTileByte(3) == 1) {
        return (r1.intersects(r2p4) || r2p4.intersects(r1));
        // otherwise this tile does not have any bytes that are handled
        // we could add different types of collisions
      } else {
        return false;
      }
    }
  }
Example #3
0
  public void checkCollisions() {

    Rectangle r3 = craft.getBounds();

    for (int j = 0; j < aliens.size(); j++) {
      Alien a = (Alien) aliens.get(j);
      Rectangle r2 = a.getBounds();

      if (r3.intersects(r2)) {
        craft.setVisible(false);
        a.setVisible(false);
        ingame = false;
      }
    }

    ArrayList ms = craft.getMissiles();

    for (int i = 0; i < ms.size(); i++) {
      Missile m = (Missile) ms.get(i);

      Rectangle r1 = m.getBounds();

      for (int j = 0; j < aliens.size(); j++) {
        Alien a = (Alien) aliens.get(j);
        Rectangle r2 = a.getBounds();

        if (r1.intersects(r2)) {
          m.setVisible(false);
          a.setVisible(false);
        }
      }
    }
  }
  public void checarColisoes() {
    Rectangle formaNave = nave.getBounds();
    Rectangle formaInimigo;
    Rectangle formaMissel;

    for (int i = 0; i < inimigos.size(); i++) {

      Inimigo tempInimigo = inimigos.get(i);
      formaInimigo = tempInimigo.getBounds();

      if (formaNave.intersects(formaInimigo)) {
        nave.setVisivel(false);
        tempInimigo.setVisible(false);
        emJogo = false;
      }
    }

    List<Missel> misseis = nave.getMisseis();

    for (int i = 0; i < misseis.size(); i++) {
      Missel tempMissel = misseis.get(i);
      formaMissel = tempMissel.getBounds();

      for (int j = 0; j < inimigos.size(); j++) {
        Inimigo tempInimigo = inimigos.get(j);
        formaInimigo = tempInimigo.getBounds();

        if (formaMissel.intersects(formaInimigo)) {
          tempInimigo.setVisible(false);
          tempMissel.setVisible(false);
        }
      }
    }
  }
Example #5
0
  public void checkCollisions() {

    Rectangle r3 = link.getBounds();

    for (int j = 0; j < enemies.size(); j++) {
      Enemy en = (Enemy) enemies.get(j);
      Rectangle r2 = en.getBounds();

      if (r3.intersects(r2)) {
        link.setVisible(false);
        en.setVisible(false);
        ingame = false;
        gamewin = false;
      } // end if
    } // end for loop

    ArrayList as = link.getArrows();

    for (int i = 0; i < as.size(); i++) {
      Arrow aa = (Arrow) as.get(i);

      Rectangle r1 = aa.getBounds();

      for (int j = 0; j < enemies.size(); j++) {
        Enemy a = (Enemy) enemies.get(j);
        Rectangle r2 = a.getBounds();

        if (r1.intersects(r2)) {
          aa.setVisible(false);
          a.setVisible(false);
        } // end of if
      } // end inner for loop
    } // end outer for loop
  } // end checkCollisions
Example #6
0
 private void checkCollision() {
   if (r.intersects(Robot.rect)
       || r.intersects(Robot.rect2)
       || r.intersects(Robot.rect3)
       || r.intersects(Robot.rect4)) {
     System.out.println("collision");
   }
 }
 private void scheduleTileForRendering(final Tile tile) {
   //        System.out.println("Scheduling tile for rendering: " + tile.getX() + ", " +
   // tile.getY());
   if (SwingUtilities.isEventDispatchThread()) {
     Rectangle visibleArea = ((JViewport) getParent()).getViewRect();
     Rectangle tileBounds = zoom(getTileBounds(tile.getX(), tile.getY()));
     if (tileBounds.intersects(visibleArea)) {
       // The tile is (partially) visible, so it should be repainted
       // immediately
       switch (refreshMode) {
         case IMMEDIATE:
           threeDeeRenderManager.renderTile(tile);
           break;
         case DELAYED:
           tilesWaitingToBeRendered.add(tile);
           lastTileChange = System.currentTimeMillis();
           break;
         case MANUAL:
           // Do nothing
           break;
         default:
           throw new InternalError();
       }
     } else {
       // The tile is not visible, so repaint it when it becomes visible
       tilesWaitingToBeRendered.remove(tile);
       renderedTiles.remove(tile);
     }
   } else {
     SwingUtilities.invokeLater(
         () -> {
           Rectangle visibleArea = ((JViewport) getParent()).getViewRect();
           Rectangle tileBounds = zoom(getTileBounds(tile.getX(), tile.getY()));
           if (tileBounds.intersects(visibleArea)) {
             // The tile is (partially) visible, so it should be repainted
             // immediately
             switch (refreshMode) {
               case IMMEDIATE:
                 threeDeeRenderManager.renderTile(tile);
                 break;
               case DELAYED:
                 tilesWaitingToBeRendered.add(tile);
                 lastTileChange = System.currentTimeMillis();
                 break;
               case MANUAL:
                 // Do nothing
                 break;
               default:
                 throw new InternalError();
             }
           } else {
             // The tile is not visible, so repaint it when it becomes visible
             tilesWaitingToBeRendered.remove(tile);
             renderedTiles.remove(tile);
           }
         });
   }
 }
Example #8
0
  public void checkVerticalCollision(Rectangle rtop, Rectangle rbot) {
    if (rtop.intersects(r)) {}

    if (rbot.intersects(r) && type == 8) {
      robot.setJumped(false);
      robot.setSpeedY(0);
      robot.setCenterY(tileY - 63);
    }
  }
  public void update(
      Character[] targets, List<Rectangle> list) { // use delta for framerate independency

    // Calculate rotation
    double closestPlayer_x = 0;
    double closestPlayer_y = 0;
    double closestPlayer_range = 100000000;
    for (Character target : targets) {
      if (target != null) {
        double dx = Math.abs(target.x - this.x);
        double dy = Math.abs(target.y - this.y);
        double range = Math.sqrt((dx * dx) + (dy * dy));
        if (closestPlayer_range > range) {
          closestPlayer_range = range;
          closestPlayer_x = target.x;
          closestPlayer_y = target.y;
        }
      }
    }
    rotateTo(closestPlayer_x, closestPlayer_y);

    // Calculate movement
    double speed = 2;
    if (havingKnockback > 0) {
      havingKnockback--; // -delta
      speed = -20;
    }

    double rotation_rads = Math.toRadians(rotation);
    double dx = (speed * Math.cos(rotation_rads));
    double dy = (speed * Math.sin(rotation_rads));

    // COLLISION DETECTION

    boolean canMoveX = true;
    boolean canMoveY = true;
    for (Rectangle rectangle : list) {
      Rectangle r1_x =
          new Rectangle(
              (int) (x - 13 + dx),
              (int) (y - 13),
              26,
              26); // TODO: use delta here aswell (see Player class in which it is implemented)
      Rectangle r1_y = new Rectangle((int) (x - 13), (int) (y - 13 + dy), 26, 26);

      if (rectangle.intersects(r1_x)) {
        canMoveX = false;
      }
      if (rectangle.intersects(r1_y)) {
        canMoveY = false;
      }
    }

    if (canMoveX) // delta here aswell?
    x += dx;
    if (canMoveY) y += dy;
  }
Example #10
0
  /** Checks all collisions between collidables */
  public void checkCollisions() {

    ArrayList<Bullet> bulletList =
        boat
            .getBulletsList(); // fire methodu çağıtıldığında boatun içinde oluşan bulletların
                               // listesi
    Rectangle boatBound = boat.getBounds();

    // boat ve ada çarpışması
    for (int i = 0; i < islands.size(); i++) {
      Island is = (Island) islands.get(i);
      Rectangle islandBound = is.getBounds();
      if (boatBound.intersects(islandBound)) {
        boat.setVisible(false);
      }
    }

    // boat ve buoy çarpışması
    for (int i = 0; i < buoys.size(); i++) {
      Buoy b = (Buoy) buoys.get(i);
      Rectangle buoyBound = b.getBounds();
      if (boatBound.intersects(buoyBound)) {
        b.setVisible(false);
        // timer.stop();
      }
    }

    // boat ve uncracked/cracked bonus çarpışması
    for (int i = 0; i < bonuses.size(); i++) {
      Bonus b = (Bonus) bonuses.get(i);
      Rectangle bonusBound = b.getBounds();
      if (boatBound.intersects(bonusBound)) {
        if (!b.isCracked()) { // boat&uncracked bonus çarpışması
          boat.setVisible(false);
        } else { // boat&bonus çarpışması
          b.setVisible(false);
        }
      }
    }

    // bullet ve bonus(uncracked) çarpışması
    for (int i = 0; i < bulletList.size(); i++) {
      Bullet bu = (Bullet) bulletList.get(i);
      Rectangle bulletBound = bu.getBounds();
      for (int k = 0; k < bonuses.size(); k++) {
        Bonus bo = (Bonus) bonuses.get(k);
        Rectangle bonusBound = bo.getBounds();
        if (bonusBound.intersects(bulletBound) && !bo.isCracked()) {
          bo.setCracked(true);
          // bo.setBonusImage(bo.getBonusType());//burası çok önemli, bonus baştan yaratılıyor
          // sayılır.
          bo.setRandomBonusImage();
          bu.setVisible(false);
        }
      }
    }
  }
Example #11
0
  /**
   * @param other
   * @return true if the objects occupy the same space
   */
  public boolean collides(GameObject other) {
    me.setBounds((int) x, (int) y, (int) dx, (int) dy);
    him.setBounds((int) other.getX(), (int) other.getY(), (int) other.getDx(), (int) other.getDy());

    if (me.intersects(him) || him.intersects(me)) {
      return true;
    } else {
      return false;
    }
  }
 /**
  * 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);
     }
 }
Example #13
0
  @Override
  public void show(
      final Component owner,
      final int aScreenX,
      final int aScreenY,
      final boolean considerForcedXY) {
    LOG.assertTrue(!isDisposed());

    Rectangle targetBounds =
        new Rectangle(new Point(aScreenX, aScreenY), getContent().getPreferredSize());
    ScreenUtil.moveRectangleToFitTheScreen(targetBounds);

    if (getParent() != null) {
      final Rectangle parentBounds = getParent().getBounds();
      parentBounds.x += STEP_X_PADDING;
      parentBounds.width -= STEP_X_PADDING * 2;
      if (parentBounds.intersects(targetBounds)) {
        targetBounds.x = getParent().getBounds().x - targetBounds.width - STEP_X_PADDING;
      }
    }

    if (getParent() == null) {
      PopupDispatcher.setActiveRoot(this);
    } else {
      PopupDispatcher.setShowing(this);
    }

    LOG.assertTrue(!isDisposed(), "Disposed popup, parent=" + getParent());
    super.show(owner, targetBounds.x, targetBounds.y, true);
  }
Example #14
0
 public boolean onScreen(Rectangle r) {
   if (r.intersects(new Rectangle(0, 0, getWidth(), getHeight()))) {
     return true;
   } else {
     return false;
   }
 }
Example #15
0
  public WritableRaster copyData(WritableRaster wr) {
    // Get my source.
    CachableRed src = (CachableRed) getSources().get(0);

    Rectangle srcR = src.getBounds();
    Rectangle wrR = wr.getBounds();

    if (wrR.intersects(srcR)) {
      Rectangle r = wrR.intersection(srcR);

      // Limit the raster I send to my source to his rect.
      WritableRaster srcWR;
      srcWR = wr.createWritableChild(r.x, r.y, r.width, r.height, r.x, r.y, null);
      src.copyData(srcWR);
    }

    if (padMode == PadMode.ZERO_PAD) {
      handleZero(wr);
    } else if (padMode == PadMode.REPLICATE) {
      handleReplicate(wr);
    } else if (padMode == PadMode.WRAP) {
      handleWrap(wr);
    }

    return wr;
  }
  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()
Example #17
0
  public boolean collidesWith(Entity other) {

    me.setBounds((int) x, (int) y, sprite.getWidth(), sprite.getHeight());
    him.setBounds((int) other.x, (int) other.y, other.sprite.getWidth(), other.sprite.getHeight());

    return me.intersects(him);
  }
Example #18
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;
 }
  /**
   * Paints the word-wrapped text.
   *
   * @param g The graphics context in which to paint.
   * @param a The shape (usually a rectangle) in which to paint.
   */
  public void paint(Graphics g, Shape a) {

    Rectangle alloc = (a instanceof Rectangle) ? (Rectangle) a : a.getBounds();
    tabBase = alloc.x;

    Graphics2D g2d = (Graphics2D) g;
    host = (RSyntaxTextArea) getContainer();
    int ascent = host.getMaxAscent();
    int fontHeight = host.getLineHeight();
    FoldManager fm = host.getFoldManager();
    TokenPainter painter = host.getTokenPainter();
    Element root = getElement();

    // Whether token styles should always be painted, even in selections
    int selStart = host.getSelectionStart();
    int selEnd = host.getSelectionEnd();
    boolean useSelectedTextColor = host.getUseSelectedTextColor();

    int n = getViewCount(); // Number of lines.
    int x = alloc.x + getLeftInset();
    tempRect.y = alloc.y + getTopInset();
    Rectangle clip = g.getClipBounds();
    for (int i = 0; i < n; i++) {

      tempRect.x = x + getOffset(X_AXIS, i);
      // tempRect.y = y + getOffset(Y_AXIS, i);
      tempRect.width = getSpan(X_AXIS, i);
      tempRect.height = getSpan(Y_AXIS, i);
      // System.err.println("For line " + i + ": tempRect==" + tempRect);

      if (tempRect.intersects(clip)) {
        Element lineElement = root.getElement(i);
        int startOffset = lineElement.getStartOffset();
        int endOffset = lineElement.getEndOffset() - 1; // Why always "-1"?
        View view = getView(i);
        if (!useSelectedTextColor
            || selStart == selEnd
            || (startOffset >= selEnd || endOffset < selStart)) {
          drawView(painter, g2d, alloc, view, fontHeight, tempRect.y + ascent);
        } else {
          // System.out.println("Drawing line with selection: " + i);
          drawViewWithSelection(
              painter, g2d, alloc, view, fontHeight, tempRect.y + ascent, selStart, selEnd);
        }
      }

      tempRect.y += tempRect.height;

      Fold possibleFold = fm.getFoldForLine(i);
      if (possibleFold != null && possibleFold.isCollapsed()) {
        i += possibleFold.getCollapsedLineCount();
        // Visible indicator of collapsed lines
        Color c = RSyntaxUtilities.getFoldedLineBottomColor(host);
        if (c != null) {
          g.setColor(c);
          g.drawLine(x, tempRect.y - 1, alloc.width, tempRect.y - 1);
        }
      }
    }
  }
Example #20
0
  public static boolean collision(int xCord, int yCord, boolean b) {

    if (GameData.isValid(xCord, yCord) && GameData.instance().blockMap[xCord][yCord] != null) {
      return true;
    }

    if (b) {

      Point p = Frame.game.m.cordToPos(xCord, yCord);
      Rectangle r1 = new Rectangle(p.x, p.y, 60, 60);

      for (int i = 0; i < GameData.instance().entityList.size(); i++) {
        Entity e = GameData.instance().entityList.get(i);

        if (e.isSolid()) {
          Rectangle r2 = e.getBounds();

          if (r1.intersects(r2)) {
            return true;
          }
        }
      }
    }

    return false;
  }
 private boolean noIntersections(Rectangle bounds) {
   Window owner = SwingUtilities.getWindowAncestor(myComponent);
   Window popup = SwingUtilities.getWindowAncestor(myTipComponent);
   Window focus = WindowManagerEx.getInstanceEx().getMostRecentFocusedWindow();
   if (focus == owner.getOwner()) {
     focus = null; // do not check intersection with parent
   }
   boolean focused = SystemInfo.isWindows || owner.isFocused();
   for (Window other : owner.getOwnedWindows()) {
     if (!focused && !SystemInfo.isWindows) {
       focused = other.isFocused();
     }
     if (popup != other
         && other.isVisible()
         && bounds.x + 10 >= other.getX()
         && bounds.intersects(other.getBounds())) {
       return false;
     }
     if (focus == other) {
       focus = null; // already checked
     }
   }
   return focused
       && (focus == owner || focus == null || !owner.getBounds().intersects(focus.getBounds()));
 }
Example #22
0
 /** Checks if the player collides with a blip, power blip, or a ghost. */
 public void checkCollision() {
   Rectangle playerRect =
       new Rectangle(player.getCenter().x - 8, player.getCenter().y - 8, 13, 13);
   for (Enemy enemy : enemies) {
     Rectangle enemyRect = new Rectangle(enemy.getCenter().x - 8, enemy.getCenter().y - 8, 13, 13);
     if (playerRect.intersects(enemyRect)) {
       if (!enemy.isAlive()) {
         continue;
       }
       if (Globals.state == ENEMY_HUNTER_STATE) {
         Globals.game.playerKilled();
         player.loseALife();
         // player is dead, so we paint the dead player screen
         paintDeadPlayer();
         try {
           // sleep to make it stay on screen
           Thread.sleep(1500);
         } catch (InterruptedException e) {
           // DO nothing
         }
         resetCanvas();
         // we return because only one enemy should be able to make a player lose a life
         return;
       } else if (Globals.state == ENEMY_HUNTED_STATE) {
         if (enemy.isAlive()) {
           enemy.setAlive(false);
           player.addPoints(POINTS_FOR_KILLING_ENEMY);
         }
       }
     } else {
       continue;
     }
   }
 }
 private boolean checkLayering(Area b) {
   ArrayList<Number> id = getVisible();
   Vector<Rectangle> rects = new Vector<Rectangle>(id.size());
   for (Number n : id) {
     rects.add(getIE().get(n).toRectangle());
   }
   Rectangle r = b.toRectangle();
   int index = 0;
   for (Rectangle rect : rects) {
     if (r.equals(rect)) {
       index = rects.indexOf(rect) + 1;
     }
   }
   for (int i = index; i < rects.size(); i++) {
     Rectangle rect = rects.get(i);
     if (r.intersects(rect)) {
       Rectangle isect = r.intersection(rect);
       isect.setRect(isect.x, isect.y, isect.getWidth() + 1, isect.getHeight() + 2);
       if (isect.contains(mascot.getAnchor())) {
         return false;
       }
     }
   }
   return true;
 }
Example #24
0
 private int countAttackableElixirs(
     final List<RegionMatch> doFindAll, final List<Rectangle> matchedElixirs, final Path next) {
   int attackableElixirs = 0;
   int c = 0;
   RECT_LOOP:
   for (final RegionMatch i : doFindAll) {
     // if matched area is out of enemy poly
     if (!ENEMY_BASE_POLY.contains(i.x, i.y)) {
       continue;
     }
     // check if it's an existing match
     for (final Rectangle r : matchedElixirs) {
       if (r.intersects(i.getBounds())) {
         break RECT_LOOP;
       }
     }
     c++;
     matchedElixirs.add(i.getBounds());
     if (next.getFileName().toString().startsWith("empty")) {
       attackableElixirs--;
     } else if (next.getFileName().toString().startsWith("full")) {
       attackableElixirs++;
     }
     logger.finest("\t" + i.getBounds() + " score: " + i.getScore());
   }
   if (c > 0) {
     logger.finest(
         String.format("\tfound %d elixirs matching %s\n", c, next.getFileName().toString()));
   }
   return attackableElixirs;
 }
 public static boolean isPointNearPoint(Point from, Point testPos, int nearTolerance) {
   Rectangle r1 =
       new Rectangle(
           from.x - nearTolerance / 2, from.y - nearTolerance / 2, nearTolerance, nearTolerance);
   Rectangle r2 = new Rectangle(testPos.x, testPos.y, 1, 1);
   return r2.intersects(r1);
 }
 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
 protected void updateFalling() {
   for (Ground g : handler.ground) {
     if (rect.intersects(g.getTopRect()) && (velocity.y > 0 || !falling)) {
       hitGround();
       return;
     }
   }
   falling = true;
 }
Example #29
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;
 }
Example #30
0
  public void update() {
    follow();
    centerX += speedX;
    speedX = bg.getSpeedX() * 5 + movementSpeed;
    r.setBounds(centerX - 25, centerY - 25, 50, 60);

    if (r.intersects(Robot.yellowRed)) {
      checkCollision();
    }
  }