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); }
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); } }
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)) ); }
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; }
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; }