예제 #1
0
    void AddSnakeCube()
    {
        float   cubeOffset = config.cubeSize;
        float   scale      = config.cubeSize;
        CubePos cp         = snakeCubes [snakeCubes.Count - 1].GetCubePos();
        float   moveTime   = 0.9f * config.moveInterval;

        SnakeCube sc = Instantiate(snakeCube) as SnakeCube;

        sc.transform.localScale    = new Vector3(scale, scale, scale);
        sc.transform.parent        = GameObject.Find("BasePoint").transform;
        sc.transform.localPosition = cp.ToVec3();
        sc.SetMovePara(cubeOffset, moveTime);
        sc.SetCubePos(cp);
        // Debug.Log ("-----" + cp.x.ToString() + " " + cp.y.ToString() + " "+ cp.z.ToString() + " ");
        cubePosEmpty [cp.GetIndex()] = false;

        sc.SetNextSnakeCube(snakeCubes[snakeCubes.Count - 1]);
        //sc.PreMove ();

        snakeCubes.Add(sc);
    }
예제 #2
0
    void InitSnake()
    {
        int     dim        = config.matrixDim;
        float   cubeOffset = config.cubeSize;
        float   scale      = config.cubeSize;
        CubePos cp         = new CubePos(0, 4, 0);
        float   moveTime   = 0.9f * config.moveInterval;

        if (dim % 2 == 0)
        {
            cp.x = dim / 2;
        }
        else
        {
            cp.x = (dim + 1) / 2;
        }

        float x = cp.x * cubeOffset;
        float y = cp.y * cubeOffset;
        float z = cp.z * cubeOffset;

        CubePos deltaCubePos = new CubePos(0, 1, 0);

        snakeCubeHead = Instantiate(snakeCubeHead) as SnakeCubeHead;
        snakeCubeHead.transform.localScale    = new Vector3(scale, scale, scale);
        snakeCubeHead.transform.parent        = GameObject.Find("BasePoint").transform;
        snakeCubeHead.transform.localPosition = new Vector3(x, y, z);
        snakeCubeHead.Init(cp, deltaCubePos, cubeOffset, moveTime, config.matrixDim + 1, FaceIndex.z_neg);
        cubePosEmpty [cp.GetIndex()] = false;

        InputController ic = GameObject.Find("InputController").GetComponent <InputController>();

        ic.snakeCubeHead = snakeCubeHead;


        for (int i = 3; i > 0; i--)
        {
            y = i * cubeOffset;
            SnakeCube sc = Instantiate(snakeCube) as SnakeCube;
            sc.transform.localScale    = new Vector3(scale, scale, scale);
            sc.transform.parent        = GameObject.Find("BasePoint").transform;
            sc.transform.localPosition = new Vector3(x, y, z);
            sc.SetMovePara(cubeOffset, moveTime);
            CubePos thisCubePos = new CubePos(cp.x, cp.y - 4 + i, cp.z);
            sc.SetCubePos(thisCubePos);
            sc.SetReadyToMove();
            cubePosEmpty [thisCubePos.GetIndex()] = false;


            if (snakeCubes.Count == 0)
            {
                sc.SetNextSnakeCube(snakeCubeHead);
            }
            else
            {
                sc.SetNextSnakeCube(snakeCubes[snakeCubes.Count - 1]);
            }

            snakeCubes.Add(sc);
        }
    }