Example #1
0
    private Direction ChooseFrightenedModeDirection(List <Direction> validDirections)
    {
        var filteredValidDirection = validDirections.FindAll(
            dir => !DirectionHelper.DirectionsAreOpposite(currentDirection, dir));
        var index = Random.Range(0, filteredValidDirection.Count);

        return(filteredValidDirection[index]);
    }
Example #2
0
 // If input direction is opposite to current direction, update target and return true
 private bool ValidateOppositeInputDirection(Direction inputDirection, Direction currentDirection)
 {
     if (!DirectionHelper.DirectionsAreOpposite(inputDirection, currentDirection))
     {
         return(false);
     }
     UpdateTargetTileCoordinates(EntityId.Player, entitiesTargetTileCoordinates[EntityId.Player], inputDirection);
     return(true);
 }
Example #3
0
    private Direction ChooseDirection(Vector2Int currentTile, Vector2Int targetTile, List <Direction> validDirections)
    {
        Direction chosenDirection = currentDirection; // Dummy value
        var       leastDistance   = float.MaxValue;

        foreach (var direction in validDirections)
        {
            if (DirectionHelper.DirectionsAreOpposite(currentDirection, direction))
            {
                continue;
            }

            var xCoord = currentTile.x;
            var yCoord = currentTile.y;
            switch (direction)
            {
            case Direction.Down:
                yCoord += 1;
                break;

            case Direction.Up:
                yCoord -= 1;
                break;

            case Direction.Right:
                xCoord += 1;
                break;

            case Direction.Left:
                xCoord -= 1;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Vector2Int projectedTile = new Vector2Int(xCoord, yCoord);
            var        distance      = Vector2Int.Distance(targetTile, projectedTile);
            if (distance < leastDistance)
            {
                chosenDirection = direction;
                leastDistance   = distance;
            }
        }
        return(chosenDirection);
    }