예제 #1
0
    void Start()
    {
        // Crear la seed
        int iSeed = UnityEngine.Random.Range(0, 99999);

        UnityEngine.Random.InitState(iSeed);

        // Me aseguro que la Y sea la mayor, y la X la menor
        if (mazeSizeX > mazeSizeY)
        {
            int minSize = mazeSizeY;
            mazeSizeY = mazeSizeX;
            mazeSizeX = minSize;
        }

        // Usaremos 4 maze para crear la ilusion de que se hacen alrededor de la Safe Zone
        List <Vector3> mazePos = new List <Vector3>();

        mazePos.Add(new Vector3(0, 0, 0));
        mazePos.Add(new Vector3(mazeSizeY * 12.0f, 0, 0));
        mazePos.Add(new Vector3(mazeSizeX * 12.0f, 0, mazeSizeY * 12.0f));
        mazePos.Add(new Vector3(0, 0, mazeSizeX * 12.0f));

        // Instanciar los 4 maze
        ConnectMaze();
        for (int i = 0; i < 4; i++)
        {
            int sizeX = (i % 2 == 0) ? mazeSizeX : mazeSizeY;
            int sizeY = (i % 2 == 0) ? mazeSizeY : mazeSizeX;

            // Paredes
            MazeGeneration.Maze maze = MazeGeneration.Maze.CreateInstance <MazeGeneration.Maze>();
            maze.Init(sizeX, sizeY, mazePos[i], iSeed, mazeWall);
            maze.Display();

            // Piso
            mazeFloor.transform.localScale = new Vector3(sizeY * 12.0f, 1.0f, sizeX * 12.0f);
            mazeFloor.GetComponent <Renderer>().sharedMaterial.mainTextureScale = new Vector2(mazeFloor.transform.localScale.x / 8.0f, mazeFloor.transform.localScale.z / 16.0f);
            UnityEngine.Object.Instantiate(mazeFloor, new Vector3(mazePos[i].x + sizeY * 6.0f, 0.0f, mazePos[i].z + sizeX * 6.0f), Quaternion.identity);
        }

        // Obtener el centro del maze
        int     sizeXCenter   = (mazeSizeX >= mazeSizeY) ? mazeSizeX : mazeSizeY;
        int     sizeYCenter   = (mazeSizeX < mazeSizeY) ? mazeSizeX : mazeSizeY;
        Vector3 mazeCenterPos = new Vector3(sizeXCenter * 12.0f - Math.Abs(sizeXCenter - sizeYCenter) * 6.0f, 0, sizeYCenter * 12.0f + Math.Abs(sizeXCenter - sizeYCenter) * 6.0f);

        // Instanciar la Safe Zone
        mazeCenter.transform.localScale = new Vector3(Math.Abs(sizeXCenter - sizeYCenter) * 12.0f, 1.0f, Math.Abs(sizeXCenter - sizeYCenter) * 12.0f);
        mazeCenter.GetComponent <Renderer>().sharedMaterial.mainTextureScale = new Vector2(mazeCenter.transform.localScale.x / 3.0f, mazeCenter.transform.localScale.z / 3.0f);
        UnityEngine.Object.Instantiate(mazeCenter, mazeCenterPos, Quaternion.identity);

        // Instanciar al player en Safe Zone
        GameManager.Instance.goPlayer = UnityEngine.Object.Instantiate(player, mazeCenterPos, Quaternion.identity) as GameObject;
        GameManager.Instance.SetReferences();

        // Instanciar Gates
        Vector3 gateScale = mazeGates.transform.localScale;

        UnityEngine.Object.Instantiate(mazeGates, new Vector3(162.19f, -24.0f, 203.54f), Quaternion.Euler(0, 180, 0));
        UnityEngine.Object.Instantiate(mazeGates, new Vector3(162.19f, -24.0f, 120.06f), Quaternion.Euler(0, 0, 0));
        UnityEngine.Object.Instantiate(mazeGates, new Vector3(120.16f, -24.0f, 162.33f), Quaternion.Euler(0, 90, 0));
        UnityEngine.Object.Instantiate(mazeGates, new Vector3(204.00f, -24.0f, 162.33f), Quaternion.Euler(0, 270, 0));

        /// Cambiar a evento
        Wait(8.0f, () => {
            InstanciateStuff();
        });
    }
예제 #2
0
파일: labirint.cs 프로젝트: sergeyhaki/cs
        static void Main(string[] args)
        {
            var maze = new Maze(20, 20);

            maze.Display();
        }