예제 #1
0
 public void VenusFlyTrapped()
 {
     //TODO: audioclip for trapped
     if (!trapped)
     {
         canMove = false;
         trapped = true;
         GetComponent <Rigidbody>().velocity        = Vector3.zero;
         GetComponent <Rigidbody>().angularVelocity = Vector3.zero;
         Animator animator = beeBody.GetComponent <Animator>();
         animator.SetBool("Trapped", true);
         PopUpTextController.CreateDamageText("Trap", transform);
     }
 }
 private void Awake()
 {
     if (Instance == null)
     {
         Instance = this;
     }
     else
     {
         if (Instance != null)
         {
             Destroy(gameObject);
         }
     }
 }
예제 #3
0
    // Use this for initialization
    void Start()
    {
        // Time left = 2 minutes, or 120 seconds
        timeLeft             = numSeconds;
        timerText.text       = timeLeft.ToString();
        beeScoreText.text    = "Bees Score: 0";
        beeScore             = 0;
        mantisScoreText.text = "Mantis Score: 0";
        mantisScore          = 0;
        kAssigned            = false;
        j1Assigned           = false;
        j2Assigned           = false;
        won          = false;
        startPressed = false;

        // Initialize pop up texts
        PopUpTextController.Initialize();
        audioSource = GetComponent <AudioSource>();
    }
예제 #4
0
 public void StartCountdown(GameMaster.GamePlayState gameState)
 {
     if (gameState == GameMaster.GamePlayState.COUNTDOWN)
     {
         _currentTime -= Time.deltaTime;
         if (_currentTime > 0)
         {
             _countdownText.text = ((int)_currentTime).ToString();
         }
         else
         {
             _currentTime = _startTime;
             GameMaster.Instance.GameState = GameMaster.GamePlayState.PLAYING;
             EventsManager.UpdateUIView();
             PopUpTextController.Initialize();
             AudioFileLoader.Instance.PlayCurrentSong(AudioFileLoader.Instance._selectedSongIndex);
         }
     }
 }
예제 #5
0
    public void AnimateExplosion()
    {
        Debug.Log("Explosion");
        // Increment score counter in ScoreManager
        ScoreManager.Instance.AddScore(_scoreValue);
        // Increment hits counter in ScoreManager
        ScoreManager.Instance._hits++;
        // Show Score pop-up text
        PopUpTextController.CreatePopUpText(_scoreValue.ToString(), gameObject.transform);
        // Instantiate explosion
        GameObject     _go        = (GameObject)Instantiate(_ps, gameObject.transform.position, Quaternion.identity);
        ParticleSystem _explosion = _go.GetComponentInChildren <ParticleSystem>();

        // Play animation
        _explosion.Play();
        // Disable note rendering
        gameObject.SetActive(false);
        // Destroy note and explosion gameobjects after particle animation finishes
        Destroy(gameObject, _explosion.main.duration);
        Destroy(_go, _explosion.main.duration);
    }
예제 #6
0
    // Update is called once per frame
    void Update()
    {
        if (Mathf.RoundToInt(timeLeft) == 33 && !playedHalfWay)
        {
            playedHalfWay = true;
            crowdAnnouncerSource.PlayOneShot(halfWayClip);
        }
        if (Mathf.RoundToInt(timeLeft) == 12 && !startedCountDownClip)
        {
            startedCountDownClip = true;
            crowdAnnouncerSource.PlayOneShot(countDownClip);
        }

        /*if (!kAssigned) {
         *      beeControllers[0].controller = "K";
         *      beeControllers[0].playerIndex = PlayerIndex.Three;
         *      kAssigned = true;
         * } /*else if (!j1Assigned && Input.GetButtonDown("J1Submit")) {
         *      Debug.Log("J1 assigned");
         *      beeControllers[1].controller = "J1";
         *      j1Assigned = true;
         * } else if (!j2Assigned && Input.GetButtonDown("J2Submit")) {
         *      Debug.Log("J2 assigned");
         *      beeControllers[2].controller = "J2";
         *      j2Assigned = true;
         * }*/

        if (!j1Assigned || !j2Assigned || !kAssigned)
        {
            for (int i = 0; i < 3; ++i)
            {
                PlayerIndex  testPlayerIndex = (PlayerIndex)i;
                GamePadState testState       = GamePad.GetState(testPlayerIndex);
                if (testState.IsConnected)
                {
                    if (!j1Assigned)
                    {
                        //beeControllers[1].controller = "J1";
                        beeControllers[1].playerIndex = PlayerIndex.One;
                        j1Assigned = true;
                    }
                    else if (!j2Assigned)
                    {
                        //beeControllers[2].controller = "J2";
                        beeControllers[2].playerIndex = PlayerIndex.Two;
                        j2Assigned = true;
                    }
                    else if (!kAssigned)
                    {
                        beeControllers[0].playerIndex = PlayerIndex.Three;
                        kAssigned = true;
                    }
                }
            }
        }

        timerText.text = Mathf.RoundToInt(timeLeft).ToString();

        if (state == 0)
        {
            if (Input.GetKeyDown(KeyCode.P) || (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed && !startPressed))
            {
                startPressed = true;
                StartCoroutine(StartGame());
            }
            // Tutorial setup, announcer describing situation, players playing
            // TODO: Play welcome and introduction announcement
        }
        else if (state == 1)
        {
            // Game play, enable all actions
            // Start decrementing the timer
            timeLeft -= Time.deltaTime;
            // If the flower is pollinated fully, the bees win
            if (AllFlowersComplete())
            {
                state += 1;
            }
            // If time is up, the mantis wins
            if (timeLeft <= 0)
            {
                state += 2;
            }
        }
        else if (state == 2)
        {
            // Play game ending state, bees won
            crowdAnnouncerSource.Stop();
            if (!won)
            {
                for (int i = 0; i < flowers.Count; i++)
                {
                    //flowers[i].animator.SetTrigger("Restart");
                }
                audioSource.PlayOneShot(winClip);
                won = true;
                beeScore++;
                beeScoreText.text = "Bees Score: " + beeScore;
                VRUIs[3].SetActive(true);
                //xboxUIs[3].SetActive(true);
            }
            if (!winningStuffPlays)
            {
                winningStuffPlays = true;
                StartCoroutine(PlaySound(3.5f, announcerSource, beesWinClip));
            }

            PopUpTextController.CreatePopUpText("The bees win!", mantis.gameObject.transform);
        }
        else if (state == 3)
        {
            if (!winningStuffPlays)
            {
                // Play game ending state, mantis won
                winningStuffPlays = true;
                StartCoroutine(PlaySound(3.5f, announcerSource, mantisWinsClip));
            }
            PopUpTextController.CreatePopUpText("The mantis wins!", mantis.gameObject.transform);
            if (!won)
            {
                for (int i = 0; i < flowers.Count; i++)
                {
                    flowers[i].animator.SetTrigger("Fade");
                    flowers[i].animator.SetBool("Smile", false);
                    flowers[i].pollinationCompleteParticles.Stop();
                }
                audioSource.PlayOneShot(winClip);
                won = true;
                mantisScore++;
                mantisScoreText.text = "Mantis Score: " + mantisScore;
                VRUIs[4].SetActive(true);
                //xboxUIs[4].SetActive(true);
            }
        }
        if (state == 4)
        {
            PopUpTextController.CreatePopUpText("Mantis: " + mantisScore + " Bee: " + beeScore, mantis.gameObject.transform);
        }
        // Play again
        if (state == 2 || state == 3)
        {
            if (!ultimateClipPlayed)
            {
                if (mantisScore + beeScore >= 3)
                {
                    // TODO: Declare final winner
                    // Wait for everything to finish
                    // Present final scores, play audio
                    StartCoroutine(Finishing(mantisScore, beeScore));
                }
                else
                {
                    // Restart
                    if (Input.GetKeyDown(KeyCode.N) || (GamePad.GetState(PlayerIndex.One).Buttons.Start == ButtonState.Pressed && startPressed))
                    {
                        //Restart();
                        startPressed = false;
                        StartCoroutine(RestartCoroutine());
                    }
                }
            }
        }
        if (Input.GetKeyDown(KeyCode.N))
        {
            //Restart();
            startPressed = false;
            gameName.SetActive(false);
            StartCoroutine(RestartCoroutine());
        }
    }
예제 #7
0
    void Update()
    {
        if (canMove)
        {
            //keyboard or xbox

            /*if (Input.GetButtonDown(controller + "Fire1")) {
             *      Sting();
             * }*/
            // Detect whether bee is pollinating
            if ((controller != null && (Input.GetButton(controller + "Fire1") || Input.GetButton(controller + "Fire2"))) ||
                (GamePad.GetState(playerIndex).Buttons.A == ButtonState.Pressed || GamePad.GetState(playerIndex).Buttons.B == ButtonState.Pressed))
            {
                if (this.GetComponent <ColliderPushBack>().onFlower)
                {
                    // If pollinating, increment pollination status
                    if (pollination >= 0 && startPollinating)
                    {
                        pollination += 1f * Time.deltaTime;
                        // Start pollinating if not pollinating and hasn't started
                    }
                    else if (pollination <= 0f && !startPollinating && !pollinationAudioSource.isPlaying && !flower.pollinationComplete)
                    {
                        gameObject.GetComponentInChildren <ParticleSystem>().Play();
                        beeBody.GetComponent <Animator>().SetBool("Pollinate", true);
                        startPollinating = true;
                        pollinationAudioSource.PlayOneShot(pollinatingClip);
                        if (flower != null)
                        {
                            flower.pollinatingParticles.SetActive(true);
                            flower.Smile();
                        }
                        StartCoroutine(Pollinate());
                    }
                }
            }
            // If pollinating has stopped, determine whether it was enough
            if (!startPollinating && pollination > 0f || !this.GetComponent <ColliderPushBack>().onFlower)
            {
                pollinationAudioSource.Pause();
                gameObject.GetComponentInChildren <ParticleSystem>().Stop();
                beeBody.GetComponent <Animator>().SetBool("Pollinate", false);
                if (pollination >= 1.25f)
                {
                    // TODO: Haptic feedback, success
                    flower.numPollinations++;
                    PopUpTextController.CreatePopUpText("+1", transform);
                    pollinationAudioSource.Stop();
                    //pollinationAudioSource.PlayOneShot(pollinationSuccessfulClip);
                }
                pollination = 0f;
                if (flower != null)
                {
                    flower.pollinatingParticles.SetActive(false);
                    flower.Idle();
                }
            }

            //to maintain previous and current position and rotation
            prevLoc = curLoc;
            curLoc  = transform.position;
            prevRot = curRot;
            curRot  = transform.rotation;

            //get displacements in x and z

            float xD;
            float zD;

            if (controller == "K")
            {
                //for keyboard
                xD = Input.GetAxis(controller + "Horizontal");
                zD = Input.GetAxis(controller + "Vertical");
            }
            else
            {
                //for xbox controllers
                xD = GamePad.GetState(playerIndex).ThumbSticks.Left.X;
                zD = GamePad.GetState(playerIndex).ThumbSticks.Left.Y;
            }

            var x = xD * Time.deltaTime * 3.0f;
            var z = zD * Time.deltaTime * 3.0f;

            //change position wrt last
            curLoc            += new Vector3(x, 0, z);
            transform.position = curLoc;

            //change rotation wrt last
            curRot             = Quaternion.Slerp(curRot, (curLoc - prevLoc == Vector3.zero ? curRot : Quaternion.LookRotation(curLoc - prevLoc)), Time.fixedDeltaTime * 30);
            transform.rotation = curRot;
        }

        //clamp position to a restricted space
        transform.position = new Vector3(Mathf.Clamp(transform.position.x, birdTransform.position.x - maxDistance.x, birdTransform.position.x + maxDistance.x),
                                         _followOffset.y,
                                         Mathf.Clamp(transform.position.z, birdTransform.position.z - maxDistance.y, birdTransform.position.z + maxDistance.y));
    }