示例#1
0
 private float randomX(GameContainer c, Shape s) throws MushroomFactoryException {
   float x = -1;
   int numTries = 0;
   while (x < 0 || x >= c.getWidth()) {
     x = (float) (s.getMaxX() - s.getX() * Math.random());
     x += s.getX();
     numTries++;
     if (numTries > 6) {
       throw new MushroomFactoryException("Can't find valid point.");
     }
   }
   return x;
 }
示例#2
0
  public boolean checkCollide(Shape s) {
    int minXTile = (int) (s.getMinX()) / TILESIZE;
    int maxXTile = (int) (s.getMaxX()) / TILESIZE;
    int minYTile = (int) (s.getMinY()) / TILESIZE;
    int maxYTile = (int) (s.getMaxY()) / TILESIZE;

    for (int x = minXTile; x <= maxXTile; x++) {
      for (int y = minYTile; y <= maxYTile; y++) {
        if (tileIntegrity[x][y] > 0
            && s.intersects(new Rectangle(x * TILESIZE, y * TILESIZE, TILESIZE, TILESIZE))) {
          return true;
        }
      }
    }

    return false;
  }
示例#3
0
 /** @see org.newdawn.slick.gui.AbstractComponent#getWidth() */
 public int getWidth() {
   return (int) (area.getMaxX() - area.getX());
 }