コード例 #1
0
 public boolean shouldBounceOffWall(double xd, double yd) {
   if (bounceWallTime > 0) return false;
   Tile nextTile =
       level.getTile(
           (int) (pos.x / Tile.WIDTH + Math.signum(xd)),
           (int) (pos.y / Tile.HEIGHT + Math.signum(yd)));
   boolean re = (nextTile != null && !nextTile.canPass(this));
   if (re) bounceWallTime = 10;
   return re;
 }
コード例 #2
0
  public boolean isTargetBehindWall(double dx2, double dy2, Entity e) {
    int x1 = (int) pos.x / Tile.WIDTH;
    int y1 = (int) pos.y / Tile.HEIGHT;
    int x2 = (int) dx2 / Tile.WIDTH;
    int y2 = (int) dy2 / Tile.HEIGHT;

    int dx, dy, inx, iny, a;
    Tile temp;
    Tile dTile1;
    Tile dTile2;
    dx = x2 - x1;
    dy = y2 - y1;
    inx = dx > 0 ? 1 : -1;
    iny = dy > 0 ? 1 : -1;

    dx = java.lang.Math.abs(dx);
    dy = java.lang.Math.abs(dy);

    if (dx >= dy) {
      dy <<= 1;
      a = dy - dx;
      dx <<= 1;
      while (x1 != x2) {
        temp = level.getTile(x1, y1);
        if (!temp.canPass(e)) {
          return true;
        }
        if (a >= 0) {
          dTile1 = level.getTile(x1 + inx, y1);
          dTile2 = level.getTile(x1, y1 + iny);
          if (!(dTile1.canPass(e) || dTile2.canPass(e))) {
            return true;
          }
          y1 += iny;
          a -= dx;
        }
        a += dy;
        x1 += inx;
      }
    } else {
      dx <<= 1;
      a = dx - dy;
      dy <<= 1;
      while (y1 != y2) {
        temp = level.getTile(x1, y1);
        if (!temp.canPass(e)) {
          return true;
        }
        if (a >= 0) {
          dTile1 = level.getTile(x1 + inx, y1);
          dTile2 = level.getTile(x1, y1 + iny);
          if (!(dTile1.canPass(e) || dTile2.canPass(e))) {
            return true;
          }
          x1 += inx;
          a -= dy;
        }
        a += dx;
        y1 += iny;
      }
    }
    temp = level.getTile(x1, y1);
    if (!temp.canPass(e)) {
      return true;
    }
    return false;
  }