Example #1
0
    virtual protected void DoNextGenerationStep(ref IntVector2 currentPosition, ref GridDirection currentDirection, ref LDCell currentCell,
                                                ref float turnProb, ref float roomProb)
    {
        //First we move the agent.
        //We change direction by chance or if the next position in the current direction is not in the level.
        if (Random.value < changeDirectionProb || !ContainsCoordinates(currentPosition + currentDirection.ToIntVector2()))
        {
            //Randomly move the agent to a new valid position in the level.
            GridDirection newDir = ChangeDirection(currentPosition, currentDirection);
            currentDirection = newDir;
            turnProb         = changeDirectionProb;
        }
        else
        if (dynamicProbabilities)
        {
            turnProb += changeDirDelta;
        }
        //Now we now the next position!
        currentPosition += currentDirection.ToIntVector2();

        //Make a room?
        if (Random.value < roomProb)
        {
            rooms.Add(CreateRoom(currentPosition, RandomRoomSize));
            roomProb = makeRoomProb;
        }
        else
        {
            //else just open current cell
            currentCell = GetCell(currentPosition);
            if (!currentCell.IsOpen)
            {
                currentCell.SetOpen(true);
            }

            if (dynamicProbabilities)
            {
                roomProb += makeRoomDelta;
            }
        }
    }