Ejemplo n.º 1
0
    // generate the puzzles in the puzzle rooms, globally using photon objects
    public void GeneratePuzzles(List <int> activePuzzleTypes)
    {
        for (int r = 0; r < 3; r++)
        {
            int  puzzleType   = activePuzzleTypes[r];
            bool keyGenerated = false;
            // lava room
            if (puzzleType == 0)
            {
                for (int c = 0; c < puzzleRooms[r].getCells().Count; c++)
                {
                    // use Perlin noise to find lava areas
                    float    generatedNoise;
                    MazeCell currentCell = puzzleRooms[r].getCells()[c];
                    generatedNoise = Mathf.PerlinNoise((currentCell.coordinates.x * currentCell.coordinates.x) / (float)mazeGenerationNumber, (currentCell.coordinates.z * currentCell.coordinates.z) / (float)mazeGenerationNumber);
                    if (generatedNoise < 0.5)
                    {
                        // add mist particle systems
                        MazeCell   addHere = puzzleRooms[r].getCells()[c];
                        Vector3    lavaPos = new Vector3(addHere.transform.position.x, 0f, addHere.transform.position.z);
                        Quaternion lavaRot = new Quaternion(0f, 0f, 0f, 0f);
                        PhotonNetwork.InstantiateSceneObject("FireyMist", lavaPos, lavaRot, 0);
                    }
                }
            }
            // minefield
            else if (puzzleType == 1)
            {
                float mineMultiplier = puzzleRooms[r].getCells().Count / 20f;
                // spawn mines of varying size and damage based on Perlin noise
                // number of mines varies with room size
                for (int c = 0; c < puzzleRooms[r].getCells().Count; c++)
                {
                    MazeCell currentCell   = puzzleRooms[r].getCells()[c];
                    float    chanceForMine = Mathf.PerlinNoise((currentCell.coordinates.x * currentCell.coordinates.x) / (float)mazeGenerationNumber, (currentCell.coordinates.z * currentCell.coordinates.z) / (float)mazeGenerationNumber);
                    if (chanceForMine < 0.25f * mineMultiplier)
                    {
                        // generate a mine
                        float      mineX    = currentCell.transform.position.x + Mathf.PerlinNoise(currentCell.coordinates.x / (float)mazeGenerationNumber, currentCell.coordinates.x / (float)mazeGenerationNumber);
                        float      mineZ    = currentCell.transform.position.z + Mathf.PerlinNoise(currentCell.coordinates.z / (float)mazeGenerationNumber, currentCell.coordinates.z / (float)mazeGenerationNumber);
                        float      mineSize = Mathf.PerlinNoise(c / (float)mazeGenerationNumber, c / (float)mazeGenerationNumber);
                        Vector3    spawnPos = new Vector3(mineX, -0.45f, mineZ);
                        Quaternion spawnRot = new Quaternion(0f, 0f, 0f, 0f);
                        GameObject newGO    = (GameObject)PhotonNetwork.InstantiateSceneObject("Mine", spawnPos, spawnRot, 0);
                        Mine       newMine  = newGO.GetComponent <Mine>();
                        newMine.setMine(mineSize);
                        CapsuleCollider cap = newMine.GetComponent <CapsuleCollider>();
                        cap.center = new Vector3(0f, 0.5f, 0f);
                        cap.radius = 0.7f;
                        mineList.Add(newMine);
                    }
                    // spawn a key
                    else if (keyGenerated == false)
                    {
                        keyGenerated = true;
                        keyLocations.Add(currentCell.transform.position.x + Mathf.PerlinNoise(currentCell.coordinates.x / (float)mazeGenerationNumber, currentCell.coordinates.x / (float)mazeGenerationNumber));
                        keyLocations.Add(currentCell.transform.position.z + Mathf.PerlinNoise(currentCell.coordinates.z / (float)mazeGenerationNumber, currentCell.coordinates.z / (float)mazeGenerationNumber));
                    }
                }
            }
            // spike room
            else if (puzzleType == 2)
            {
                float spikeMultiplier = puzzleRooms[r].getCells().Count / 15f;
                // spawn spikes
                for (int c = 0; c < puzzleRooms[r].getCells().Count; c++)
                {
                    MazeCell currentCell     = puzzleRooms[r].getCells()[c];
                    float    chanceForSpikes = Mathf.PerlinNoise((currentCell.coordinates.x * currentCell.coordinates.x) / (float)mazeGenerationNumber, (currentCell.coordinates.z * currentCell.coordinates.z) / (float)mazeGenerationNumber);
                    if (chanceForSpikes < 0.3f * spikeMultiplier)
                    {
                        // generate a set of spikes
                        float      spikeX     = currentCell.transform.position.x + Mathf.PerlinNoise(currentCell.coordinates.x / (float)mazeGenerationNumber, currentCell.coordinates.x / (float)mazeGenerationNumber);
                        float      spikeZ     = currentCell.transform.position.z + Mathf.PerlinNoise(currentCell.coordinates.z / (float)mazeGenerationNumber, currentCell.coordinates.z / (float)mazeGenerationNumber);
                        float      spikeSize  = 4 * Mathf.PerlinNoise(c / (float)mazeGenerationNumber, c / (float)mazeGenerationNumber);
                        float      spikeTimer = Mathf.PerlinNoise(c / (float)mazeGenerationNumber, c / (float)mazeGenerationNumber);
                        Vector3    spawnPos   = new Vector3(spikeX, 0.0f, spikeZ);
                        Quaternion spawnRot   = new Quaternion(0f, 0f, 0f, 0f);
                        GameObject newGO      = (GameObject)PhotonNetwork.InstantiateSceneObject("Spike", spawnPos, spawnRot, 0);
                        Spike      newSpike   = newGO.GetComponent <Spike>();
                        newSpike.setSpike(spikeSize, spikeTimer);
                        spikeList.Add(newSpike);
                    }
                    // spawn a key
                    else if (keyGenerated == false)
                    {
                        keyGenerated = true;
                        keyLocations.Add(currentCell.transform.position.x + Mathf.PerlinNoise(currentCell.coordinates.x / (float)mazeGenerationNumber, currentCell.coordinates.x / (float)mazeGenerationNumber));
                        keyLocations.Add(currentCell.transform.position.z + Mathf.PerlinNoise(currentCell.coordinates.z / (float)mazeGenerationNumber, currentCell.coordinates.z / (float)mazeGenerationNumber));
                    }
                }
            }
            // ball room, roll balls onto targets
            else if (puzzleType == 3)
            {
                // pick 6 areas
                List <int> itemCells = new List <int>();
                int        counter   = 0;
                int        index     = 0;
                while (index < 7)
                {
                    int cell = 0;
                    counter++;
                    // keep giving cell new values until its a new value not already in the list
                    do
                    {
                        cell = (int)Random.Range(0f, puzzleRooms[r].getCells().Count - 1);
                    }while(itemCells.Contains(cell));
                    itemCells.Add(cell);
                    index++;
                }
                for (int i = 0; i < 7; i++)
                {
                    Debug.Log(itemCells[i]);
                }
                // first 3 cells contain balls
                for (int b = 0; b < 3; b++)
                {
                    Vector3    spawnPos = new Vector3(puzzleRooms[r].getCells()[itemCells[b]].transform.position.x, 0.5f, puzzleRooms[r].getCells()[itemCells[b]].transform.position.z);
                    Quaternion spawnRot = new Quaternion(0f, 0f, 0f, 0f);
                    GameObject newGO    = (GameObject)PhotonNetwork.InstantiateSceneObject("Ball", spawnPos, spawnRot, 0);
                    Ball       newBall  = newGO.GetComponent <Ball>();
                    newBall.setSize(0.5f);
                    ballList.Add(newBall);
                }
                // last 3 cells contain holes
                for (int h = 3; h < 6; h++)
                {
                    Vector3    spawnPos  = new Vector3(puzzleRooms[r].getCells()[itemCells[h]].transform.position.x, 0f, puzzleRooms[r].getCells()[itemCells[h]].transform.position.z);
                    Quaternion spawnRot  = new Quaternion(0f, 0f, 0f, 0f);
                    GameObject newGO     = (GameObject)PhotonNetwork.InstantiateSceneObject("Target", spawnPos, spawnRot, 0);
                    Target     newTarget = newGO.GetComponent <Target>();
                    newTarget.setSize(0.5f);
                    targetList.Add(newTarget);
                }
                MazeCell currentCell = puzzleRooms[r].getCells()[itemCells[6]];
                keyLocations.Add(currentCell.transform.position.x + Mathf.PerlinNoise(currentCell.coordinates.x / (float)mazeGenerationNumber, currentCell.coordinates.x / (float)mazeGenerationNumber));
                keyLocations.Add(currentCell.transform.position.z + Mathf.PerlinNoise(currentCell.coordinates.z / (float)mazeGenerationNumber, currentCell.coordinates.z / (float)mazeGenerationNumber));
            }
            // for the ice room we spawn "icy mist"
            else if (puzzleType == 4)
            {
                for (int c = 0; c < puzzleRooms[r].getCells().Count; c++)
                {
                    // add mist particle systems
                    MazeCell   addHere = puzzleRooms[r].getCells()[c];
                    Vector3    mistPos = new Vector3(addHere.transform.position.x, 0f, addHere.transform.position.z);
                    Quaternion mistRot = new Quaternion(0f, 0f, 0f, 0f);
                    PhotonNetwork.InstantiateSceneObject("IcyMist", mistPos, mistRot, 0);
                }
            }
            // boss room, fight a strong monster
            else if (puzzleType == 5)
            {
                // spawn boss
                MazeCell   bossCell  = puzzleRooms[r].getCells()[Random.Range(0, puzzleRooms[r].getCells().Count)];
                Vector3    bossPos   = new Vector3(bossCell.transform.position.x, 0f, bossCell.transform.position.z);
                Quaternion bossRot   = new Quaternion(0f, 0f, 0f, 0f);
                GameObject monsterGO = (GameObject)PhotonNetwork.InstantiateSceneObject("PuzzleRoomBoss", bossPos, bossRot, 0);
                monsterGO.GetComponent <MonsterAI>().enabled = true;
                MonsterAI monster = monsterGO.GetComponent <MonsterAI>();
                monster.setMonsterType("PuzzleRoomBoss");

                // key location
                MazeCell keyCell = puzzleRooms[r].getCells()[Random.Range(0, puzzleRooms[r].getCells().Count)];
                keyLocations.Add(keyCell.transform.position.x + Mathf.PerlinNoise(keyCell.coordinates.x / (float)mazeGenerationNumber, keyCell.coordinates.x / (float)mazeGenerationNumber));
                keyLocations.Add(keyCell.transform.position.z + Mathf.PerlinNoise(keyCell.coordinates.z / (float)mazeGenerationNumber, keyCell.coordinates.z / (float)mazeGenerationNumber));
            }
        }
    }