public GameEntity getEntityAt(int x, int y) {
        GameEntity entity = null;

        if (x >= 0 && x < width && y >= 0 && y < height) {
            MapSquare square = mapSquares[x][y];

            if (square.isOccupied()) {
                entity = square.getActor();
            } else if (square.isPortal()) {
                entity = square.getPortal();
            } else if (square.hasItems()) {
                entity = square.topOfPile();
            }
        }

        return entity;
    }