Esempio n. 1
0
  public boolean addEntity(Entity e, boolean initial) {
    for (Entity entity : entities) {
      if (e.getBump(true).intersects(entity.getBump(true))) return false;
    }
    entities.add(e);
    e.onSpawn(initial);

    render();

    return true;
  }
Esempio n. 2
0
  public boolean isFreeTile(int x, int y) {
    for (Entity entity : entities) {
      if (entity.getBump(true).intersects(new Rectangle(x, y, Tile.SIZE, Tile.SIZE))) return false;
    }

    return true;
  }
Esempio n. 3
0
  private static void handleAdjacentTiles(Node node) {
    byte[][] neighbors = Game.world.getNeighbors((int) node.t.x, (int) node.t.y);

    for (int i = 0; i < neighbors.length; i++) {
      for (int j = 0; j < neighbors[0].length; j++) {
        if (i == j
            || neighbors[i][j] == Tile.empty.getId()
            || (i == 0 && j == 2)
            || (i == 2 && j == 0)) continue;

        Vector tile = new Vector(node.t.x + i - 1, node.t.y + j - 1);
        Node n =
            new Node(
                node.G + Tile.getTileForId(neighbors[i][j]).G,
                tile.getDistance(target),
                tile,
                node);

        if (closedList.contains(n)) continue;

        if (openList.contains(n) && openList.get(openList.indexOf(n)).G > n.G) {
          openList.get(openList.indexOf(n)).G = n.G;
          openList.get(openList.indexOf(n)).p = node;
        } else if (!openList.contains(n)) {
          boolean free = true;
          for (Entity e : Game.world.entities) {
            if (e.getBump(true)
                    .intersects(
                        tile.x * Tile.SIZE + 8,
                        tile.y * Tile.SIZE + 8,
                        Tile.SIZE - 16,
                        Tile.SIZE - 16)
                && e.isMassive()) {
              free = false;
              break;
            }
          }

          if (free || n.H == 0) openList.add(n);
        }
      }
    }
  }