Esempio n. 1
0
    void OnWaterSpray(Vector3 mousePostiion)
    {
        if (m_levelManager.State == LevelManager.LevelState.End ||
            m_levelManager.State == LevelManager.LevelState.Paused)
        {
            return;
        }

        //if it's the FTUE, then stop the water player and return
        if (m_levelManager.State == LevelManager.LevelState.FTUE)
        {
            m_waterPlayer.Stop();
            return;
        }

        if (mousePostiion.x < (Screen.width / 10.0f))
        {
            return;
        }

        if (m_levelManager.AvailableWater <= 0.0f || m_levelManager.WaterFilling)
        {
            m_waterPlayer.Stop();
            return;
        }

        m_waterPlayer.Spray(mousePostiion);
        m_levelManager.ConsumeWater();

        bool dispel = false;

        for (int i = (m_fires.Count - 1); i >= 0; i--)
        {
            //to determine if the fire is dispelled, we check if it collided with tip
            dispel = m_waterPlayer.CheckCollisionWith(m_fires[i].transform);
            //let's dispel this fire!
            if (dispel == true)
            {
                // Water tip is mostly on fire
                m_levelManager.AddScore(LevelManager.ScoreType.Fire);
                //check if player 2 also collected something
                //note that this is simulated play for player 2
                if (GSTJ_Core.SelectedMode == GSTJ_Core.GameMode.Multi)
                {
                    m_levelManager.AddScoreForOpponent(LevelManager.ScoreType.Fire);
                }
                m_fires[i].Extinguish();
                //remove it from the water player collision list
                m_waterPlayer.RemoveFromList(m_fires[i].transform);
                m_fires.Remove(m_fires[i]);
            }
        }

        for (int i = (m_coins.Count - 1); i >= 0; i--)
        {
            //to determine if the coin can be collected, we check if it collided with tip
            dispel = m_waterPlayer.CheckCollisionWith(m_coins[i].transform);
            //let's collect this coin!
            if (dispel == true)
            {
                //start a co-routine to take care of flying coin image to the counter
                FlyItemToCounter(m_coins[i].transform, dur: 1.0f, scaleDown: false);
                // Water tip is mostly on coin
                m_levelManager.AddScore(LevelManager.ScoreType.Coin);

                //check if player 2 also collected something
                if (GSTJ_Core.SelectedMode == GSTJ_Core.GameMode.Multi)
                {
                    m_levelManager.AddScoreForOpponent(LevelManager.ScoreType.Coin);
                }

                m_coins[i].Collect();
                //first remove it from the water player collision list
                m_waterPlayer.RemoveFromList(m_coins[i].transform);
                m_coins.Remove(m_coins[i]);
            }
        }

        for (int i = (m_easterEggs.Count - 1); i >= 0; i--)
        {
            //to determine if the easter egg can be collected, we check if it collided with tip
            dispel = m_waterPlayer.CheckCollisionWith(m_easterEggs[i].transform);
            //let's collect this easter egg!
            if (dispel == true)
            {
                //check if easter egg is already collected
                bool isEasEggCol = m_levelManager.IsEasterEggCollected(HUD.PlayerHUD.Player_01,
                                                                       m_easterEggs[i].GetSpriteResource(),
                                                                       m_easterEggCollectedCount);
                if (isEasEggCol == true)
                {
                    //only add score for this collectible
                    m_levelManager.AddCollectibleScore(HUD.PlayerHUD.Player_01, m_easterEggCollectedCount);
                }
                else
                {
                    //add the easter egg image to the in-game HUD and end-game UI
                    m_easterEggCollectedCount += 1;
                    m_levelManager.AddCollectibletoUI(HUD.PlayerHUD.Player_01,
                                                      m_easterEggs[i].GetSpriteResource(),
                                                      m_easterEggCollectedCount);
                }

                // Water helper is looking mostly towards easter egg
                //note that collectible score is based on difficulty mode
                int difficultyID = PlayerPrefs.GetInt("LEVEL", 0);
                int colScore     = 25;
                if (difficultyID == 1)
                {
                    colScore = 50;                    //med mode
                }
                if (difficultyID == 2)
                {
                    colScore = 40;                    //hard mode val is doubled
                }
                m_levelManager.AddScore(LevelManager.ScoreType.Coin, colScore);
                //play the easter egg (item) collection sound
                m_levelManager.PlayItemColAudio();
                //check if easter egg is also collected by the opponent
                if (GSTJ_Core.SelectedMode == GSTJ_Core.GameMode.Multi)
                {
                    m_levelManager.CheckEasterEggForOpponent(m_easterEggs[i].GetSpriteResource(), 50);
                }

                m_easterEggs[i].Collect();
                //first remove it from the water player collision list
                m_waterPlayer.RemoveFromList(m_easterEggs[i].transform);
                m_easterEggs.Remove(m_easterEggs[i]);
            }
        }
    }