예제 #1
0
파일: AI.java 프로젝트: ABB1203/Kack
  protected boolean hasCollided(double xDir, double yDir) {
    if (super.hasCollided(xDir, yDir)) {
      seenPlayer = false;
      return true;
    }

    // Checks if it will collide with other AIs
    for (Mob ai : level.getAIs()) {
      if (!ai.equals(this)) {
        if (getCollisionBox(xDir, yDir).intersects(ai.getCollisionBox())) {
          return true;
        }
      }
    }

    return false;
  }
예제 #2
0
파일: AI.java 프로젝트: ABB1203/Kack
  protected boolean sees(Mob player) {

    double x0 = ((x < player.getX()) ? x : player.getX()) / 16;
    double x1 =
        (((x + sprite.getWidth() > player.getX() + player.getSprite().getWidth())
                    ? x + sprite.getWidth()
                    : player.getX() + player.getSprite().getWidth())
                - 1)
            / 16;
    double y0 = ((y < player.getY()) ? y : player.getY()) / 16;
    double y1 =
        (((y + sprite.getHeight() > player.getY() + player.getSprite().getHeight())
                    ? y + sprite.getHeight()
                    : player.getY() + player.getSprite().getHeight())
                - 1)
            / 16;

    if (x != player.getX())
      getLineEquation(
          x + sprite.getWidth(),
          player.getX() + player.getSprite().getWidth(),
          y + sprite.getHeight(),
          player.getY() + player.getSprite().getHeight());

    for (double yy = y0; yy < y1; yy++) {
      if ((int) x0 != (int) x1) {
        for (double xx = x0; xx <= x1; xx++) {

          if (level.getTile((int) xx, (int) yy).isSolid()) {
            if (yy <= xx * k + m && xx * k + m < yy + 1) return false;
            if (xx <= (yy - m) / k && (yy - m) / k < xx + 1) return false;
          }
        }
      } else if (level.getTile((int) x1, (int) yy).isSolid()) return false;
    }

    if (x != player.getX())
      getLineEquation(
          x + sprite.getWidth(), player.getX() + player.getSprite().getWidth(), y, player.getY());

    for (double yy = y0; yy < y1; yy++) {
      if ((int) x0 != (int) x1) {
        for (double xx = x0; xx <= x1; xx++) {

          if (level.getTile((int) xx, (int) yy).isSolid()) {
            if (yy <= xx * k + m && xx * k + m < yy + 1) return false;
            if (xx <= (yy - m) / k && (yy - m) / k < xx + 1) return false;
          }
        }
      } else if (level.getTile((int) x1, (int) yy).isSolid()) return false;
    }

    if (x != player.getX())
      getLineEquation(
          x + sprite.getWidth(),
          player.getX() + player.getSprite().getWidth(),
          y + sprite.getHeight(),
          player.getY() + sprite.getHeight());

    for (double yy = y0; yy < y1; yy++) {
      if ((int) x0 != (int) x1) {
        for (double xx = x0; xx <= x1; xx++) {

          if (level.getTile((int) xx, (int) yy).isSolid()) {
            if (yy <= xx * k + m && xx * k + m < yy + 1) return false;
            if (xx <= (yy - m) / k && (yy - m) / k < xx + 1) return false;
          }
        }
      } else if (level.getTile((int) x1, (int) yy).isSolid()) return false;
    }

    if (x != player.getX())
      getLineEquation(x, player.getX(), y + sprite.getHeight(), player.getY() + sprite.getHeight());

    for (double yy = y0; yy < y1; yy++) {
      if ((int) x0 != (int) x1) {
        for (double xx = x0; xx <= x1; xx++) {

          if (level.getTile((int) xx, (int) yy).isSolid()) {
            if (yy <= xx * k + m && xx * k + m < yy + 1) return false;
            if (xx <= (yy - m) / k && (yy - m) / k < xx + 1) return false;
          }
        }
      } else if (level.getTile((int) x1, (int) yy).isSolid()) return false;
    }

    // This may be redundant
    if (x != player.getX())
      getLineEquation(
          x + sprite.getWidth() / 2 + 1,
          player.getX() + player.getSprite().getWidth() / 2,
          y + sprite.getHeight() / 2,
          player.getY() + player.getSprite().getHeight() / 2);

    // The value of the first parameter is changed (+1). By doing this, it
    // prevents the AI to spot the player when the situation is like this:
    // P = player
    // M = AI
    // X = wall
    // PX
    // XM
    // If this would not be done, the AI would be able to look through the
    // walls

    for (double yy = y0; yy < y1; yy++) {
      if ((int) x0 != (int) x1) {
        for (double xx = x0; xx <= x1; xx++) {

          if (level.getTile((int) xx, (int) yy).isSolid()) {
            if (yy <= xx * k + m && xx * k + m < yy + 1) return false;
            if (xx <= (yy - m) / k && (yy - m) / k < xx + 1) return false;
          }
        }
      } else if (level.getTile((int) x1, (int) yy).isSolid()) return false;
    }

    return true;
  }
예제 #3
0
파일: AI.java 프로젝트: ABB1203/Kack
 public void tick() {
   super.tick();
 }