public static SwinGameSDK.Vector[,] CalculateForces(Point2D current, Tile[,] toTraverse, Point2D destination) { int playerX = (int)Math.Floor(current.X / 60); int playerY = (int)Math.Floor(current.Y / 60); int destX = (int)Math.Floor(destination.X / 60); int destY = (int)Math.Floor(destination.Y / 60); PathfinderTile[,] tiles = new PathfinderTile[Game.x_width, Game.y_height]; for (int i = 0; i < Game.x_width; i++) { for (int j = 0; j < Game.y_height; j++) { tiles[i, j] = new PathfinderTile(); } } if (playerX < 0 || playerX > Game.x_width - 1 || playerY < 0 || playerY > Game.y_height - 1) { return(new Vector[Game.x_width, Game.y_height]); } if (destX < 0 || destX > Game.x_width - 1 || destY < 0 || destY > Game.y_height - 1) { return(new Vector[Game.x_width, Game.y_height]); } ScanTiles(playerX, playerY, toTraverse, tiles, destX, destY); List <PathfinderTile> waypoints = new List <PathfinderTile>(); AssignWaypoints(tiles, destX, destY, waypoints, toTraverse); AssignForces(tiles, destX, destY, waypoints); SwinGameSDK.Vector[,] forceVectors = new Vector[Game.x_width, Game.y_height]; for (int i = 0; i < Game.x_width; i++) { for (int j = 0; j < Game.y_height; j++) { forceVectors[i, j] = tiles[i, j].Direction; } } return(forceVectors); }
public static int GetCost(Point2D current, Tile[,] toTraverse, Point2D destination) { int playerX = (int)Math.Floor(current.X / 60); int playerY = (int)Math.Floor(current.Y / 60); int destX = (int)Math.Floor(destination.X / 60); int destY = (int)Math.Floor(destination.Y / 60); PathfinderTile[,] tiles = new PathfinderTile[Game.x_width, Game.y_height]; for (int i = 0; i < Game.x_width; i++) { for (int j = 0; j < Game.y_height; j++) { tiles[i, j] = new PathfinderTile(); } } ScanTiles(playerX, playerY, toTraverse, tiles, destX, destY); return(tiles[destX, destY].Value); }