Exemple #1
0
 //swaps over lightning debuff on plant
 void SwapLightningDebuff()
 {
     if (basePlant.GetActive())
     {
         if ((m_stateInfo.normalizedTime % 1) <= 0.5f)
         {
             DebuffPlant debuff = basePlant as DebuffPlant;
             debuff.SetLightning(true);
             debuff.SetScore(0);
             if (spawnOnceLightning == false)
             {
                 lightning = Instantiate(Resources.Load("Minigames/PlantMinigame/Prefabs/LightningStrike")) as GameObject;
                 lightning.transform.SetParent(basePlant.transform);
                 lightning.transform.localPosition = new Vector3(0, 0, -1);
                 spawnOnceLightning = true;
             }
         }
         else
         {
             spawnOnceLightning = false;
             DebuffPlant debuff = basePlant as DebuffPlant;
             debuff.SetLightning(false);
             debuff.SetScore(20);
         }
     }
 }
Exemple #2
0
    //if tile is swiped over
    public int Swiped(out BasePlant plant)
    {
        int tempScore = 0;

        plant = basePlant;

        //if the plant is already active
        if (basePlant.GetActive())
        {
            //get the score from the plant
            tempScore = basePlant.GetScore();
            Debug.Log(basePlant.GetScore());

            //if the plant is type of double plant
            if (basePlant is DoubleScorePlant)
            {
                //white text
                FloatingTextManager.CreateFloatingText("+" + basePlant.GetScore().ToString(), basePlant.transform, Color.white);
            }
            else if (basePlant is NormalPlant)
            {
                //yellow text
                FloatingTextManager.CreateFloatingText("+" + basePlant.GetScore().ToString(), basePlant.transform);
            }
            else if (basePlant is DebuffPlant)
            {
                FloatingTextManager.CreateFloatingText("+" + basePlant.GetScore().ToString(), basePlant.transform, Color.blue);
                DebuffPlant debuff = basePlant as DebuffPlant;
                Destroy(lightning);
            }

            //activate the dead plant animation
            m_animator.SetTrigger("DeadPlant");

            //Set the plant state to be inactive
            basePlant.SetActive(false);

            for (int i = 0; i < emmiters.Count; i++)
            {
                emmiters [i].Play();
            }
        }
        return(tempScore);
    }
    //does Kevins work but appeals to touch controls for the specific minigame
    void SwipeLine()
    {
        //if there is touch input
        if (Input.touchCount == 1)
        {
            //get that touch input
            Touch touch = Input.GetTouch(0);

            switch (touch.phase)
            {
            //if the touch has began
            case TouchPhase.Began:
            {
                //store that start position
                m_touchBegin = touch.position;
            }
            break;

            //if the touch has ended
            case TouchPhase.Ended:
            {
                //store the end position
                m_touchEnd = touch.position;

                var ray2 = Camera.main.ScreenPointToRay(m_touchBegin);

                Vector2 directionPreNorm = (m_touchEnd - m_touchBegin);
                m_swipeDirection = (m_touchEnd - m_touchBegin);

                m_swipeDirection = NegativePositiveFunction(m_swipeDirection);

                //normalize
                m_swipeDirection.Normalize();

                //check for multiple hits from a raycast and store them
                RaycastHit2D[] hit = Physics2D.RaycastAll(ray2.origin, m_swipeDirection, m_swipeDirection.magnitude);

                //for everything hit by the raycast
                for (int i = 0; i < hit.Length; i++)
                {
                    //check if any of them are plants, if they are
                    if (hit[i].collider.tag == "Plant")
                    {
                        //Get that plants script and set it to swiped
                        PlantScriptManager tempPlantScript = hit[i].collider.gameObject.GetComponent <PlantScriptManager>();

                        //add the plants score to the list of scores
                        m_plantScore.Add(tempPlantScript.Swiped(out plantHit));
                        //add the plants score to the list of scores
                        //m_plantScore.Add(tempPlantScript.Swiped());

                        //if the plant hit is a debuff plant (lightning plant
                        if (plantHit is DebuffPlant)
                        {
                            //Upcase the baseplant to debuff plant since we're sure it's a debuffplant
                            DebuffPlant tempPlant = plantHit as DebuffPlant;

                            //if the debuff plants lightning is active
                            if (tempPlant.GetLightning())
                            {
                                //lock out swiping for 2 seconds
                                bSwipeLockout = true;
                            }
                            //else
                            else
                            {
                                //do nothing
                            }
                        }
                    }
                }

                //for each score swiped
                for (int i = 0; i < m_plantScore.Count; i++)
                {
                    //add that to the game score (DO SOMETHING FUNKY WITH MULTIPLIERS HERE)
                    m_combinedScore += m_plantScore[i];
                }
                //m_combinedScore *= m_plantScore.Count;

                //Create float text feedback numbers
                FloatingTextManager.CreateFloatingText(m_combinedScore.ToString(), Player1.transform);

                //increment the local players score
                if (LocalPlayerPortrait)
                {
                    LocalPlayerPortrait.IncrementScore(m_combinedScore);
                }
                else
                {
                    Player1Stats.IncrementScore(m_combinedScore);
                }

                //m_combinedScore *= m_plantScore.Count;
                //manager.IncrementScore(m_combinedScore);
                m_combinedScore = 0;
                m_plantScore.Clear();
            }
            break;
            }
        }
    }
    //mouse input class
    void OnTileClick()
    {
        //check if the mouse is down
        m_newMouseDown = Input.GetMouseButton(0);

        //if left mouse button is down
        if (m_newMouseDown == true && m_oldMouseDown == false)
        {
            swipe = Instantiate(Resources.Load("Minigames/PlantMinigame/Prefabs/Swipe") as GameObject);

            //shoot a ray from the mouse position to the screen
            m_StartDrag   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            m_StartDrag.z = 0;
        }
        if (m_newMouseDown == true && m_oldMouseDown == true)
        {
            swipe.transform.position = new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y, -5);
        }
        if (m_newMouseDown == false && m_oldMouseDown == true)
        {
            m_EndDrag   = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            m_EndDrag.z = 0;

            Vector2 direction = (m_EndDrag - m_StartDrag);

            direction = NegativePositiveFunction(direction);

            Vector2 directionPreNorm = direction;

            direction = direction.normalized;

            RaycastHit2D[] hits = Physics2D.RaycastAll(m_StartDrag, direction, directionPreNorm.magnitude);

            //check all the hits from the raycast
            for (int i = 0; i < hits.Length; i++)
            {
                //check if any of them are plants, if they are
                if (hits[i].collider.tag == "Plant")
                {
                    //Get that plants script and set it to swiped
                    PlantScriptManager tempPlantScript = hits[i].collider.gameObject.GetComponent <PlantScriptManager>();

                    //get plant component
                    m_plantsHit.Add(tempPlantScript.GetPlantComponent());

                    m_plantScore.Add(tempPlantScript.Swiped(out plantHit));
                    //add the plants score to the list of scores
                    //m_plantScore.Add(tempPlantScript.Swiped());

                    //if the plant hit is a debuff plant (lightning plant
                    if (plantHit is DebuffPlant)
                    {
                        //Upcase the baseplant to debuff plant since we're sure it's a debuffplant
                        DebuffPlant tempPlant = plantHit as DebuffPlant;

                        //if the debuff plants lightning is active
                        if (tempPlant.GetLightning())
                        {
                            //lock out swiping for 2 seconds
                            bSwipeLockout = true;
                        }
                        //else
                        else
                        {
                            //do nothing
                        }
                    }
                }
            }

            //for (int i = 0; i < m_plantsHit.Count; i++) {
            //	m_plantScore.Add (0);
            //	int temp;
            //	m_plantsHit [i].ActivatePlant (out temp);
            //	m_plantScore [m_plantScore.Count-1] = temp;
            //}

            //for each score swiped
            for (int i = 0; i < m_plantScore.Count; i++)
            {
                //add that to the game score (DO SOMETHING FUNKY WITH MULTIPLIERS HERE)
                m_combinedScore += m_plantScore[i];
            }

            //m_combinedScore *= m_plantScore.Count;

            //Create float text feedback numbers
            //FloatingTextManager.CreateFloatingText (m_combinedScore.ToString(), Player1.transform);

            //increment the local players score
            if (LocalPlayerPortrait)
            {
                LocalPlayerPortrait.IncrementScore(m_combinedScore);
            }
            else
            {
                m_portraitScripts [0].GetComponent <PortaitScript> ().IncrementScore(m_combinedScore);
                //GameObject.FindGameObjectWithTag("Portrait").GetComponent<PortaitScript>().IncrementScore (m_combinedScore);
            }
            m_combinedScore = 0;
            m_plantScore.Clear();
            m_plantsHit.Clear();
        }
        m_oldMouseDown = m_newMouseDown;
    }