void loadGeneration()
    {
        GameObject [] creatures = GameObject.FindGameObjectsWithTag("Creature");
        GameObject [] food      = GameObject.FindGameObjectsWithTag("Food");

        for (int c = 0; c < creatures.Length; c++)
        {
            Destroy(creatures[c]);
        }
        for (int f = 0; f < food.Length; f++)
        {
            Destroy(food[f]);
        }

        creatureList.Clear();

        for (int i = 0; i < ga.Population.Count; i++)
        {
            GameObject        newCreature = Instantiate(creaturePrefab, new Vector3(Random.Range(-40f, 40f), 1f, Random.Range(-40f, 40f)), Quaternion.identity);
            CreatureBehaviour cb          = newCreature.GetComponent <CreatureBehaviour>();
            cb.LoadDNA(ga.Population[i], i);
            creatureList.Add(cb);
        }

        for (int n = 0; n < amountOfFood; n++)
        {
            Instantiate(foodPrefab, new Vector3(Random.Range(-49f, 49f), 0.5f, Random.Range(-49f, 49f)), Quaternion.identity);
        }
    }
Esempio n. 2
0
    // Use this for initialization
    void Start()
    {
        float creatureWidth = creaturePrefab.GetComponent <Renderer>().bounds.size.x;

        int nb = 0;

        for (float d = emptySpaceDiameter; d < (domeDiameter / 2f); d += creatureWidth * (1 + spaceBetweenCreatures))
        {
            // spawn as many creatures as possible as long as there's only 1 per 'trajectory' in the dome
            GameObject myCreature = Instantiate(creaturePrefab, Vector3.zero, Quaternion.identity) as GameObject;
            // set parent
            myCreature.transform.parent = this.transform;
            // set position
            //myCreature.transform.localPosition =
            CreatureBehaviour creatureBehaviour = myCreature.GetComponent <CreatureBehaviour>();
            creatureBehaviour.distFromCenter = d;
            //print ("Instantiated: "+d);

            // set unique number
            creatureBehaviour.uniqueNb = nb;

            nb++;
        }

        // add empty object for tail parts (less messy)
        GameObject creatureTailParent = new GameObject("creatureTailParent");

        creatureTailParent.transform.position = this.transform.position;
    }
 private void InvokeAttackZoneEntered(CreatureBehaviour creature)
 {
     var handler = AttackZoneEntered;
     if (handler == null) {
             return;
     }
     var e = new BehaviourEventArgs<CreatureBehaviour>(creature);
     AttackZoneEntered(this, e);
 }
Esempio n. 4
0
    public void CopyStateFrom(CreatureBehaviour other)
    {
        if (!other || this == other)
        {
            return;
        }

        m_fallTime   = other.m_fallTime;
        m_motionTime = other.m_motionTime;
        m_lastShake  = other.m_lastShake;
        m_shakeIdx   = other.m_shakeIdx;
        m_shake      = other.m_shake;

        m_knockbackDistance = other.m_knockbackDistance;
    }
Esempio n. 5
0
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (enabled)
        {
            if (collision.gameObject.tag == "Player")
            {
                float distance     = Vector2.Distance(collision.transform.position, transform.position);
                float currentForce = forceOverDistance.Evaluate(1f - (distance / (boxCollider.size.x / 2f)));

                PlayerController player = SceneManager.main.player;
                currentForce *= force;

                if (player.velocity.y <= 0f)
                {
                    currentForce *= player.riseTime / player.fallTime;
                }

                SceneManager.main.player.velocity += (Vector2)transform.right * currentForce;
            }
            if (collision.gameObject.tag == "Creature")
            {
                float distance     = Vector2.Distance(collision.transform.position, transform.position);
                float currentForce = forceOverDistance.Evaluate(1f - (distance / (boxCollider.size.x / 2f)));

                CreatureBehaviour creature = SceneManager.main.creature;
                currentForce *= force;

                if (creature.velocity.y <= 0f)
                {
                    currentForce += 10f;
                }

                SceneManager.main.creature.velocity += (Vector3)transform.right * currentForce;
            }
        }
    }
Esempio n. 6
0
 public RetreatEffect(CreatureBehaviour e)
     : base()
 {
     creature = e;
     Duration = new TimeSpan(0, 0, 10);
 }
Esempio n. 7
0
 public PointsEffect(float pointValue, CreatureBehaviour creature)
     : base()
 {
     PointChange = pointValue;
     Creature = creature;
 }
Esempio n. 8
0
 private void OnEnable()
 {
     creature = (CreatureBehaviour)target;
 }