Example #1
0
    void Awake()
    {
        pipePrefabDict = new Dictionary <PipeType, GameObject>();
        //assigning the pipe prefabs to their specific types
        for (int i = 0; i < pipePrefabs.Length; i++)
        {
            if (!pipePrefabDict.ContainsKey(pipePrefabs[i].type))
            {
                pipePrefabDict.Add(pipePrefabs[i].type, pipePrefabs[i].prefab);
            }
        }
        //creating the background squares
        for (int x = 0; x < xDim; x++)
        {
            for (int y = 0; y < yDim; y++)
            {
                GameObject background = (GameObject)Instantiate(backgroundPrefab, GetWorldPosition(x, y), Quaternion.identity);
                background.transform.parent = transform;
            }
        }



        // an array to store the pipes
        pipes = new GamePipe[xDim, yDim];

        //creating the starting and ending pipes
        WinDetect win = this.GetComponent <WinDetect>();

        SpawnNewPipe(win.xstart, win.ystart, PipeType.STARTSTOP);
        StartEndRot(GameObject.Find("(" + win.xstart + ", " + win.ystart + ")"), 1);
        SpawnNewPipe(win.xend, win.yend, PipeType.STARTSTOP);
        StartEndRot(GameObject.Find("(" + win.xend + ", " + win.yend + ")"), -1);

        //creates the pipes from the level loader
        for (int j = 0; j < array.Length; j++)
        {
            SpawnNewPipe(array[j].xcoord, array[j].ycoord, array[j].t);
            GameObject.Find("(" + array[j].xcoord + ", " + array[j].ycoord + ")").GetComponent <RotationPipe>().SetRotation(array[j].orientation);
        }

        //scaling the grid so it looks good at any size
        float xprop = xDim / 15f;
        float yprop = yDim / 7f;

        if (xprop >= yprop)
        {
            this.transform.localScale = new Vector3(1 / xprop, 1 / xprop, 1);
        }
        else
        {
            this.transform.localScale = new Vector3(1 / yprop, 1 / yprop, 1);
        }
    }
Example #2
0
    //this function determines the NESW rotation of the starting/ending pipe
    public void StartEndRot(GameObject Pipe, int define)
    {
        WinDetect win = this.GetComponent <WinDetect>();

        if (define == 1)
        {
            if (win.startXDir * define == 1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.EAST);
            }
            if (win.startXDir * define == -1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.WEST);
            }
            if (win.startYDir * define == 1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.NORTH);
            }
            if (win.startYDir * define == -1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.SOUTH);
            }
        }
        else
        {
            if ((win.endXDir * define) == 1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.EAST);
            }
            if ((win.endXDir * define) == -1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.WEST);
            }
            if ((win.endYDir * define) == 1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.NORTH);
            }
            if ((win.endYDir * define) == -1)
            {
                Pipe.GetComponent <RotationPipe>().SetRotation(RotationPipe.Rotations.SOUTH);
            }
        }
    }