Beispiel #1
0
    //private float GetPlayerDisplacement(int direction, int threshold, bool isVertical)
    //{
    //    if (Mathf.Abs(direction) != 1)
    //        throw new InvalidOperationException("Direction must be either 1 or -1");

    //    var playerY = (int)_player.LocalPosition.y;
    //    var playerX = (int)_player.LocalPosition.x;
    //    var destination = playerY + direction;
    //    var currentCell = _grid[playerX, playerY];

    //    while (destination >= 0 && destination < threshold)
    //    {
    //        currentCell = _grid[playerX, destination];

    //        if (!currentCell.Empty)
    //            break;

    //        destination += direction;
    //    }

    //    if (!CanPlayerActivateTheItemInCell(currentCell))
    //        destination -= direction;

    //    return Mathf.Abs(destination - playerY) * direction;
    //}

    private bool CanPlayerActivateTheItemInCell(Cell currentCell)
    {
        return(!currentCell.Empty && currentCell.AcceptPlayer(_player));
    }