예제 #1
0
 /// <summary>
 /// Switch on or off all Orb instances
 /// </summary>
 /// <param name="on">Whether to turn on or off Orb instances</param>
 private void switchOrb(bool on)
 {
     // Loop through the Orbs array
     for (int i = 0; i < 5; i++)
     {
         for (int j = 0; j < 6; j++)
         {
             Orb orb = orbs[i, j];
             orb.gameObject.SetActive(on);
             if (on)
             {
                 // Make Orb instance visisble again
                 SpriteRenderer orbSprite = orb.GetComponent <SpriteRenderer>();
                 Color          orbColor  = orbSprite.color;
                 orbColor.a      = 1;
                 orbSprite.color = orbColor;
             }
             else
             {
                 // Making Orb invisible
                 SpriteRenderer orbSprite = orb.GetComponent <SpriteRenderer>();
                 orbSprite.color -= new Color(0, 0, 0, 1);
             }
         }
     }
 }
예제 #2
0
    public void ThrowOrb()
    {
        Vector3 pos = Camera.main.transform.position + (Camera.main.transform.forward * .35f);
        Orb     b   = grabbedOrb.GetComponent <Orb>();

        b.grabbed = false;
        grabbedOrb.transform.position = pos;
        b.GetComponent <Rigidbody>().WakeUp();
        //b.GetComponent<Rigidbody>().useGravity = true;
        b.GetComponent <Rigidbody>().isKinematic = false;
        if (b.type == Orb.Type.Speed)
        {
            b.GetComponent <Rigidbody>().AddForce(transform.forward * 1500);
        }
        else
        {
            b.GetComponent <Rigidbody>().AddForce(transform.forward * 500);
        }
        foreach (Collider c in grabbedOrb.GetComponents <Collider>())
        {
            c.enabled = true;
        }
        grabbedOrb = null;
        absorbed   = false;
    }
예제 #3
0
    public void GrabOrb(GameObject go)
    {
        Color color = new Color(1, 1, 1, 0);

        grabbedOrb         = go.GetComponent <Orb> ();
        grabbedOrb.grabbed = true;
        foreach (Collider c in go.GetComponents <Collider>())
        {
            c.enabled = false;
        }
        grabbedOrb.GetComponent <Rigidbody>().Sleep();

        absorbedMat       = grabbedOrb.GetComponent <Renderer> ().material;
        absorbedMat.color = color;
    }
예제 #4
0
    private void createOrb(Vector3 orbPosition, int direction)
    {
        Orb orbInstance = Instantiate(dungeonOrbPrefab) as Orb;

        orbInstance.setStartingPosition(orbPosition, direction);
        orbInstance.setMaxMovementValues(minX, maxX, minY, maxY);
        puzzleSpheres.Add(orbInstance);
        orbInstance.GetComponent <lightUp> ().setIndex(puzzleSpheres.Count - 1);
    }
예제 #5
0
    public void DropOrb()
    {
        Vector3 pos = Camera.main.transform.position + (Camera.main.transform.forward * .35f);
        Orb     b   = grabbedOrb.GetComponent <Orb>();

        b.grabbed = false;
        grabbedOrb.transform.position = pos;
        b.GetComponent <Rigidbody>().WakeUp();
        //b.GetComponent<Rigidbody>().useGravity = true;
        b.GetComponent <Rigidbody>().isKinematic = false;
        b.GetComponent <Rigidbody>().velocity    = cc.velocity;
        foreach (Collider c in grabbedOrb.GetComponents <Collider>())
        {
            c.enabled = true;
        }
        grabbedOrb = null;
        absorbed   = false;
    }
예제 #6
0
    public static void PlaceOrbAt(Vector3 position, int playerNumber)
    {
        Vector3 newPos = new Vector3(position.x, Mathf.Max(position.y, 0f), position.z);
        Orb     orb    = Instantiate(orbPrefab, newPos, Quaternion.identity * Quaternion.AngleAxis(90, Vector3.right)) as Orb;

        orb.playerNumber = playerNumber;
        MeshRenderer orbRend = orb.GetComponent <MeshRenderer>();

        orbRend.material.SetColor("_TintColor", MultiplayerManagement.GetPlayer(playerNumber).playerColor);
    }
예제 #7
0
    void OnTriggerEnter(Collider other)
    {
        Orb b = other.gameObject.GetComponent <Orb> ();

        if (b == null)
        {
            return;
        }
        b.GetComponent <Rigidbody> ().velocity = Vector3.zero;
        b.gameObject.transform.position        = transform.position;
    }
예제 #8
0
        /// <summary>
        /// Spawn a tracking Orb that track the current mouse position
        /// </summary>
        /// <param name="original">Original Orb instance that the tracking Orb should be based on</param>
        private static void spawnTrackingOrb(Orb original)
        {
            GameObject     trackingObj = new GameObject();
            SpriteRenderer sr          = trackingObj.AddComponent <SpriteRenderer>();

            sr.sprite = original.GetComponent <SpriteRenderer>().sprite;
            Vector3 originalPos = original.transform.position;

            originalPos.x += 0.1f;
            originalPos.y += 0.1f;
            originalPos.z  = trackingZ;
            trackingObj.transform.position   = originalPos;
            trackingObj.transform.localScale = new Vector3(1, 1, 1);
            currentTracker = trackingObj;
        }
 private void endPopingOrbs()
 {
     Debug.unityLogger.Log("End Orb Pop", "Starting");
     foreach (LinkedList <GameObject> Col in Cols)
     {
         foreach (GameObject orb in Col.ToList())
         {
             Orb temporb = orb.GetComponent <Orb>();
             Debug.unityLogger.Log("End Orb Pop", "Orb " + temporb.name + " is being checked");
             if (temporb.curState == Orb.OrbState.Poping)
             {
                 Vector3 temp = temporb.GetComponent <Orb>().GetRelPos();
                 Cols[(int)temp.x].Remove(temporb.gameObject);
                 Destroy(temporb.gameObject);
                 Debug.unityLogger.Log("End Orb Pop", "Orb " + temporb.name + " has been Popped");
             }
         }
     }
     Debug.unityLogger.Log("End Orb Pop", "Ending");
 }
예제 #10
0
    // Update is called once per frame
    void Update()
    {
        int     mod       = -1;
        float   h         = Input.GetAxis("Horizontal");
        float   v         = Input.GetAxis("Vertical");
        float   rotationX = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX;
        Vector3 vel       = (transform.forward * v + transform.right * h) * speed;

        rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
        rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

        transform.localEulerAngles = new Vector3(-rotationY, rotationX, 0);

        if (cc.isGrounded)
        {
            vSpeed = 0;
            // We are grounded, so recalculate
            // move direction directly from axes

            if (Input.GetButton("Jump"))
            {
                vSpeed = jumpSpeed;
            }
        }

        if (absorbed)
        {
            switch (grabbedOrb.type)
            {
            case Orb.Type.Speed:
                vel *= 2f;
                break;

            case Orb.Type.Flip:
                mod = 1;
                break;
            }
        }


        vSpeed = vSpeed + (gravity * Time.deltaTime) * mod;
        vel.y  = vSpeed;


        cc.Move(vel * Time.deltaTime);

        if (grabbedOrb == null)
        {
            Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            if (Physics.Raycast(ray, out hit, 1.5f))
            {
                GameObject go = hit.collider.gameObject;
                if (go.GetComponent <Orb> () != null)
                {
                    go.GetComponent <Orb> ().Hover();

                    if (Input.GetMouseButtonDown(0))
                    {
                        grabbedOrb         = go.GetComponent <Orb> ();
                        grabbedOrb.grabbed = true;
                        foreach (Collider c in go.GetComponents <Collider>())
                        {
                            c.enabled = false;
                        }
                        grabbedOrb.GetComponent <Rigidbody>().useGravity = false;
                        grabbedOrb.GetComponent <Rigidbody>().Sleep();
                    }
                }
            }
        }
        else
        {
            grabbedOrb.transform.position = Camera.main.transform.position + (Camera.main.transform.forward * .6f);
            grabbedOrb.transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y - 90, transform.rotation.eulerAngles.z);

            // Dropping orb
            if (Input.GetMouseButtonDown(0))
            {
                Vector3 pos = Camera.main.transform.position + (Camera.main.transform.forward * .35f);
                Orb     b   = grabbedOrb.GetComponent <Orb>();
                b.grabbed = false;
                grabbedOrb.transform.position = pos;
                b.GetComponent <Rigidbody>().WakeUp();
                b.GetComponent <Rigidbody>().useGravity  = true;
                b.GetComponent <Rigidbody>().isKinematic = false;
                b.GetComponent <Rigidbody>().velocity    = cc.velocity;
                foreach (Collider c in grabbedOrb.GetComponents <Collider>())
                {
                    c.enabled = true;
                }
                grabbedOrb = null;
                absorbed   = false;
            }
            // Throwing orb
            else if (Input.GetButtonDown("Throw"))
            {
                Vector3 pos = Camera.main.transform.position + (Camera.main.transform.forward * .35f);
                Orb     b   = grabbedOrb.GetComponent <Orb>();
                grabbedOrb.transform.position = pos;
                b.GetComponent <Rigidbody>().WakeUp();
                b.GetComponent <Rigidbody>().useGravity  = true;
                b.GetComponent <Rigidbody>().isKinematic = false;
                foreach (Collider c in grabbedOrb.GetComponents <Collider>())
                {
                    c.enabled = true;
                }
                b.GetComponent <Rigidbody> ().AddForce(transform.forward * 500);
                grabbedOrb = null;
                absorbed   = false;
            }
            // Absorb orb
            else if (Input.GetButtonDown("Absorb"))
            {
                absorbed = !absorbed;
            }
        }
    }
예제 #11
0
        /// <summary>
        /// Initiate a rearrangement of Orb where some or all Orb are eliminated
        /// </summary>
        /// <param name="unarranged">Raw Orb 2D array with some Orb eliminated</param>
        public void rearrangeOrb(Orb[,] unarranged)
        {
            // Calculate the distance in y-axis in world space between each Orb
            float distanceBetweenOrb = unarranged[0, 0].transform.position.y - unarranged[1, 0].transform.position.y;

            // Loop through all Orbs, column by column
            for (int i = 0; i < unarranged.GetLength(1); i++)
            {
                // Loop through each column from bottom to top (i.e. from j = 4 to j = 0)
                for (int j = unarranged.GetLength(0) - 1; j >= 0; j--)
                {
                    Orb orb = unarranged[j, i];
                    if (orb.getType() == -1)
                    {
                        // Orb are eliminated
                        // Loop through all Orbs above this orb in the same column and look for any orb above it to fall down to this position
                        // Suppose j = 4, then we have to check from k = 3 to k = 0
                        for (int k = j - 1; k >= 0; k--)
                        {
                            // Check if that orb has type not equals to -1 (i.e. not eliminated)
                            if (unarranged[k, i].getType() != -1)
                            {
                                // If not eliminated, that orb should fall to the current location
                                // Set tht current orb to have that type
                                orb.setType(unarranged[k, i].getType());
                                // Eliminate the Orb that has now fall to some position below
                                unarranged[k, i].eliminate();
                                // Spawn DummyOrb that do the drop animation, and store it in the list
                                DummyOrb d = DummyOrb.Factory(unarranged[k, i].transform.position, unarranged[k, i].GetComponent <SpriteRenderer>().sprite, unarranged[k, i].transform.localScale);
                                d.StartTranslate(orb.transform.position);
                                dummyOrbs.Add(d);
                                // Listen to AnimationDone
                                d.AnimationDone += animationCallback;
                                // Increment counter
                                pendingAnimation++;
                                // We are done with this orb
                                break;
                            }
                            // This Orb is also eliminated, look for 1 higher Orb then
                        }
                        // Triggered if there are non-eliminated Orb above this current Orb
                        if (orb.getType() == -1)
                        {
                            // No orbs are above this orb to fall down to this position
                            // Loop through all Orbs above this Orb
                            for (int k = j; k >= 0; k--)
                            {
                                // Set the current Orb and every Orb above this Orb to a random type
                                int newType = Orb.GetRandomNumber(1, 5);
                                unarranged[k, i].setType(newType);
                                // Spawn a DummyOrb that translate to the position for that animation
                                // Calculate the Orb position, it should be just above the Orb itself seperated by the distance between each normal Orb
                                Vector3 dummyOrbPos = unarranged[k, i].transform.position;
                                dummyOrbPos.y += distanceBetweenOrb;
                                // Spawn DummyOrb that do the drop animation, and store it in the list
                                DummyOrb d = DummyOrb.Factory(dummyOrbPos, unarranged[k, i].GetComponent <SpriteRenderer>().sprite, unarranged[k, i].transform.localScale);
                                d.StartTranslate(unarranged[k, i].transform.position);
                                dummyOrbs.Add(d);
                                // Listen to AnimationDone
                                d.AnimationDone += animationCallback;
                                // Increment counter
                                pendingAnimation++;
                            }
                            // We are done with the entire column at this point, no point to run this loop any further since all Orb within this column is set
                            break;
                        }
                    }
                    else
                    {
                        // Orbs are not eliminated, but we are still spawning a non-moving dummyOrb for that
                        // This only applies to Orb at the bottom that are not eliminated
                        staticDummyOrbs.Add(DummyOrb.Factory(orb.transform.position, orb.GetComponent <SpriteRenderer>().sprite, orb.transform.localScale));
                    }
                }
            }
        }
예제 #12
0
    // Update is called once per frame
    void Update()
    {
        int     mod = 1, rotFlip = 0;
        float   h = Input.GetAxis("Horizontal");
        float   v = Input.GetAxis("Vertical");
        float   rotationX;
        Vector3 vel = (transform.forward * v + transform.right * h) * speed;



        if (absorbed)
        {
            switch (grabbedOrb.type)
            {
            case Orb.Type.Speed:
                vel *= 2f;
                break;

            case Orb.Type.Flip:
                mod     = -1;
                rotFlip = 1;
                break;
            }
        }

        rotationX  = transform.localEulerAngles.y + Input.GetAxis("Mouse X") * sensitivityX * mod;
        rotationY += Input.GetAxis("Mouse Y") * sensitivityY * mod;
        rotationY  = Mathf.Clamp(rotationY, minimumY, maximumY);

        Ray ray;

        if ((cc.collisionFlags & CollisionFlags.Above) != 0 || cc.isGrounded)
        {
            vSpeed = 0;
            // We are grounded, so recalculate
            // move direction directly from axes

            if (Input.GetButton("Jump"))
            {
                vSpeed = jumpSpeed * mod;
            }
        }

        transform.localEulerAngles = new Vector3(-rotationY, rotationX, rotFlip * 180);
        vSpeed -= (gravity * Time.deltaTime) * mod;
        vel.y   = vSpeed;


        cc.Move(vel * Time.deltaTime);


        ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
        if (Physics.Raycast(ray, out hit, 1.5f))
        {
            GameObject go = hit.collider.gameObject;
            if (go.name == "Reset" && Input.GetMouseButtonDown(0))
            {
                go.GetComponent <ResetSwitch> ().orb.GetComponent <Rigidbody>().transform.position = go.transform.position + new Vector3(0, .25f, 0);
            }
        }

        if (grabbedOrb == null)
        {
            ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
            if (Physics.Raycast(ray, out hit, 1.5f))
            {
                GameObject go = hit.collider.gameObject;
                if (go.GetComponent <Orb> () != null)
                {
                    go.GetComponent <Orb> ().Hover();

                    if (Input.GetMouseButtonDown(0))
                    {
                        GrabOrb(go);
                    }
                }
            }
        }
        else
        {
            grabbedOrb.transform.position = Camera.main.transform.position + (Camera.main.transform.forward * .6f) + (-Camera.main.transform.right * .2f) + (-Camera.main.transform.up * .2f);
            grabbedOrb.transform.rotation = Quaternion.Euler(0, transform.rotation.eulerAngles.y - 90, transform.rotation.eulerAngles.z);

            // Dropping orb
            if (Input.GetMouseButtonDown(0))
            {
                DropOrb();
            }
            // Throwing orb
            else if (Input.GetButtonDown("Throw"))
            {
                ThrowOrb();
            }
            // Absorb orb
            if (Input.GetButtonDown("Absorb") && canAbsorb)
            {
                canAbsorb = false;
                // Instantanious vs persistent
                if (grabbedOrb.type == Orb.Type.Swap && absorbed == false)
                {
                    swapTS   = 1;
                    absorbed = true;
                }
                else
                {
                    grabbedOrb.GetComponent <Renderer> ().material = absorbedMat;
                    absorbed = !absorbed;
                }
            }
        }

        if (Input.GetButtonUp("Absorb"))
        {
            canAbsorb = true;
        }


        if (Input.GetButtonDown("Reset"))
        {
            Application.LoadLevel(Application.loadedLevel);
        }
    }