예제 #1
0
    private void FixedUpdate()
    {
        animator.SetBool("hit", true);
        this.particle.transform.position = this.transform.position;
        times += Time.fixedDeltaTime;

        // kinectPointController.ThreeWave();
        //机器人发球kinectPointController.Squats()
        if (playerStatus == PlayerStatus.robotServe)
        {
            if (Input.GetKey(KeyCode.W))
            {
                move = true;
            }
            if (kinectPointController.Squats())
            {
                move = true;
            }
        }
        if (move == true)
        {
            rightX = false;
            leftX  = false;
            speed  = TestTennisMove(startPosition, pointB.position);
            TennisMove(speed);
            hitTurn = 1; //机器人发球之后,轮到玩家击球。
        }
        if (playerStatus == PlayerStatus.serve)
        {
            //move = false;kinectPointController.HandUp()
            if (Input.GetKey(KeyCode.S))
            {
                hitTurn   = 0;
                hitMoving = true;
                fa        = true;
            }
            if (kinectPointController.HandUp())
            {
                hitTurn   = 0;
                hitMoving = true;
                fa        = true;
            }
        }
        if (hitMoving == true)
        {
            if (fa == true)
            {
                speed = TestTennisMove(playerServePos, pointB.position);
                TennisMove(speed);
            }
            if (leftX == true)
            {
                int i = 0;
                speed  = TestTennisMove(playerServePos, pointB.position);
                speed += new Vector3(-1.75f, 0, 0);
                TennisMove(speed);
                i++;
                if (i == 1)
                {
                    robotRandom = Random.Range(0, 10);
                    i           = 0;
                }
                hitTurn = 0;
                if (robotRandom >= 8)
                {
                }
            }
            if (rightX == true)
            {
                int i = 0;
                speed  = TestTennisMove(playerServePos, pointB.position);
                speed += new Vector3(3, 0, 0);
                TennisMove(speed);
                i++;
                if (i == 1)
                {
                    robotRandom = Random.Range(0, 10);
                    i           = 0;
                }
                hitTurn = 0;
                if (robotRandom >= 8)
                {
                }
            }
        }
        if (playerHit.canHit == true && hitTurn == 1)
        {
            Debug.Log(hitTurn);
            fa        = false;
            move      = false;
            hitMoving = true;
            if (Input.GetKey(KeyCode.A))  //左方向X轴
            {
                hitTurn = 0;
                leftX   = true;
            }
            if (kinectPointController.TwoWave())
            {
                hitTurn = 0;
                leftX   = true;
            }
            if (Input.GetKey(KeyCode.D))
            {
                hitTurn = 0;
                rightX  = true;
            }
            if (kinectPointController.ThreeWave())
            {
                hitTurn = 0;
                rightX  = true;
            }
        }
        //机器人回击
        if (kinecAction.robotHit && hitTurn == 0 && transform.position.z > pointB.position.z)
        {
            playerHit.canHit = false;
            if (robotRandom > 6)
            {
                animator.SetBool("hit", true);
                Quaternion a = new Quaternion(0, 180, 0, 0);
                pointA.transform.rotation = a;
                move    = false;
                hitTurn = 1;
            }
            else
            {
                animator.SetBool("hit", false);
                Quaternion a = new Quaternion(0, 180, 0, 0);
                pointA.transform.rotation = a;
                move      = true;
                hitMoving = false;
                hitTurn   = 1;
            }
        }
        //暂停
        if (kinectPointController.Stop() == true)
        {
            move      = false;
            hitMoving = false;
        }
        End();//得分
        #region 游戏结束
        if (int.Parse(robotGame.text) >= 7)
        {
            if (int.Parse(robotGame.text) - int.Parse(playerGame.text) >= 2)
            {
                game.SwitchSatus(Game.GameStatus.gameEnd1);
            }
        }
        if (int.Parse(playerGame.text) >= 7)
        {
            if (int.Parse(playerGame.text) - int.Parse(robotGame.text) >= 2)
            {
                game.SwitchSatus(Game.GameStatus.gameEnd2);
            }
        }
        #endregion
    }
예제 #2
0
    private void FixedUpdate()
    {
        animator.SetBool("hit", true);
        if (kinectPointController.Squats()) //下蹲
        {
            animator.SetBool("hit", false);
            Quaternion a = new Quaternion(0, 180, 0, 0);
            pointStartA.transform.rotation = a;
            move = true;
        }
        if (Input.GetKey(KeyCode.I))
        {
            animator.SetBool("hit", false);
            Quaternion a = new Quaternion(0, 180, 0, 0);
            pointStartA.transform.rotation = a;
            move = true;
        }

        if (move == true)
        {
            speed = TestTennisMove(startPosition, pointEnd.transform.position);
            left  = false;
            right = false;
        }
        //玩家能否回击条件判定
        if (canHit.canHit == true)
        {
            tempTime += Time.fixedDeltaTime;
            move      = false;
            hitMoving = true;
            infoMessage.gameObject.SetActive(true);
            Fading(tempTime, "现在回击该球!", DURATION);
            //infoMessage.text = "现在回击该球";
            //正手挥拍,X轴偏移
            if (Input.GetKey(KeyCode.K))
            {
                left = true;
            }
            if (kinectPointController.TwoWave())
            {
                left = true;
            }
            ////反手挥拍,X轴偏移
            if (kinectPointController.ThreeWave())
            {
                right = true;
            }
        }
        if (kinecAction.robotHit == true)
        {
            canHit.canHit = false;
            speed         = TestTennisMove(kinecAction.startPosition, pointEnd.transform.position);
            animator.SetBool("hit", false);
            Quaternion a = new Quaternion(0, 180, 0, 0);
            pointStartA.transform.rotation = a;
        }

        if (hitMoving == true)
        {
            if (left == true)
            {
                tempTime += Time.fixedDeltaTime;
                speed     = TestTennisMove(canHit.startPosition, pointEnd.transform.position);
                speed    += new Vector3(-1.75f, 0, 0);
                TennisMove(speed);
                Fading(tempTime, "恭喜您获得该球得分!", DURATION);
                Debug.Log(tempTime);
                if (tempTime > 13)
                {
                    //game.SwitchSatus(Game.GameStatus.gameNew);
                    start.SetActive(true);
                    news.SetActive(false);
                }
            }
            if (right == true)
            {
                tempTime += Time.fixedDeltaTime;
                speed     = TestTennisMove(canHit.startPosition, pointEnd.transform.position);
                speed    += new Vector3(3, 0, 0);
                TennisMove(speed);
                Fading(tempTime, "恭喜您获得该球得分!", DURATION);
                if (tempTime > 13)
                {
                    //game.SwitchSatus(Game.GameStatus.gameNew);
                    start.SetActive(true);
                    news.SetActive(false);
                }
            }
        }
        if (move == true)
        {
            TennisMove(speed);
        }
    }