/** * Gets whether or not this sensor senses a Pedestrian. * * @param tileMap the PedestrianTileBasedMap to use, to get the TileState, and the resulting * list of Pedestrians in that tile * @return true if a Pedestrian is detected, false otherwise. */ public MovingEntity relativePointSensesEntity(GameMap map) { MovingEntity entitySensed = null; // Get the point of the entity that may encounter an obstacle Point2D.Float relativePoint = this.entity.getRelativePointFromCenter(rx, ry); // Get the tile this point is in Tile tileSensed = map.getTile( (int) (relativePoint.x / GameMap.TILE_SIZE), (int) (relativePoint.y / GameMap.TILE_SIZE)); // Search for an entity in this tile if (tileSensed != null) { LinkedList<Entity> entities = tileSensed.getEntities(); for (Entity e : entities) { if (Math.hypot(relativePoint.x - e.getX(), relativePoint.y - e.getX()) <= SENSOR_RADIUS) { entitySensed = (MovingEntity) e; break; } } } return entitySensed; }
/** * Gets whether or not the PedestrianTileBasedMap tile is blocked, or open. * * @param tileMap the PedestrianTileBasedMap to use * @return true, if the corresponding tile is blocked, false if it is open. */ public boolean relativeTileIsBlocked(GameMap map) { // Get the point of the entity that may encounter an obstacle Point2D.Float relativePoint = this.entity.getRelativePointFromCenter(rx, ry); // Get the tile this point is in Tile tileSensed = map.getTile( (int) (relativePoint.x / GameMap.TILE_SIZE), (int) (relativePoint.y / GameMap.TILE_SIZE)); // Search for an entity in this tile if (tileSensed != null) return tileSensed.isBlocked(); return false; }
/** * Go to somewhere * * @param tile Go to this tile */ public void goTo(Tile tile) { if (tile == null) return; // Initialize visited tiles this.map.clearVisited(); // Search path Path path = this.map.findPath(this, this.tile, tile); // Set path headAlongPath(path); if (path == null) Debug.log("MOVING_ENTITY", "MovingEntity::GoTo:No path found"); else Debug.log("MOVING_ENTITY", "MovingEntity::GoTo " + tile.getColumn() + "," + tile.getRow()); }