Ejemplo n.º 1
0
        public void generatePuzzle()
        {
            generatetime += Time.deltaTime;
            if (generatetime > timePerGenerate)
            {
                generatetime = 0;

                puzzlecount++;
                System.Random rnd = new System.Random();
                //int puzzleindex = rnd.Next(1, numberOfPuzzle + 1);
                int        puzzleindex = puzzlecount % numberOfPuzzle + 1;
                int        x           = rnd.Next(0, groundsize);
                int        z           = rnd.Next(0, groundsize - 3);
                GameObject newpuzzle   = (GameObject)GameObject.Instantiate(Resources.Load("prefabs/puzzle" + puzzleindex.ToString()));
                newpuzzle.transform.position = new Vector3(x, groundsize - 2, z);
                puzzle newp = new puzzle(newpuzzle, puzzlecount);
                newp.type = puzzleindex;
                for (int i = 0; i < newpuzzle.transform.childCount; i++)
                {
                    GameObject cube = newpuzzle.transform.GetChild(i).gameObject;
                    if (getGrid(cube.transform.position) != 0)
                    {
                        gameover();
                    }
                    Cube newcub = new Cube(cube, puzzlecount);
                    newp.addCube(newcub);
                }
                puzzles.Add(newp);
                curr           = newp;
                newpuzzle.name = puzzlecount.ToString();
            }
        }
Ejemplo n.º 2
0
 public bool addCube(Vector3 coord)
 {
     coord = WorldToCube(coord);
     if (valid(coord) && getGrid(coord) == 0 && money >= 20)
     {
         GameObject cub = (GameObject)GameObject.Instantiate(Resources.Load("prefabs/Cubeadd"));
         cub.transform.position = coord;
         puzzlecount++;
         GameObject puzobj = new GameObject(puzzlecount.ToString());
         cub.transform.parent = puzobj.transform;
         puzzle newp = new puzzle(puzobj, puzzlecount);
         newp.type = 6;
         Cube c = new Cube(cub, puzzlecount);
         newp.addCube(c);
         puzzles.Add(newp);
         money -= 20;
         return(true);
     }
     return(false);
 }
Ejemplo n.º 3
0
        public void Update()
        {
            switchtime += Time.deltaTime;
            displayarmwidget();
            updatebomb();
            updatecube();
            objtime   += Time.deltaTime;
            leaporigin = leapspace.transform.position;
            Matrix4x4 wtc         = camera.worldToCameraMatrix;
            Matrix4x4 ctw         = camera.cameraToWorldMatrix;
            Vector3   leftoffset  = vec4To3(ctw * vec3To4(Vector3.left * 0.1f, 0));
            Vector3   rightoffset = vec4To3(ctw * vec3To4(Vector3.right * 0.1f, 0));
            Vector3   upoffset    = vec4To3(ctw * vec3To4(Vector3.up * 0.1f, 0));
            Vector3   downoffset  = vec4To3(ctw * vec3To4(Vector3.down * 0.1f, 0));

            if (objtime > 1)
            {
                if (righthand != null)
                {
                    Vector3 normal = Vector3.Normalize(leapVectorToWorld(righthand.PalmNormal));
                    Vector3 dir    = leapToWorld(righthand.PalmPosition) - leaporigin;
                    if (translate)
                    {         //translate
                        if (decideDirection(normal) != Vector3.zero)
                        {     //valid pos
                            if (detectColli(leftoffset, rightoffset, upoffset, downoffset, dir))
                            { // has target
                                leavetime = 0;
                                GameObject target = info.collider.gameObject;
                                if (prepos == Vector3.zero)
                                {//first hit
                                    prepos = leapToWorld(righthand.PalmPosition);
                                }
                                else
                                {
                                    if ((prepos - leapToWorld(righthand.PalmPosition)).magnitude > 0.06f)
                                    {//move obj
                                        int    id = Int32.Parse(target.transform.parent.gameObject.name);
                                        puzzle p  = gameController.GetPuzzle(id);
                                        if (p.startMove(decideDirection(normal)))
                                        {
                                            p.highlight();
                                            objtime = 0;
                                        }
                                        prepos = Vector3.zero;
                                    }
                                }
                            }
                            else
                            { //reset pre
                                leavetime += Time.deltaTime;
                                if (leavetime > 0.5f)
                                {
                                    prepos = Vector3.zero;
                                }
                            }
                        }
                    }
                    else
                    {     //rotation
                        if (detectColli(leftoffset, rightoffset, upoffset, downoffset, dir))
                        { // has target
                            GameObject target   = info.collider.gameObject;
                            GameObject parent   = target.transform.parent.gameObject;
                            int        id       = Int32.Parse(target.transform.parent.gameObject.name);
                            puzzle     p        = gameController.GetPuzzle(id);
                            Vector3    hitpoint = info.point;
                            if (righthand.GrabStrength > 0.8f)
                            {
                                p.highlight();
                                Vector3 ax = Vector3.Cross(leapVectorToWorld(righthand.Direction), leapVectorToWorld(righthand.PalmNormal));
                                if (p.rotate(findclosestunit(ax)))
                                {
                                    objtime = 0;
                                }
                            }
                        }
                    }
                }
            }
            movetime += Time.deltaTime;
            if (movetime > 1)
            {
                if (lefthand != null)
                {
                    if (bomb == null && cub == null)
                    {
                        if (isFist(lefthand))
                        {
                            if (leftprepos == Vector3.zero)
                            {
                                leftprepos = leapToWorld(lefthand.PalmPosition);
                            }
                            else
                            {
                                if ((leftprepos - leapToWorld(lefthand.PalmPosition)).magnitude > 0.12f)
                                {
                                    Vector3 dir = findclosestunit(leftprepos - leapToWorld(lefthand.PalmPosition));
                                    gamer.moveplayer(dir);
                                    leftprepos = Vector3.zero;
                                    movetime   = 0;
                                }
                            }
                        }
                        else
                        {
                            leftprepos = Vector3.zero;
                        }
                    }
                    else if (bomb != null)
                    {
                        if (!isFist(lefthand) && !release)
                        {
                            releasetime += Time.deltaTime;
                            if (prebombpos == Vector3.zero)
                            {
                                prebombpos = bomb.transform.position;
                            }
                            if (releasetime > 0.3f)
                            {
                                release = true;
                                bombdir = 0.2f * Vector3.Normalize(bomb.transform.position - prebombpos);
                            }
                        }
                        else
                        {
                            releasetime = 0;
                            prebombpos  = Vector3.zero;
                        }
                    }
                    else
                    {
                        if (!isFist(lefthand))
                        {
                            cubereleasetime += Time.deltaTime;
                            if (cubereleasetime > 1)
                            {
                                if (gameController.ctr.addCube(leaporigin + leapspace.transform.forward))
                                {
                                    cubereleasetime = 0;
                                    GameObject.Destroy(cub);
                                    cub = null;
                                }
                            }
                        }
                    }
                }
            }
        }