Beispiel #1
0
    IEnumerator GameUpdateR()
    {
        for (;;)
        {
            if (pause)
            {
                break;
            }

            if (playerRdone)
            {
                break;
            }

            Kinect.Body[] data = _BodyManager.GetData();
            if (data == null)
            {
                yield return(null);

                continue;
            }

            List <Kinect.Body> bodies = new List <Kinect.Body>();
            foreach (Kinect.Body body in data)
            {
                if (body != null && body.IsTracked)
                {
                    bodies.Add(body);
                }
            }

            if (bodies.Count != 2)
            {
                //Debug.LogError("Body count not 1 or 2! Got " + bodies.Count.ToString());
                //Debug.LogError("Body count not good, Got " + bodies.Count.ToString());

                StartCoroutine(WaitForBodies());
                break;

                //if (bodies.Count == 0)
                //{
                //    yield return null;
                //    continue;
                //}
            }

            //PlayerR

            //TODO:
            //1)Same to left player

            if (charR.transform.position.z > levelR[nextWallR].transform.position.z - wallAnimDistance)
            {
                levelR[nextWallR].GetComponent <Animator>().SetBool("isPlay", true);
            }

            if (charR.transform.position.z > levelR[nextWallR + 1].transform.position.z - wallAnimDistance)
            {
                levelR[nextWallR + 1].GetComponent <Animator>().SetBool("isPlay", true);
            }

            if (charR.transform.position.z > endPrefabZ)
            {
                // We win! Script motion, land in truck...
                playerRdone = true;

                Vector3 angleDir = Quaternion.Euler(0.0f, -17.7f, 0.0f) * Vector3.forward;

                while (charR.transform.position.z < endPrefabZ + 57.0f)
                {
                    camR.transform.Translate(3 * camMoveTickR * beat * Time.deltaTime * angleDir, Space.World);
                    charR.transform.Translate(3 * camMoveTickR * beat * Time.deltaTime * angleDir, Space.World);
                    yield return(null);
                }

                while (charR.transform.position.z < endPrefabZ + 117.0f)
                {
                    camR.transform.Translate(3 * camMoveTickR * beat * Time.deltaTime * Vector3.forward, Space.World);
                    charR.transform.Translate(3 * camMoveTickR * beat * Time.deltaTime * Vector3.forward, Space.World);
                    yield return(null);
                }

                charR.transform.position = new Vector3(charR.transform.position.x, charR.transform.position.y, endPrefabZ + 117.0f);

                yield return(null);

                GameObject goR = avatarR.gameObject;
                Destroy(avatarR);

                GameObject dancer = Instantiate(dancerPrefab);
                dancer.transform.localScale = goR.transform.localScale;
                dancer.transform.rotation   = goR.transform.rotation;
                dancer.transform.position   = goR.transform.position;

                Destroy(goR);
                goR = dancer;

                // jump in box
                float jumpVel = 3.5f;

                float startSizeFactor = 4.0f;
                float endSizeFactor   = 3.5f;
                float sizeVel         = 0.0f;

                float startRot = 0.0f;
                float endRot   = 180.0f;
                float rotVel   = 0.0f;

                float rot = startRot;
                while (rot < 175f)
                {
                    jumpVel -= 0.1f;
                    goR.transform.Translate(new Vector3(-1.0f * Time.deltaTime, Time.deltaTime * jumpVel, Mathf.Min(endPrefabZ + 122.0f, 0.87f * camMoveTickR * beat * Time.deltaTime)), Space.World);

                    if (goR.transform.position.z > endPrefabZ + 122.0f)
                    {
                        Vector3 pos = goR.transform.position;
                        pos.z = endPrefabZ + 122.0f;
                        goR.transform.position = pos;
                    }

                    if (goR.transform.position.y < 1.0f && rot > 80.0f)
                    {
                        Vector3 pos = goR.transform.position;
                        pos.y = 1.0f;
                        goR.transform.position = pos;
                    }

                    float scale = Mathf.SmoothDamp(goR.transform.localScale.x, endSizeFactor, ref sizeVel, 0.5f);
                    goR.transform.localScale = scale * Vector3.one;

                    rot = Mathf.SmoothDamp(rot, endRot, ref rotVel, 0.8f);

                    goR.transform.eulerAngles = new Vector3(0.0f, rot, 0.0f);

                    yield return(null);
                }

                /////////////////////

                while (!playerLdone)
                {
                    yield return(null);
                }

                yield return(new WaitForSeconds(0.5f));

                // end the game
                truck.GetComponentInChildren <Animator>().SetBool("isLeaving", true);

                StartCoroutine(BgmFade());

                yield return(new WaitForSeconds(1.0f));

                //yield return new WaitForSeconds(0.1f);

                truckSource.Play();
                yield return(new WaitForSeconds(1.2f));

                goL.SetActive(false);
                goR.SetActive(false);

                yield return(new WaitForSeconds(1.0f));

                doorSource.Play();

                yield return(new WaitForSeconds(0.6f));

                envGO.GetComponent <Animator>().SetBool("isDoor", true);

                yield return(new WaitForSeconds(2.5f));

                Vector3 cVel    = Vector3.zero;
                Vector3 endCamL = new Vector3(camL.transform.position.x, camL.transform.position.y + 3.0f, camL.transform.position.z + 21.0f);
                Vector3 endCamR = new Vector3(camR.transform.position.x, camR.transform.position.y + 3.0f, camR.transform.position.z + 21.0f);
                for (; ;)
                {
                    camL.transform.position = Vector3.SmoothDamp(camL.transform.position, endCamL, ref cVel, 1.2f);
                    camR.transform.position = Vector3.SmoothDamp(camR.transform.position, endCamR, ref cVel, 1.2f);
                    yield return(null);
                }

                break;
            }

            //if (bodies.Count == 2 && charR.transform.position.z > level[nextWallR].transform.position.z - collisionCheckDistance)
            if (charR.transform.position.z > levelR[nextWallR].transform.position.z - collisionCheckDistance)
            {
                Vector3 failVecR      = Vector3.zero;
                uint    newFailStateR = 0;
                if (levelR[nextWallR].Permits(BodyR, ref failVecR, failStateR, out newFailStateR))
                {
                    permitR = true;
                }

                if (charR.transform.position.z >= levelR[nextWallR].transform.position.z)
                {
                    if (permitR)
                    {
                        passWallAudio.PlayOneShot(passWallAudio.clip);
                        //Debug.Log("Player R made it past wall " + nextWallR.ToString() + "!");
                    }
                    else
                    {
                        failStateR           |= newFailStateR;
                        materialR.mainTexture = tex[failStateR];

                        GameObject limb         = null;
                        Vector3    limbVelocity = Vector3.zero;
                        switch ((Wall.FailStates)newFailStateR)
                        {
                        case Wall.FailStates.LeftArm:
                        {
                            limb = Instantiate(arm);
                            limb.transform.position = LshoulderR.transform.position;
                            limbVelocity            = armVelocity;
                            Debug.Log("Left arm is gone!");
                        }
                        break;

                        case Wall.FailStates.RightArm:
                        {
                            limb = Instantiate(arm);
                            limb.transform.position = RshoulderR.transform.position;
                            limbVelocity            = armVelocity;
                            Debug.Log("Right arm is gone!");
                        }
                        break;

                        case Wall.FailStates.LeftLeg:
                        {
                            limb = Instantiate(leg);
                            limb.transform.position = LhipR.transform.position;
                            limbVelocity            = legVelocity;
                            Debug.Log("Left leg is gone!");
                        }
                        break;

                        case Wall.FailStates.RightLeg:
                        {
                            limb = Instantiate(leg);
                            limb.transform.position = RhipR.transform.position;
                            limbVelocity            = legVelocity;
                            Debug.Log("Right leg is gone!");
                        }
                        break;
                        }

                        limb.transform.forward = failVecR;
                        Rigidbody rb = limb.AddComponent <Rigidbody>();
                        rb.velocity        = limbVelocity + new Vector3(Random.Range(-0.3f, 0.3f), Random.Range(-0.3f, 0.3f), Random.Range(-0.3f, 0.3f));
                        rb.angularVelocity = Random.Range(2.0f, 4.0f) * Random.onUnitSphere;
                        GenerateParticle(failVecR, charR.transform.position);
                        splatAudio.PlayOneShot(splatAudio.clip);

                        Vector3    camPos   = camR.transform.position;
                        Vector3    shakeVel = Vector3.zero;
                        Quaternion rot      = camR.transform.rotation;

                        {
                            float moveVel = 0.0f;
                            while (camMoveTickR > 0.03f)
                            {
                                camMoveTickR = Mathf.SmoothDamp(camMoveTickR, 0.0f, ref moveVel, 0.1f);
                                Vector3 pos = Vector3.SmoothDamp(camR.transform.position, camPos + Random.Range(0.0f, 0.4f * (camMoveSpeed - camMoveTickR) / camMoveSpeed) * Random.onUnitSphere, ref shakeVel, 0.2f);
                                pos.z = camR.transform.position.z;
                                camR.transform.position = pos;
                                camR.transform.rotation = Quaternion.Euler(Random.Range(-3.0f * (camMoveSpeed - camMoveTickR) / camMoveSpeed, 3.0f * (camMoveSpeed - camMoveTickR) / camMoveSpeed), Random.Range(-3.0f * (camMoveSpeed - camMoveTickR) / camMoveSpeed, 3.0f * (camMoveSpeed - camMoveTickR) / camMoveSpeed), Random.Range(-3.0f * (camMoveSpeed - camMoveTickR) / camMoveSpeed, 3.0f * (camMoveSpeed - camMoveTickR) / camMoveSpeed)) * rot;
                                yield return(null);
                            }
                            camR.transform.rotation = rot;
                            camMoveTickR            = 0.03f;
                        }

                        yield return(new WaitForSeconds(1.0f));

                        if ((failStateR & (uint)Wall.FailStates.LeftLeg) != 0 && (failStateR & (uint)Wall.FailStates.RightLeg) != 0)
                        {
                            failStateR            = 0;
                            materialR.mainTexture = tex[failStateR];
                            yield return(new WaitForSeconds(0.5f));

                            meshR.GetComponent <SkinnedMeshRenderer>().enabled = false;
                            yield return(new WaitForSeconds(0.5f));

                            meshR.GetComponent <SkinnedMeshRenderer>().enabled = true;
                            yield return(new WaitForSeconds(0.5f));

                            meshR.GetComponent <SkinnedMeshRenderer>().enabled = false;
                            yield return(new WaitForSeconds(0.5f));

                            meshR.GetComponent <SkinnedMeshRenderer>().enabled = true;
                        }

                        {
                            float vel = 0.0f;
                            while (camMoveTickR < camMoveSpeed - 0.1f)
                            {
                                camMoveTickR = Mathf.SmoothDamp(camMoveTickR, camMoveSpeed, ref vel, 0.6f);
                                Vector3 pos = Vector3.SmoothDamp(camR.transform.position, camPos, ref shakeVel, 0.3f);
                                pos.z = camR.transform.position.z;
                                camR.transform.position = pos;
                                yield return(null);
                            }
                            camMoveTickR = camMoveSpeed;
                        }
                    }

                    ++nextWallR;
                    permitR = false;
                }
            }
            progress.SetRightValue(charR.transform.position.z / endZ);

            yield return(null);
        }
    }