Exemplo n.º 1
0
        private void buildBehaviorTree()
        {
            //Initialize pathfinding
            _origin    = (entity.position / Game1.TILE_SIZE).ToPoint();
            _waypoints = _grid.search(new Point(_origin.X, _origin.Y), new Point(_origin.X + 5, _origin.Y));

            BehaviorTreeBuilder <EnemyController> _behaviorTreeBuilder = BehaviorTreeBuilder <EnemyController> .begin(this);

            _behaviorTreeBuilder.untilSuccess();
            //Creates a method with input of EnemyController and output of TaskStatus
            Func <EnemyController, TaskStatus> chasePlayer = delegate(EnemyController context) {
                if (target == null)
                {
                    return(TaskStatus.Failure);
                }

                Point currentNode = (entity.position / Game1.TILE_SIZE).ToPoint();
                Point targetNode  = (target.position / Game1.TILE_SIZE).ToPoint();

                _waypoints            = _grid.search(currentNode, targetNode);
                _currentWaypointIndex = 0;

                //Check to see if path exists
                if (_waypoints == null)
                {
                    return(TaskStatus.Failure);
                }

                return(TaskStatus.Running);
            };


            _behaviorTreeBuilder.action(chasePlayer);

            _behaviorTree = _behaviorTreeBuilder.build();
        }