コード例 #1
0
ファイル: VirtualMachine.cs プロジェクト: HTCGS/Evolution
    public static int FeedOn(Creature creature)
    {
        int foodType = GetFoodType(creature.DNA);

        if (foodType == 0)
        {
            creature.Energy += Env.GetSunEnergy(creature.transform.position);
        }
        else if (foodType == 1)
        {
            creature.Energy += Env.GetMineralEnergy(creature.transform.position);
        }
        else if (foodType == 2)
        {
            RaycastHit raycastHit = RayCast(creature.gameObject);
            if (raycastHit.transform != null)
            {
                if (raycastHit.transform.parent.gameObject.tag == "Microorganism")
                {
                    EvolutionEngine.GiveBackObject(raycastHit.transform.parent.gameObject);
                    Move(creature.gameObject, true);
                    creature.Energy += 8;
                }
            }
        }
        return(0);
    }
コード例 #2
0
    void Update()
    {
        time += Time.deltaTime;

        //if (time >= 0.1)
        {
            VirtualMachine.Step(this);
            if (DNA.GenePos >= DNA.Genes.Count)
            {
                DNA.GenePos = 0;
            }
            Energy--;
            if (Energy <= 0)
            {
                EvolutionEngine.GiveBackObject(gameObject);
            }
            LifeTime++;
            if (LifeTime >= MaxLifeTime)
            {
                DNA.GenePos = 0;
                Statistics.AddOldestDNA(this);
                EvolutionEngine.GiveBackObject(gameObject);
            }
            if (Energy >= MaxEnergy)
            {
                Division();
            }
            time = 0;
        }

        //Test();
    }