コード例 #1
0
 private void PathfindingSetup()
 {
     SpawnLocation      = transform.position;
     PlayerSpawn        = TileMap.getObjectGroup("objects").objectWithName("spawn");
     Start              = new Point((int)SpawnLocation.X, (int)SpawnLocation.Y);
     End                = new Point(PlayerSpawn.x, PlayerSpawn.y);
     WeightedSearchPath = WeightedGraph.search(Start, End);
     SetState(EnemyState.Following);
 }
コード例 #2
0
ファイル: Pathfinder.cs プロジェクト: Zertuk/monogamefun
        void IUpdatable.update()
        {
            // on left click set our path end time
            if (Input.leftMouseButtonPressed)
            {
                _end = _tilemap.worldToTilePosition(Input.mousePosition);
            }

            // on right click set our path start time
            if (Input.rightMouseButtonPressed)
            {
                _start = _tilemap.worldToTilePosition(Input.mousePosition);
            }

            // regenerate the path on either click
            if (Input.leftMouseButtonPressed || Input.rightMouseButtonPressed)
            {
                // time both path generations
                var first = Debug.timeAction(() =>
                {
                    _breadthSearchPath = _gridGraph.search(_start, _end);
                });

                var second = Debug.timeAction(() =>
                {
                    _astarSearchPath = _astarGraph.search(_start, _end);
                });

                // debug draw the times
                Debug.drawText("Breadth First: {0}\nAstar: {1}", first, second);
            }
        }
コード例 #3
0
 protected void SetPath()
 {
     Path = graph.search(
         new Point((int)Math.Floor(entity.position.X / 8), (int)Math.Floor((entity.position.Y + 8) / 8)),
         new Point((int)Math.Floor(Player.position.X / 8), (int)Math.Floor((Player.position.Y + 8) / 8))
         );
 }
コード例 #4
0
ファイル: Punk.cs プロジェクト: coryfinnegan/EyesHaveIt
 public Punk(String inEntityType, int inTotalLife, Nez.Tiled.TiledMap inMap, bool enemyHasGun, int ntargetPositionRange) : base(inEntityType, inTotalLife, inMap, enemyHasGun, ntargetPositionRange)
 {
     EntityType          = inEntityType;
     TileMap             = inMap;
     TotalLife           = inTotalLife;
     CurrentLife         = TotalLife;
     CollisionLayer      = TileMap.getLayer <TiledTileLayer>("collisionLayer");
     WeightedGraph       = new WeightedGridGraph(CollisionLayer);
     Start               = new Point(1, 1);
     End                 = new Point(10, 10);
     WeightedSearchPath  = WeightedGraph.search(Start, End);
     EnemyCanShootGun    = enemyHasGun;
     TargetPositionRange = ntargetPositionRange;
 }
コード例 #5
0
ファイル: Pathfinder.cs プロジェクト: Zertuk/monogamefun
        public Pathfinder(TiledMap tilemap)
        {
            _tilemap = tilemap;
            var layer = tilemap.getLayer <TiledTileLayer>("main");

            _start = new Point(1, 1);
            _end   = new Point(10, 10);

            _gridGraph         = new UnweightedGridGraph(layer);
            _breadthSearchPath = _gridGraph.search(_start, _end);

            _astarGraph      = new WeightedGridGraph(layer);
            _astarSearchPath = _astarGraph.search(_start, _end);

            Debug.drawTextFromBottom = true;
        }