Ejemplo n.º 1
0
 private void ClearLeaded(MagnetPattern other)
 {
     for (int i = 0; i < leaded.Count; i++)
     {
         other.leaded.Add(leaded[i]);
         leaded[i].leader = other;
     }
     //other.leaded = leaded;
     leaded.Clear();
 }
Ejemplo n.º 2
0
    public void SpawnChromosome(Vector3 position)
    {
        GameObject    chromosome = (GameObject)GameObject.Instantiate(Chromosome, position, Quaternion.identity);
        MagnetPattern magnet     = chromosome.GetComponent <MagnetPattern>();

        magnet.id = nbChromosomes++;
        magnet.otherChromosomes = chromosomes;
        magnet.speed            = Random.Range(2, 4);
        magnet.leadCapacity     = Random.Range(5, 20);
        magnet.player           = player;

        chromosomes.Add(magnet);
    }
Ejemplo n.º 3
0
 public bool isInOurGroup(MagnetPattern other)
 {
     if (other.id == id)
     {
         return(true);
     }
     for (int i = 0; i < leaded.Count; i++)
     {
         if (leaded[i].id == other.id)
         {
             return(true);
         }
     }
     return(false);
 }
Ejemplo n.º 4
0
    IEnumerator CheckChromosomes()
    {
        for (int i = 0; i < chromosomes.Count; i++)
        {
            MagnetPattern chromosome = chromosomes[i];
            if (chromosome.isAttached || chromosome.isFull)
            {
                chromosomes.RemoveAt(i);
                i--;
            }
        }
        yield return(new WaitForSeconds(1f));

        StartCoroutine("CheckChromosomes");
    }
Ejemplo n.º 5
0
    public void reachingOther(GameObject other, Detector detector)
    {
        MagnetPattern otherMagnet = other.gameObject.GetComponent <MagnetPattern>();

        if (!isAttached)
        {
            if (!otherMagnet.isAttached &&
                (leadCapacity < otherMagnet.leadCapacity ||
                 (otherMagnet.isLeading && leadCapacity == otherMagnet.leadCapacity)))
            {
                JoiningPattern join = gameObject.GetComponent <JoiningPattern>();
                join.enabled = true;
                if (otherMagnet.leaded.Count > 0)
                {
                    int           count      = otherMagnet.leaded.Count;
                    MagnetPattern lastLeaded = otherMagnet.leaded[count - (Random.Range(1, 1))];
                    if (lastLeaded)
                    {
                        join.MakeJoin(anchors, lastLeaded.anchors, lastLeaded.gameObject.rigidbody2D, lastLeaded.transform);
                    }
                }
                else
                {
                    join.MakeJoin(anchors, otherMagnet.anchors, other.gameObject.rigidbody2D, other.transform);
                }
                isLeading = false;
                leader    = otherMagnet;
                //detector.enabled = false;
                StartCoroutine("Attach");
            }
            else if (!otherMagnet.isAttached)
            {
                isLeading  = true;
                isAttached = false;
            }
        }
        else
        {
//			if(!leader.isInOurGroup(otherMagnet)){
//				//leader.reachingOther(other, detector);
//			}
        }
    }
Ejemplo n.º 6
0
    IEnumerator FindTarget()
    {
        float distance = 0;

        foreach (MagnetPattern chromosome in otherChromosomes)
        {
            if (chromosome)
            {
                float chromosomeDistance = Vector3.Distance(transform.position, chromosome.gameObject.transform.position);
                if (chromosome.id != id && (distance == 0 || distance > chromosomeDistance) && !chromosome.isFull)
                {
                    distance         = chromosomeDistance;
                    targetChromosome = chromosome;
                    continue;
                }
            }
        }
        yield return(new WaitForSeconds(cooldown));

        StartCoroutine("FindTarget");
    }
Ejemplo n.º 7
0
 public void newChromosome(MagnetPattern chromosome)
 {
     otherChromosomes.Add(chromosome);
 }
Ejemplo n.º 8
0
 // Use this for initialization
 void Start()
 {
     camera = GameObject.FindGameObjectWithTag("TrueMainCamera");
     magnet = gameObject.GetComponent <MagnetPattern>();
 }