Exemple #1
0
    //-------------------------------------------------------------------------------------------------
    private void SpawnBabiesWith(PreyController otherPrey)
    {
        //If mating then spawn babies
        if (m_isMating || otherPrey.m_isMating)
        {
            AudioManager.Play(eSoundType.BUNNY_SEXY_TIMES);

            //Spawn setup
            int     spawnTotal    = GameManager.GetInstance().m_babySpawnTotal;
            Vector2 spawnLocation = (transform.position + otherPrey.transform.position) / 2;
            Vector3 babyLocation  = spawnLocation;
            babyLocation.z = GameManager.GAME_Z;

            //Spawn babies
            for (int babyIndex = 0; babyIndex < spawnTotal; ++babyIndex)
            {
                Instantiate(GameManager.GetInstance().m_preyPrefab, babyLocation, Quaternion.identity);
            }

            //Spawn Explosion
            Vector3 explosionLocation = babyLocation;
            explosionLocation.y -= 0.5f;             //Appear slightly below mate location
            Instantiate(GameManager.GetInstance().m_explosionPrefab, explosionLocation, Quaternion.identity);

            StopHop();
            otherPrey.StopHop();
        }
    }
Exemple #2
0
    //-------------------------------------------------------------------------------------------------
    private void ReviveAndTransformBack()
    {
        //Find controller if it was a prey
        GameObject[] preys = GameObject.FindGameObjectsWithTag(TAG_PREY);
        for (int preyIndex = 0; preyIndex < preys.Length; ++preyIndex)
        {
            PreyController prey = preys[preyIndex].GetComponent <PreyController>();
            if (prey != null)
            {
                //Revive dead players
                if (prey.m_netController != null)
                {
                    prey.m_isDead = false;
                }
                //Clear AI
                else
                {
                    Destroy(prey.gameObject);
                }
            }
        }

        //Find controller if it was a predator
        GameObject[] predators = GameObject.FindGameObjectsWithTag(TAG_PREDATOR);
        for (int predatorIndex = 0; predatorIndex < predators.Length; ++predatorIndex)
        {
            PredatorController predator = predators[predatorIndex].GetComponent <PredatorController>();
            if (predator != null)
            {
                predator.TransformIntoPrey();
            }
        }
    }
Exemple #3
0
    //-------------------------------------------------------------------------------------------------
    public void Mate()
    {
        if (m_isDead)
        {
            return;
        }

        if (GameManager.GetInstance().m_currentState != eGameState.IN_GAME)
        {
            return;
        }

        //Find closest mate
        PreyController closestPrey = GameManager.GetClosestPrey(this);

        if (closestPrey != null)
        {
            //Mate in their direction
            Vector2 positionMate    = closestPrey.transform.position;
            Vector2 positionCurrent = transform.position;
            Vector2 hopDirection    = positionMate - positionCurrent;

            // play audio when I attempt to mate;
            if (m_isMating == false)
            {
                AudioManager.Play(eSoundType.BUNNY_LAUGH);
            }

            m_isMating     = true;
            m_firstContact = true;
            Hop(hopDirection);
        }
    }
Exemple #4
0
 //-------------------------------------------------------------------------------------------------
 private void SpawnAdditionalPrey()
 {
     GameObject[] preys = GameObject.FindGameObjectsWithTag(TAG_PREY);
     for (int preyIndex = 0; preyIndex < preys.Length; ++preyIndex)
     {
         PreyController prey = preys[preyIndex].GetComponent <PreyController>();
         Instantiate(m_preyPrefab, prey.transform.position, Quaternion.identity);
     }
 }
Exemple #5
0
    //-------------------------------------------------------------------------------------------------
    public static PreyController GetClosestPrey(Vector2 fromPosition, float range, PreyController ignore = null)
    {
        //Setup
        float          closestDistance = -1.0f;
        PreyController closestPrey     = null;

        GameObject[] preys = GameObject.FindGameObjectsWithTag(TAG_PREY);

        //Find the closest one
        for (int preyIndex = 0; preyIndex < preys.Length; ++preyIndex)
        {
            PreyController currentPrey = preys[preyIndex].GetComponent <PreyController>();
            if (currentPrey == null)
            {
                continue;
            }

            Vector2 preyPosition = currentPrey.gameObject.transform.position;
            float   preyDistance = Vector2.Distance(preyPosition, fromPosition);

            //Is close
            if (closestDistance == -1.0f ||
                preyDistance < closestDistance)
            {
                //Is not the prey to ignore
                if (currentPrey != ignore)
                {
                    //New closest prey
                    closestPrey     = currentPrey;
                    closestDistance = preyDistance;
                }
            }
        }

        //Dont care about range
        if (range == -1.0f)
        {
            return(closestPrey);
        }

        //Make sure it's less than range
        if (closestDistance < range)
        {
            return(closestPrey);
        }

        //Closest prey not within range
        return(null);
    }
Exemple #6
0
    //-------------------------------------------------------------------------------------------------
    private void AddPlayer(VirtualNetworkController controller)
    {
        Vector3 spawnLocation = Vector3.zero;

        spawnLocation.z = GAME_Z;
        GameObject     preyObject = Instantiate(m_preyPrefab, spawnLocation, Quaternion.identity);
        PreyController prey       = preyObject.GetComponent <PreyController>();

        prey.m_netController = controller;

        m_UIJoin.SetActive(false);
        if (m_firstGame)
        {
            m_UIInstructions.SetActive(true);
        }
    }
Exemple #7
0
    //-------------------------------------------------------------------------------------------------
    public PreyController[] GetHumanPrey()
    {
        List <PreyController> preyList = new List <PreyController>();

        GameObject[] preys = GameObject.FindGameObjectsWithTag(TAG_PREY);
        for (int preyIndex = 0; preyIndex < preys.Length; ++preyIndex)
        {
            PreyController prey = preys[preyIndex].GetComponent <PreyController>();
            if (prey != null)
            {
                if (prey.IsPlayer())
                {
                    preyList.Add(prey);
                }
            }
        }
        return(preyList.ToArray());
    }
Exemple #8
0
    //-------------------------------------------------------------------------------------------------
    private void RemovePlayer(VirtualNetworkController controller)
    {
        //Find controller if it was a prey
        GameObject[] preys = GameObject.FindGameObjectsWithTag(TAG_PREY);
        for (int preyIndex = 0; preyIndex < preys.Length; ++preyIndex)
        {
            PreyController prey = preys[preyIndex].GetComponent <PreyController>();
            if (prey != null)
            {
                if (prey.m_netController == controller)
                {
                    // C4 - ghosts were multiplying really fast
                    GameObject.Destroy(prey.gameObject);
                }
            }

            if (m_firstGame && (HopperNetwork.GetPlayerCount() == 0))
            {
                m_UIJoin.SetActive(true);
                m_UIInstructions.SetActive(false);
            }
        }

        //Find controller if it was a predator
        GameObject[] predators = GameObject.FindGameObjectsWithTag(TAG_PREDATOR);
        for (int predatorIndex = 0; predatorIndex < predators.Length; ++predatorIndex)
        {
            PredatorController predator = predators[predatorIndex].GetComponent <PredatorController>();
            if (predator != null)
            {
                if (predator.m_netController == controller)
                {
                    Destroy(predator);
                    return;
                }
            }
        }
    }
Exemple #9
0
    //-------------------------------------------------------------------------------------------------
    private void OnCollisionEnter2D(Collision2D other)
    {
        GameObject hitObject = other.gameObject;

        if (IsPlayer())
        {
            PreyController hitPrey = hitObject.GetComponent <PreyController>();
            if (hitPrey == null)
            {
                return;
            }

            if (hitPrey.IsPlayer())
            {
                SpawnBabiesWith(hitPrey);
            }
            else if (m_isMating && m_firstContact)
            {
                m_firstContact = false; // only play a bump once
                AudioManager.Play(eSoundType.BUNNY_BUMP);
            }
        }
    }
    //-------------------------------------------------------------------------------------------------
    private void UpdateAttack()
    {
        if (m_isAttacking)
        {
            m_attackTimer += Time.deltaTime;

            //Find what we can attack
            int          maxThingsToEatThisFrame = 10;
            Collider2D[] colliders = new Collider2D[maxThingsToEatThisFrame];
            m_attackAreaCollider.OverlapCollider(m_attackAreaFilter, colliders);

            //Loop through all things attacked
            for (int colliderIndex = 0; colliderIndex < colliders.Length; ++colliderIndex)
            {
                if (colliders[colliderIndex] == null)
                {
                    continue;
                }

                GameObject attackedObject       = colliders[colliderIndex].gameObject;
                Transform  attackedObjectParent = attackedObject.transform.parent;
                if (attackedObjectParent == null)
                {
                    continue;
                }

                PreyController attackedPrey = attackedObjectParent.GetComponent <PreyController>();
                if (attackedPrey != null)
                {
                    if (attackedPrey.m_isDead)
                    {
                        continue;
                    }

                    if (m_isFirstPrey)
                    {
                        AudioManager.Play(eSoundType.FOX_EAT);
                        AudioManager.Play(eSoundType.BUNNY_SCREAM);
                        m_isFirstPrey = false;
                    }

                    attackedPrey.Eaten();
                    IncreaseStomachSize(m_foodSizeBunny);
                }
            }

            //Stop attacking
            if (m_attackTimer >= m_attackDuration)
            {
                m_isAttacking = false;
            }
        }
        else
        {
            //Update attack area location
            float attackAreaOffset = 0.75f;
            m_attackAreaReference.transform.localPosition = m_movePrevious * attackAreaOffset;
            m_attackAreaReference.transform.rotation      = Quaternion.Euler(0.0f, 0.0f, Mathf.Rad2Deg * Mathf.Atan2(m_movePrevious.y, m_movePrevious.x));
        }

        if (m_isAttacking)
        {
            float attackAlpha = (m_attackDuration - m_attackTimer) / m_attackDuration;
            m_attackBiteReference.color = new Color(1.0f, 1.0f, 1.0f, Mathf.Sqrt(attackAlpha));
        }
        else
        {
            m_attackBiteReference.color = new Color(1.0f, 1.0f, 1.0f, 0.0f);
        }
    }
Exemple #11
0
 //-------------------------------------------------------------------------------------------------
 public static PreyController GetClosestPrey(Vector2 fromPosition, PreyController ignore = null)
 {
     return(GetClosestPrey(fromPosition, -1.0f, ignore));
 }
Exemple #12
0
 //-------------------------------------------------------------------------------------------------
 public static PreyController GetClosestPrey(PreyController fromPrey)
 {
     return(GetClosestPrey(fromPrey.gameObject.transform.position, fromPrey));
 }