public Tilemap(Game game) { this.game = game; width = 16; height = 12; scale = 3; tiles = new Tile[width, height]; for (var y = 0; y < height; y++) { for (var x = 0; x < width; x++) { if (x == 0 || x == width - 1 || y == 0 || y == height - 1) tiles[x,y] = new Tile(game, new Vector2i(x, y), scale, 1, true); else tiles[x, y] = new Tile(game, new Vector2i(x, y), scale, 0); } } startTile = tiles[1, 1]; endTile = tiles[14, 10]; UpdatePath(); game.CenterGameView(new Vector2f((width * 16 * 3) / 2f, (height * 16 * 3) / 2f)); }
float ManhattanHeuristic(Tile from, Tile target) => Math.Abs(target.Position.X - from.Position.X) + Math.Abs(target.Position.Y - from.Position.Y);
float MovementWeight(Tile from, Tile to) { if (((from.MapPos.X < to.MapPos.X || from.MapPos.X > to.MapPos.X) && from.MapPos.Y == to.MapPos.Y) || (from.MapPos.X == to.MapPos.X && (from.MapPos.Y < to.MapPos.Y || from.MapPos.Y > to.MapPos.Y))) return 10f; return 14f; }
float DistanceHeuristic(Tile from, Tile target) => from.Position.Distance(target.Position);