Exemple #1
0
    private void AddBossRoom()
    {
        Vector2Int placeToUse  = Vector2Int.zero;
        float      distanceMin = 0f;

        //We want to find the farest room in the level
        foreach (Vector2Int current in _availablePlaces)
        {
            if (_grid.FindPlaceNeighbour(current) == 1)
            {
                //We compute its distance from origin
                float dSqrToTarget = Mathf.Sqrt((_levelCreatedUsed[0].GetPosition() - current).sqrMagnitude);

                //And if it's more than previous we store it
                if (dSqrToTarget > distanceMin)
                {
                    distanceMin = dSqrToTarget;
                    placeToUse  = current;
                }
            }
        }

        Room bufferRoom = Instantiate(_roomsUsed.GetBossRoom());

        bufferRoom.SetPosition(placeToUse);

        _availablePlaces.Remove(placeToUse);

        foreach (Vector2Int current in bufferRoom.GetAllAvailableNeighbourPlaces())
        {
            if (!_availablePlaces.Contains(current))
            {
                _availablePlaces.Add(current);
            }
        }

        _grid.AddRoomToLevel(bufferRoom);
        _levelCreated.Add(bufferRoom);
    }