Beispiel #1
0
        private void OnDrawGizmosSelected()
        {
            if (Application.isPlaying)
            {
                var surroundings = Environments.Environment.Sense(coord);
                Gizmos.color = Color.white;
                if (surroundings.nearestFoodSource != null)
                {
                    Gizmos.DrawLine(transform.position, surroundings.nearestFoodSource.transform.position);
                }
                if (surroundings.nearestWaterTile != Coord.Invalid)
                {
                    Gizmos.DrawLine(
                        transform.position,
                        Environments.Environment.tileCentres[surroundings.nearestWaterTile.x,
                                                             surroundings.nearestWaterTile.y]
                        );
                }

                if (currentAction == CreatureAction.GoingToFood)
                {
                    var next = EnvironmentUtility.GetNextInPath(coord.x, coord.y, foodTarget.coord.x,
                                                                foodTarget.coord.y);
                    var path = EnvironmentUtility.GetPath(coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y);
                    Gizmos.color = Color.black;
                    for (var i = 0; i < path.Length; i++)
                    {
                        Gizmos.DrawSphere(Environments.Environment.tileCentres[path[i].x, path[i].y], .2f);
                    }
                    Gizmos.color = Color.red;
                    Gizmos.DrawSphere(Environments.Environment.tileCentres[next.x, next.y] + Vector3.up * .1f, .25f);
                }
            }
        }
Beispiel #2
0
    protected virtual void ChooseNextAction()
    {
        Surroundings surroundings = Environment.Sense(coord);

        if (surroundings.nearestFoodSource != null)
        {
            currentAction = CreatureAction.GoingToFood;
            foodTarget    = surroundings.nearestFoodSource;
        }

        // If exploring, move to random tile
        if (currentAction == CreatureAction.Exploring)
        {
            StartMoveToCoord(Environment.GetNextTileWeighted(coord, moveFromCoord));
        }
        else if (currentAction == CreatureAction.GoingToFood)
        {
            if (Coord.AreNeighbours(coord, foodTarget.coord))
            {
                currentAction = CreatureAction.Eating;
            }
            else
            {
                StartMoveToCoord(EnvironmentUtility.GetNextInPath(coord.x, coord.y, foodTarget.coord.x, foodTarget.coord.y));
            }
        }
    }