Example #1
0
    protected void Act()
    {
        switch (currentAction)
        {
        case CreatureAction.Exploring:
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
            break;

        case CreatureAction.GoingToFood:
            if (Coord.AreNeighbours(coord, foodTarget.coord))
            {
                LookAt(foodTarget.coord);
                currentAction = CreatureAction.Eating;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.GoingToWater:
            if (Coord.AreNeighbours(coord, waterTarget))
            {
                LookAt(waterTarget);
                currentAction = CreatureAction.Drinking;
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;

        case CreatureAction.SearchingForMate:
            if (Coord.AreNeighbours(coord, mateTarget.coord))
            {
                LookAt(mateTarget.coord);
                if (mateTarget && Math.Abs(mateTarget.lifespan - lifespan) < 0.1 && desire > 0 && mateTarget.desire > 0)
                {
                    desire            = 0;
                    mateTarget.desire = 0;
                    //mateTarget.canReproduce = false;
                    //canReproduce = false;

                    Animal entity = (Animal)Instantiate(prefab);
                    entity.Init(coord);
                    entity.genes = Genes.InheritedGenes(genes, mateTarget.genes);
                    Environment.speciesMaps[entity.species].Add(entity, coord);
                }
            }
            else
            {
                StartMoveToCoord(path[pathIndex]);
                pathIndex++;
            }
            break;
        }
    }