Пример #1
0
        private Point?GetTarget()
        {
            // Prioritise food over actually reaching the goal! :D
            var food = this.GetNearbyObjects(Constants.Food);

            if (food.Any())
            {
                var closestFood = this.GetClosest(food);
                return(new Point
                {
                    X = closestFood.X,
                    Y = closestFood.Y
                });
            }

            var destination = Critter.GetDestination();

            if (destination.X == 0 && destination.Y == 0)
            {
                return(null);
            }

            if (!Critter.IsTerrainBlockingRouteTo(destination.X, destination.Y))
            {
                return(new Point
                {
                    X = destination.X,
                    Y = destination.Y
                });
            }

            return(null);
        }
Пример #2
0
        //finds coords of the exit point
        private void FindLevelExit()
        {
            Rectangle destination = Critter.GetDestination();

            centreDestinationX = destination.X + destination.Width / 2;
            centreDestinationY = destination.Y + destination.Height / 2;
        }
        public override void Think()
        {
            Rectangle destination        = Critter.GetDestination();
            int       centreDestinationX = destination.X + destination.Width / 2;
            int       centreDestinationY = destination.Y + destination.Height / 2;

            if (!Critter.IsTerrainBlockingRouteTo(centreDestinationX, centreDestinationY))
            {
                int direction = Critter.GetDirectionTo(centreDestinationX, centreDestinationY);
                Critter.Direction = direction;
                Critter.Speed     = nominalSpeed;
            }
        }