bool CibleEnVue(out Vector3 result)
    {
        if (preyList.Length != 0) // test seulement dans le cas ou le Poule est seule (test unitaire)

        {
            List <GameObject> preyVisibleList = new List <GameObject>();
            result   = Vector3.zero;
            enChasse = false;
            for (int i = 0; i < preyList.Length; i++)
            {
                GameObject prey = preyList[i];
                MoveVipere controlTouchedPrey = prey.GetComponent <MoveVipere>();
                preyTouched = controlTouchedPrey.touched; // access this particular touched variable
                // on teste si la prey est a distance de vue  ..................................  et    dans le champ de vision  ...........................................................................    et    s'il n'y a pas une proie plus proche
                if (((prey.transform.position - agent.transform.position).magnitude < sightRange) && (Vector3.Angle(prey.transform.position - agent.transform.position, agent.transform.forward) < sightAngle) && (preyTouched == false))
                {
                    enChasse = true;
                    preyVisibleList.Add(prey);
                }
            }
            Transform tempResult = getClosest(preyVisibleList);
            result = tempResult.position;
            return(enChasse);
        }
        else
        {
            result   = new Vector3(0.0f, 0.0f, 0.0f);
            enChasse = false;
            return(enChasse);
        }
    }
 void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.tag == tagPrey)
     {
         //agent.SetDestination(new Vector3(0,0,0));
         // Destroy(collision.gameObject);
         MoveVipere controlCollisionPrey = collision.gameObject.GetComponent <MoveVipere>();
         if (controlCollisionPrey.touched == false)
         {
             controlCollisionPrey.touched            = true; // access this particular touched variable
             collision.gameObject.transform.position = homePoule;
         }
         else
         {
             // print(gameObject.name + " : Get out of my way !!") ;
         }
     }
     else if (collision.gameObject.tag == tagFriend)
     {
         MovePoule controlCollisiontFriend = collision.gameObject.GetComponent <MovePoule>();
         if (controlCollisiontFriend.touched == true && touched == false)
         {
             controlCollisiontFriend.touched = false;
         }
         else
         {
             // print("Pardon copain");
         }
     }
 }
Exemple #3
0
 bool endOfGame()
 {
     for (int j = 0; j < preyList.Length; j++)
     {
         prey = preyList[j];
         MovePoule controlTouchedPrey = prey.GetComponent <MovePoule>();
         preyTouched = controlTouchedPrey.touched;
         if (preyTouched)
         {
             for (int k = 0; k < predatorList.Length; k++)
             {
                 predator = predatorList[k];
                 MoveVipere controlTouchedPredator = predator.GetComponent <MoveVipere>();
                 predatorTouched = controlTouchedPredator.touched;
                 if (predatorTouched == false)
                 {
                     return(false);
                 }
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
    bool getPlusProcheAmiArrete(out Vector3 result)
    {

      if(friendList.Length > 1){  // test seulement dans le cas ou la poule est seule (test unitaire)

        List<GameObject> friendArreteList = new List<GameObject>();
        amiArrete = false ;
        result = Vector3.zero;
        foreach(GameObject friend in friendListMinusMe)
        {
              MoveVipere controlAlterArrete = friend.GetComponent<MoveVipere>();
              bool friendTouched = controlAlterArrete.touched; // access this particular touched variable
              // on teste si la prey est a distance de vue  ..................................  et    dans le champ de vision  ...........................................................................    et    s'il n'y a pas une proie plus proche
              if ( friendTouched == true )
                {
                  friendArreteList.Add(friend) ;
                  amiArrete = true ;
                }
          }
          Transform tempResult = getClosest(friendArreteList);
          result = tempResult.position ;
          return amiArrete ;
      }
      else
      {
        result = new Vector3 (0.0f,0.0f,0.0f) ;
        amiArrete = false ;
        return amiArrete ;}
    }
    bool amiArreteEnVue(out Vector3 cible)
    {
      if(friendListMinusMe.Count != 0)
      {  // test seulement dans le cas ou le renard est seule (test unitaire)

        List<GameObject> friendArrestedVisibleList = new List<GameObject>();
        cible = Vector3.zero;
        unCamaradeALiberer = false ;
        foreach(GameObject camarade in friendListMinusMe)
          {
              MoveVipere controlFriendArrested = camarade.GetComponent<MoveVipere>();
              bool friendArrested = controlFriendArrested.touched; // access this particular touched variable
              // on teste si la prey est a distance de vue  ..................................  et    dans le champ de vision  ...........................................................................    et    s'il n'y a pas une proie plus proche
              if ( ((camarade.transform.position - agent.transform.position).magnitude < sightRange) && (Vector3.Angle(camarade.transform.position - agent.transform.position, agent.transform.forward) < sightAngle) && ( friendArrested == true ) )
                {
                  unCamaradeALiberer = true ;
                  friendArrestedVisibleList.Add(camarade) ;
                 }
          }
          Transform tempResult = getClosest(friendArrestedVisibleList);
          cible = tempResult.position ;
          return unCamaradeALiberer;
      }
      else
      {
        cible = new Vector3 (0.0f,0.0f,0.0f);
        unCamaradeALiberer = false ;
        return unCamaradeALiberer;
      }
    }
 bool endOfGame()
 {
     for (int j = 0; j < preyList.Length; j++)
     {
         prey = preyList[j];
         MoveVipere controlTouchedPrey = prey.GetComponent <MoveVipere>();
         preyTouched = controlTouchedPrey.touched;
         if (preyTouched == false)
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #7
0
 bool prisPourCible(out Vector3 result)
 {
     for (int i = 0; i < predatorList.Length; i++)
     {
         GameObject predator = predatorList[i];
         MoveVipere controlPredatorTouched = predator.GetComponent <MoveVipere>();
         predatorTouched = controlPredatorTouched.touched; // access this particular touched variable
         if (((predator.transform.position - agent.transform.position).magnitude < sightRange) && (predatorTouched == false))
         {
             Vector3 cibleDir = predator.transform.position - agent.transform.position;
             if (Vector3.Angle(cibleDir, agent.transform.forward) < sightAngle)
             {
                 result       = predator.transform.position;
                 prisEnChasse = true;
                 return(true);
             }
         }
     }
     result = Vector3.zero;
     return(false);
 }