예제 #1
0
    /**
     * Checks if movement is possible from current position in a direction
     * vector specified. Call this only when you are in a center of a labyrinth
     * cell.
     *
     * @param Vector3 newDirection - direction of movement suggested.
     *    Only one of x or y can be non zero. I.e. if x component non-zero then
     *    y must be equal to zero and vice versa.
     * @return bool
     *   - true if movement in suggested direction is possible from current position
     */
    bool IsMovementPossible(Vector3 newDirection)
    {
        Vector2 coords = GetCurrentCellCoords();

        int position_x = Mathf.RoundToInt(coords.x);
        int position_y = Mathf.RoundToInt(coords.y);
        int target_x   = position_x + Mathf.RoundToInt(newDirection.x);
        int target_y   = position_y + Mathf.RoundToInt(newDirection.y);

        LabyrinthController lc = labyrinth.GetComponent <LabyrinthController>();

        return(lc.CanMoveFromCell(position_x, position_y, target_x, target_y));
    }