示例#1
0
    void OnCollisionEnter(Collision collision)
    {
        BoidsFish collidedFish = collision.gameObject.GetComponent <BoidsFish> ();

        if (collision.gameObject.tag == "Fish" && collidedFish.Size < this.Size &&
            this.Size != SIZE.GOD && collidedFish.Size != SIZE.GOD)
        {
            // check if contact point is near the mouth
            if (Vector3.Angle(transform.forward, collision.contacts[0].point - transform.position) < 60)
            {
                // collided with prey, eat it
                this.State = STATE.EATING;
                collidedFish.Eaten(this);
            }
        }
        else if (collision.gameObject.tag == "Player" && collidedFish.Size < this.Size && collidedFish.Size != SIZE.GOD && this.Size != SIZE.GOD)
        {
            // check if contact point is near the mouth
            if (Vector3.Angle(transform.forward, collision.contacts [0].point - transform.position) < 60)
            {
                // collided with Auliv, kill?
                Player auliv = collision.gameObject.GetComponent <Player> ();
                auliv.Eaten(this);
            }
        }
    }
示例#2
0
 /// <summary> This message is called by the child FlockVolume gameobject </summary>
 public void AddPeer(BoidsFish peer)
 {
     if (this.Flock.Count < BoidsSettings.Instance.MaxFlockSize)
     {
         this.Flock.Add(peer);
     }
 }
示例#3
0
 public virtual void RemoveFishReferences(BoidsFish referencedFish)
 {
     Repellants.Remove(referencedFish);
     Predators.Remove(referencedFish);
     Predatees.Remove(referencedFish);
     // do something if predators are gone
 }
示例#4
0
    protected bool checkIfVisible(BoidsFish target)
    {
        // if target is too close, it is always visible
        if (Vector3.Distance(target.transform.position, transform.position) < 20)
        {
            return(true);
        }

        // if target is out of sight
        if (Vector3.Angle(transform.forward, target.transform.position - transform.position) > BoidsSettings.Instance.MedFishVisualAngle)
        {
            return(false);
        }

        // if target is obscured
        RaycastHit raycastHit;
        int        layerMask = 1 << 8 | 1 << 9 | 1 << 14 | 1 << 15 | 1 << 16 | 1 << 17 | 1 << 18 | 1 << 20;

        layerMask = ~layerMask;
        Physics.Raycast(transform.position, target.transform.position - transform.position, out raycastHit, Mathf.Infinity, layerMask);
        if (raycastHit.collider != target.GetComponent <Collider> ())
        {
            return(false);
        }
        return(true);
    }
示例#5
0
    void OnTriggerExit(Collider other)
    {
        BoidsFish fish = other.gameObject.GetComponent <BoidsFish>();

        if (fish && fish != GameManager.Instance.Player)
        {
            FishManager.Instance.DestroyFish(fish);
        }
    }
示例#6
0
    void OnTriggerExit(Collider other)
    {
        BoidsFish predatee = other.gameObject.GetComponent <BoidsFish>();

        if (predatee != null && (predatee.Size < this.ParentFish.Size))
        {
            predatee.RemovePredator(this.ParentFish);
        }
    }
示例#7
0
    void OnTriggerEnter(Collider other)
    {
        // Get the triggering BoidsFish
        BoidsFish predatee = other.gameObject.GetComponent <BoidsFish>();

        if (predatee != null && (predatee.Size < this.ParentFish.Size))
        {
            this.ParentFish.AddPredatee(predatee);
        }
    }
示例#8
0
    void OnTriggerExit(Collider other)
    {
        // Is the triggering object a BoidsFish?
        BoidsFish peer = other.gameObject.GetComponent <BoidsFish>();

        if (peer != null && (peer.Size == this.ParentFish.Size))
        {
            this.ParentFish.RemovePeer(peer);
        }
    }
示例#9
0
    void OnTriggerExit(Collider other)
    {
        // Is the triggering object a BoidsFish?
        BoidsFish fish = other.gameObject.GetComponent <BoidsFish>();

        if (fish != null)
        {
            fish.OutsideBounds(this);
        }
    }
示例#10
0
 public virtual void RemoveFishReferences(BoidsFish referencedFish)
 {
     if (this.PhysicalTarget == referencedFish)
     {
         this.Idle();
     }
     Repellants.RemoveAll(fish => fish == referencedFish);
     Predators.RemoveAll(fish => fish == referencedFish);
     Predatees.RemoveAll(fish => fish == referencedFish);
     // do something if predators are gone
 }
示例#11
0
    void OnTriggerEnter(Collider other)
    {
        // Is the triggering object a BoidsFish that is attracted to this target?
        BoidsFish attracted = other.gameObject.GetComponent <BoidsFish>();

        if (attracted != null && this.Attracts.Contains(attracted.Size))
        {
            // attracted.SendMessage("AddFlockTarget", this, SendMessageOptions.RequireReceiver);
            attracted.PhysicalTarget = this;
        }
    }
示例#12
0
    void OnCollisionEnter(Collision collision)
    {
        BoidsFish collidedFish = collision.gameObject.GetComponent <BoidsFish> ();

        if (collision.gameObject.tag == "Fish" && collidedFish.Size < this.Size)
        {
            // collided with prey, eat it
            this.State = STATE.EATING;
            collidedFish.Eaten(this);
        }
    }
示例#13
0
    void OnTriggerExit(Collider other)
    {
        // Is the triggering object a BoidsFish?
        BoidsFish attracted = other.gameObject.GetComponent <BoidsFish>();

        if (attracted != null && attracted.PhysicalTarget == this)
        {
            // attracted.SendMessage("AddFlockTarget", this, SendMessageOptions.RequireReceiver);
            attracted.PhysicalTarget = null;
        }
    }
示例#14
0
 protected void OnTriggerEnter(Collider other)
 {
     if (other.isTrigger == false)
     {
         BoidsFish fish = other.gameObject.GetComponent <BoidsFish> ();
         if (fish && other.gameObject != GameManager.Instance.Player)
         {
             Debug.Log("Repel!");
             fish.beingRepelled = true;
             fish.delayCancelRepel(2);
         }
     }
 }
示例#15
0
    public float CalculateDistance(MonoBehaviour obj)
    {
        BoidsFish targetFish = obj as BoidsFish;

        if (targetFish != null)
        {
            return(Vector3.Distance(targetFish.transform.position, transform.position));
        }
        else
        {
            return(200);
        }
    }
示例#16
0
    void OnTriggerExit(Collider other)
    {
        // Is the triggering object a BoidsFish?
        BoidsFish repellant = other.gameObject.GetComponent <BoidsFish>();

        if (repellant != null)
        {
            // Is the triggering BoidsFish the same size as this one?
            if (repellant.Size == this.ParentFish.Size)
            {
                // this.ParentFish.SendMessage("RemoveRepellant", repellant, SendMessageOptions.RequireReceiver);
                this.ParentFish.RemoveRepellant(repellant);
            }
        }
    }
示例#17
0
 public virtual void Eaten(BoidsFish eater)
 {
     eater.BeingEaten = this;
     eater.Animator.SetTrigger("Eat");
     if (eater.audioSource == null)
     {
         eater.audioSource = GetComponent <AudioSource>();
     }
     eater.audioSource.clip  = eatSound;
     eater.audioSource.pitch = 1.0f;
     eater.audioSource.Play();
     eater.audioSource.clip = mediumFishSound;
     eater.audioSource.Play();
     /*GameObject energyBall = (GameObject) */
 }
示例#18
0
    public void RegisterFish(BoidsFish fish)
    {
        if (fish.Size == BoidsFish.SIZE.SMALL)
        {
            this.SmallFishList.Add(fish);
        }

        else if (fish.Size == BoidsFish.SIZE.MEDIUM)
        {
            this.MediumFishList.Add(fish);
        }

        else
        {
            this.LargeFishList.Add(fish);
        }
    }
示例#19
0
    void OnTriggerEnter(Collider other)
    {
        // Is the triggering object a BoidsFish?
        BoidsFish peer = other.gameObject.GetComponent <BoidsFish>();

        if (peer != null)
        {
            // Is the triggering BoidsFish the same size as this one?
            if (peer.Size <= this.ParentFish.Size)
            {
                this.ParentFish.AddPeer(peer);
            }
            else if (peer.Size >= BoidsFish.SIZE.LARGE)// IT'S A PREDATOR AHHHH
            {
                this.ParentFish.Flee();
            }
        }
    }
示例#20
0
 public void DestroyFish(BoidsFish fishToDestroy)
 {
     foreach (BoidsFish aFish in LargeFishList)
     {
         aFish.RemoveFishReferences(fishToDestroy);
     }
     foreach (BoidsFish aFish in MediumFishList)
     {
         aFish.RemoveFishReferences(fishToDestroy);
     }
     foreach (BoidsFish aFish in SmallFishList)
     {
         aFish.RemoveFishReferences(fishToDestroy);
     }
     LargeFishList.Remove(fishToDestroy);
     MediumFishList.Remove(fishToDestroy);
     SmallFishList.Remove(fishToDestroy);
     Destroy(fishToDestroy.gameObject);
 }
示例#21
0
    public override void Eaten(BoidsFish eater)
    {
        if (this.Dead)
        {
            return;
        }

        this.Dead = true;

        Action reload = () => {
            FishManager.Instance.Reset();
            OrbManager.Instance.Reset();
            GameManager.Instance.WaitForInputToReload();
        };

        GUIManager.Instance.FadeToEaten(reload);

        base.Eaten(eater);
    }
示例#22
0
    void OnTriggerEnter(Collider other)
    {
        // Get the triggering BoidsFish
        BoidsFish predatee = other.gameObject.GetComponent <BoidsFish>();

//		EnergyBall b;

        if (predatee != null && (predatee.Size < this.ParentFish.Size))
        {
            this.ParentFish.AddPredatee(predatee);
        }
//		else
//		{
//			b = other.gameObject.GetComponent<EnergyBall>();
//			if (b != null && (this.ParentFish.Size == BoidsFish.SIZE.GOD))
//			{
//				this.ParentFish.A(b);
//			}
//		}
    }
示例#23
0
 /// <summary> Called by the predator gameobject </summary>
 public void RemovePredator(BoidsFish predator)
 {
     this.Predators.Remove(predator);
 }
示例#24
0
 /// <summary> Called by the hunt volume </summary>
 public void RemovePredatee(BoidsFish predatee)
 {
     this.Predatees.Remove(predatee);
 }
示例#25
0
 /// <summary> Called by the hunt volume </summary>
 public void AddPredatee(BoidsFish predatee)
 {
     this.Predatees.Add(predatee);
 }
示例#26
0
 /// <summary> Called by the child RepelVolume gameobject </summary>
 public void RemoveRepellant(BoidsFish repellant)
 {
     this.Repellants.Remove(repellant);
 }
示例#27
0
 /// <summary> Called by the predator </summary>
 public void AddPredator(BoidsFish predator)
 {
     this.Predators.Add(predator);
 }
示例#28
0
 public override void RemoveFishReferences(BoidsFish referencedFish)
 {
     base.RemoveFishReferences(referencedFish);
     Flock.RemoveAll(fish => fish == referencedFish);
 }
示例#29
0
 /// <summary> This message is called by the child FlockVolume gameobject </summary>
 public void RemovePeer(BoidsFish peer)
 {
     this.Flock.Remove(peer);
 }
示例#30
0
    protected void AnalyzePrey()
    {
        // when eating, dont try to hunt anyone
        if (this.State == STATE.EATING)
        {
            return;
        }

        if (size == SIZE.GOD)
        {
            // God fish has special logic, it will sense energies and chase them no matter how far away
            EnergyBall eBall = checkForEnergy();
            if (eBall)
            {
                this.PhysicalTarget = eBall;
                Hunt();
            }
            else
            {
                Idle();
            }

            return;
        }

        FishTarget orbTarget = this.PhysicalTarget as FishTarget;

        if (orbTarget)
        {
            // light orb presents, ignore all else
            return;
        }

        BoidsFish predatee = this.PhysicalTarget as BoidsFish;

        // if the target is out of sight, stop hunting
        if (predatee && !checkIfVisible(predatee))
        {
            predatee = null;
        }

        if (predatee != null)
        {
            foreach (BoidsFish potentialSwitch in this.Predatees)
            {
                // ignore if not visible
                if (!checkIfVisible(potentialSwitch))
                {
                    continue;
                }

                if (BoidsSettings.Instance.AulivTheBestPrey)
                {
                    // Don't switch if the predatee is A.U.L.I.V.
                    if (predatee == GameManager.Instance.Player)
                    {
                        break;
                    }

                    // Switch to A.U.L.I.V. if within prey
                    if (potentialSwitch == GameManager.Instance.Player)
                    {
                        predatee = potentialSwitch;
                        break;
                    }
                }

                // Skip if potential switch is smaller in size or the same fish as already being hunted
                if (potentialSwitch == predatee || potentialSwitch.Size < predatee.Size)
                {
                    continue;
                }

                if (this.Size >= SIZE.LARGE && this.Size != SIZE.GOD)
                {
                    // Skip small fish that aren't in a big enough flock
                    SmallBoidsFish potentialSmall = potentialSwitch as SmallBoidsFish;
                    SmallBoidsFish predateeSmall  = predatee as SmallBoidsFish;
                    if ((predateeSmall != null && potentialSmall != null) && (potentialSmall.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                    {
                        continue;
                    }
                }

                float sqrDistToCurrent   = (this.transform.position - predatee.transform.position).sqrMagnitude;
                float sqrDistToPotential = (this.transform.position - potentialSwitch.transform.position).sqrMagnitude;
                if (sqrDistToPotential < sqrDistToCurrent)
                {
                    predatee = potentialSwitch;
                }
            }

            this.PhysicalTarget = predatee;
        }
        else
        {
            float     closestSqrDist = float.PositiveInfinity;
            BoidsFish closestFish    = null;
            foreach (BoidsFish fish in this.Predatees)
            {
                // ignore if not visible
                if (!checkIfVisible(fish))
                {
                    continue;
                }

                if (BoidsSettings.Instance.AulivTheBestPrey)
                {
                    // Set A.U.L.I.V. as prey immediately if present
                    if (fish == GameManager.Instance.Player)
                    {
                        closestFish = fish;
                        break;
                    }
                }

                // Large fish skip small fish that aren't in a big enough flock
                if (this.Size >= SIZE.LARGE && this.Size != SIZE.GOD)
                {
                    SmallBoidsFish small = fish as SmallBoidsFish;
                    if (fish == GameManager.Instance.Player && (small != null) && (small.FlockSize < BoidsSettings.Instance.MinFlockSizeToAttractLargeFish))
                    {
                        continue;
                    }
                }

                float sqrDistToFish = (this.transform.position - fish.transform.position).sqrMagnitude;
                if (sqrDistToFish < closestSqrDist)
                {
                    closestSqrDist = sqrDistToFish;
                    closestFish    = fish;
                }
            }

            if (closestFish != null)
            {
                this.PhysicalTarget = predatee = closestFish;
                this.Hunt();
            }
            else
            {
                this.PhysicalTarget = null;
                this.Idle();
            }
        }

        // Only medium fish are scared of approaching flocks
        if (this.Size == SIZE.MEDIUM)
        {
            SmallBoidsFish smallPredatee = predatee as SmallBoidsFish;
            if (smallPredatee != null)
            {
                if (smallPredatee.FlockSize > BoidsSettings.Instance.MinFlockSizeToScareMediumFish)
                {
                    this.PhysicalTarget = predatee = null;
                    this.Idle();
                }
            }
        }

        // if (this.Size != SIZE.SMALL)
        // {
        //     if (predatee != null)
        //         this.Hunt ();
        //     else
        //     {
        //         this.Idle ();
        //     }
        // }
    }