Ejemplo n.º 1
0
    void Update()
    {
        if (!pView.IsMine)
        {
            return;
        }

        if (!gameOver)
        {
            redScore  = gnc.getScore(true);
            blueScore = gnc.getScore(false);

            redScoreBar.fillAmount  = redScore / 20f;
            blueScoreBar.fillAmount = blueScore / 20f;
            redScoreText.text       = "" + redScore;
            blueScoreText.text      = "" + blueScore;

            if (gameStarted)
            {
                if (!dead)
                {
                    if (showTutorial)
                    {
                        if (Input.GetKeyUp(KeyCode.Return))
                        {
                            Debug.Log("Enter pressed");
                            tutorialNum++;
                            if (tutorialNum < 11)
                            {
                                showTutorial = false;
                                tutorialObj.gameObject.SetActive(false);
                                StartCoroutine(showNextTutorial());
                            }
                            else
                            {
                                showTutorial = false;
                                tutorialObj.gameObject.SetActive(false);
                            }
                        }
                    }
                    if (autoWP == 1)
                    {
                        if (Input.GetKeyUp(KeyCode.E))
                        {
                            if (pbc.canUseWaterPack() && waterPacks > 0)
                            {
                                pbc.applyWaterPack();
                                waterPacks--;
                                waterPackText.text = "Water Packs: " + waterPacks;
                                pbc.setAmmoText();
                            }
                        }
                    }
                    if (outOfBounds)
                    {
                        if (Time.time < outOfBoundsTimer)
                        {
                            outOfBoundsText.text = "Return to Playing Field! " +
                                                   (int)(outOfBoundsTimer - Time.time);
                        }
                        else
                        {
                            ac.SetBool("dead", true);
                            deaths++;
                            deathText.text = "" + deaths;
                            //pbc.dropAllBlasters();
                            dead = true;
                            StartCoroutine(die(-1));
                        }
                    }
                    if (crossHitShown)
                    {
                        if (Time.time > crossHitEndTime)
                        {
                            crossHitShown = false;
                            crossHairHit.gameObject.SetActive(false);
                        }
                    }
                    if (playerBlastImageShown)
                    {
                        if (Time.time > playerBlastImgEndTime)
                        {
                            playerBlastImage.SetActive(false);
                            playerBlastImageShown = false;
                        }
                    }
                    if (damaged)
                    {
                        if (Time.time > nextHP)
                        {
                            //add health
                            if (hp <= 100 - hpAmount)
                            {
                                hp += hpAmount;
                            }
                            //if health was almost 100
                            else
                            {
                                hp = 100;
                            }
                            nextHP = Time.time + hpTime;
                        }
                        if (hp >= 100)
                        {
                            damaged = false;
                        }
                    }
                    if (hp >= 100)
                    {
                        hpBar.fillAmount = 1f;
                    }
                    else
                    {
                        hpBar.fillAmount = (float)hp / 100;
                    }
                    if (bubbleImageShown)
                    {
                        if (bubbleEndTime < Time.time)
                        {
                            bubbleImg.gameObject.SetActive(false);
                            bubbleImageShown = false;
                        }
                    }
                    if (hurtImgShown)
                    {
                        if (hurtEndTime < Time.time)
                        {
                            hurtImg.gameObject.SetActive(false);
                            hurtImgShown = false;
                        }
                    }
                    if (!gc.getQuestionMode())
                    {
                        if (pbc.hasGun())
                        {
                            if (autoWP == 0)
                            {
                                if (pbc.canUseWaterPack() && waterPacks > 0)
                                {
                                    pbc.applyWaterPack();
                                    waterPacks--;
                                    waterPackText.text = "Water Packs: " + waterPacks;
                                    pbc.setAmmoText();
                                }
                            }
                        }
                        if (pbc.isReloading())
                        {
                            if (!ac.GetBool("reloading"))
                            {
                                ac.SetBool("Dancing", false);
                                ac.SetBool("reloading", true);
                            }
                        }
                        else
                        {
                            ac.SetBool("reloading", false);
                            if (Input.GetKeyDown("r"))
                            {
                                if (pbc.canReload())
                                {
                                    pbc.reload();
                                }
                            }
                        }

                        if (sprinting && Time.time > nextRun)
                        {
                            newVect   = transform.position;
                            newVect.y = 1.5f;

                            ///LOCAL INSTANTIATION NOT NETWORK//////////////////////
                            //Instantiate(sprintObj, newVect, transform.rotation);
                            PhotonNetwork.Instantiate(sprintObj.name, newVect, transform.rotation, 0);
                            nextRun = Time.time + runTime;
                        }
                        if (Input.GetKeyDown(KeyCode.LeftShift))
                        {
                            nextRun = Time.time + runTime;
                        }
                        if (Input.GetKey(KeyCode.LeftShift))
                        {
                            sprinting = true;
                        }
                        else
                        {
                            sprinting = false;
                        }

                        moveDirection.x = Input.GetAxis("Horizontal");
                        // moveDirection.y -= gravity * Time.deltaTime;
                        moveDirection.z = Input.GetAxis("Vertical");
                        moveDirection   = transform.TransformDirection(moveDirection);

                        if (!Mathf.Approximately(Input.GetAxis("Horizontal"), 0f) || !Mathf.Approximately(Input.GetAxis("Vertical"), 0f))
                        {
                            ac.SetBool("Dancing", false);
                        }
                        if (sprinting)
                        {
                            moveDirection.x *= speed * sprintMod;
                            moveDirection.z *= speed * sprintMod;
                        }
                        else
                        {
                            moveDirection.x *= speed;
                            moveDirection.z *= speed;
                        }

                        if (controller.isGrounded)
                        {
                            moveDirection.x = Input.GetAxis("Horizontal");
                            moveDirection.y = 0f;
                            moveDirection.z = Input.GetAxis("Vertical");
                            moveDirection   = transform.TransformDirection(moveDirection);

                            if (sprinting)
                            {
                                moveDirection *= speed * sprintMod;
                            }
                            else
                            {
                                moveDirection *= speed;
                            }

                            ac.SetBool("jumping", false);
                            if (Input.GetButton("Jump"))
                            {
                                moveDirection.y = jumpSpeed;
                                ac.SetBool("jumping", true);
                            }
                            if (falling)
                            {
                                if (Time.time > spawnEndTime)
                                {
                                    //Debug.Log("fall dist: " + (int)(startY - transform.position.y));
                                    if ((int)(startY - transform.position.y) > 15)
                                    {
                                        hurtImg.gameObject.SetActive(true);
                                        hurtEndTime  = Time.time + .25f;
                                        hurtImgShown = true;
                                        hp          -= (int)(startY - transform.position.y);
                                        damaged      = true;
                                        nextHP      += damageWait;

                                        if (hp <= 0)
                                        {
                                            ac.SetBool("dead", true);
                                            deaths++;
                                            deathText.text = "" + deaths;
                                            //pbc.dropAllBlasters();
                                            dead = true;
                                            StartCoroutine(die(-1));
                                        }
                                    }
                                }

                                falling = false;
                            }
                        }

                        else
                        {
                            moveDirection.y -= gravity * Time.deltaTime;
                            if (!falling)
                            {
                                if (Time.time > spawnEndTime)
                                {
                                    if (transform.position.y > 20)
                                    {
                                        falling = true;
                                        startY  = transform.position.y;
                                    }
                                }
                            }
                        }
                        //moveDirection = Quaternion.AngleAxis(-30, Vector3.up) * moveDirection;
                        //controller.Move(moveDirection * Time.deltaTime);

                        if (Mathf.Approximately(moveDirection.x, 0) && Mathf.Approximately(moveDirection.z, 0))
                        {
                            ac.SetBool("running", false);
                        }

                        else
                        {
                            ac.SetBool("running", true);
                        }
                        if (Input.GetKeyDown(KeyCode.Alpha2))
                        {
                            if (pbc.checkForBlaster(1))
                            {
                                pbc.swapItems(1);
                            }
                            else
                            {
                                //do nothing?
                            }
                        }
                        if (Input.GetKeyDown(KeyCode.Alpha3))
                        {
                            if (pbc.checkForBlaster(2))
                            {
                                pbc.swapItems(2);
                            }
                            else
                            {
                                //do nothing?
                            }
                        }
                        if (Input.GetKeyDown(KeyCode.Alpha4))
                        {
                            if (pbc.checkForBlaster(3))
                            {
                                pbc.swapItems(3);
                            }
                            else
                            {
                                //do nothing?
                            }
                        }
                        if (Input.GetKeyDown(KeyCode.Alpha5))
                        {
                            if (pbc.checkForBlaster(4))
                            {
                                pbc.swapItems(4);
                            }
                            else
                            {
                                //do nothing?
                            }
                        }
                        if (Input.GetKeyDown(KeyCode.Alpha0))
                        {
                            pbc.dropBlast1(3 * transform.forward + transform.position);
                        }
                        if (Input.GetKeyDown(KeyCode.Alpha9))
                        {
                            ac.SetBool("Dancing", true);
                        }
                    }
                }
            }

            else
            {
                if (countdown)
                {
                    if (PhotonNetwork.Time > gameTimer)
                    {
                        countdown   = false;
                        gameStarted = true;
                        teamText.gameObject.SetActive(false);
                        startTime    = Time.time;
                        spawnEndTime = Time.time + 5f;
                        gc.setGameOver(false);
                        namePlateCanvas.gameObject.SetActive(false);
                        pView.RPC("setNamePlate", RpcTarget.OthersBuffered, null);

                        //gnc.initializeAISLocally();
                    }
                    else
                    {
                        teamText.text = "Game starts in: " + (int)(gameTimer - PhotonNetwork.Time);
                    }
                }
                else
                {
                }
            }
        }
        if (canExit)
        {
            //exit to the main menu
            if (Input.anyKeyDown)
            {
                canExit = false;
                GameObject.FindWithTag("serverConnector").GetComponent <serverConnector>().exitToMainMenu();
                handler.destroyMe();
            }
        }
    }