Exemplo n.º 1
0
    // Use this for initialization
    void Start()
    {
        drawMazeScript = this.GetComponent <DrawMaze>();
        boardDimension = drawMazeScript.dimSquare;

        Instantiate(player, new Vector2(1, 1), Quaternion.identity);

        // Get collectible positions and place them
        Vector2 pacificerPos = getRandomPos(6);
        Vector2 bearPos      = getRandomPos(14);
        Vector2 keysPos      = getRandomPos(22);
        Vector2 ringPos      = getRandomPos(28);
        Vector2 coffinPos    = getRandomPos(32);

        Instantiate(collectibles [0], pacificerPos, Quaternion.identity);
        Instantiate(collectibles [1], bearPos, Quaternion.identity);
        Instantiate(collectibles [2], keysPos, Quaternion.identity);
        Instantiate(collectibles [3], ringPos, Quaternion.identity);
        Instantiate(collectibles [4], coffinPos, Quaternion.identity);

        // Instantiate chests
        for (int i = 0; i < drawMazeScript.endOfHallCoords.Count; i++)
        {
            int rand = UnityEngine.Random.Range(0, 3);

            if (rand == 0)
            {
                Instantiate(chest, drawMazeScript.endOfHallCoords [i], Quaternion.identity);
            }
        }
    }
Exemplo n.º 2
0
    // Called by the button "Generate"
    // It calls the script to generate a maze in memory
    // It calls the script to draw the maze calculated
    public void CreateMaze()
    {
        GenerateMaze generatedMaze = GameObject.Find("/Scripts").GetComponent <GenerateMaze>();
        DrawMaze     drawnMaze     = GameObject.Find("/Scripts").GetComponent <DrawMaze>();

        generatedMaze.ComputeMaze();
        drawnMaze.generatedMaze = generatedMaze;
        drawnMaze.Draw();
    }
    // Use this for initialization
    void Start()
    {
        //find the maze generation script and get the board size
        maze           = this.GetComponent <DrawMaze>();
        boardDimension = maze.dimSquare;


        //how many monsters and roughly where
        int monstersX = Mathf.FloorToInt(numMonsters / 3);      //how many monsters accross
        int monstersY = Mathf.FloorToInt(numMonsters / 4);      //how many monsters go up

        int[] xMax = new int[monstersX];
        int[] xMin = new int[monstersX];
        int[] yMax = new int[monstersY];
        int[] yMin = new int[monstersY];

        //Min and Max x value for each monster
        for (int i = 0; i < monstersX; i++)
        {
            xMax [i] = boardDimension / monstersX * (i + 1);
            xMin [i] = (boardDimension / monstersX * i);
        }

        //Min and Max y value for each monster
        for (int i = 0; i < monstersY; i++)
        {
            yMax [i] = boardDimension / monstersY * (i + 1);
            yMin [i] = (boardDimension / monstersY * i);
        }

        // Instantiate monsters
        for (int i = 0; i < monstersX; i++)
        {
            for (int j = 0; j < monstersY; j++)
            {
                Debug.Log("board dimension: " + boardDimension);
                Debug.Log("i = " + i + ", j = " + j);
                Debug.Log("xMin = " + xMin[i] + ", xMax = " + xMax[i]);
                Debug.Log("yMin = " + yMin[j] + ", yMax = " + yMax[j]);

                //find the random point within the min and max for each dimension that we found earlier
                //then put it in a vector3 which will make the model apear above the floor.
                Vector2 monsterPos = new Vector2(genMonsterRand(xMin[i], xMax[i]), genMonsterRand(yMin[j], yMax[j]));
                Vector3 instPos    = new Vector3(monsterPos.x, monsterPos.y, -.15f);

                //find which monster we should use
                int whichMonster = Random.Range(0, monsters.Length);
                //Debug.Log (monsterPos);

                //instantiate the monster into the world.
                Instantiate(monsters [whichMonster], instPos, Quaternion.Euler(0, 180, 0));
            }
        }
    }    //Start