public bool CheckLOS(Point A, Point B) { Vector2 a = HexMap.ToScreenLocation(A); Vector2 b = HexMap.ToScreenLocation(B); Vector2 broadened; Vector2 dir = Vector2.Normalize(b - a); Vector2 perpDir = new Vector2(dir.Y, -dir.X); int clearance = (int)(HexMap.TileHalfWidth * 0.4f); // the width of the ray a += (HexMap.TileHalfHeight + 6) * dir; //start raycasting at the tile border + some int targetDist = (int)Vector2.Distance(b, a); for (int i = 0; i < targetDist; i++) { broadened = i % 2 == 1 ? a + clearance * perpDir : a - clearance * perpDir; // check collision at clearance distance perpendicular to the ray (+odd, -even) Point coord = HexMap.ToMapCoordinate(broadened); if (coord.X >= 0 && coord.Y >= 0 && coord.X < HexMap.Layout.GetLength(1) && coord.Y < HexMap.Layout.GetLength(0)) { char tileChar = HexMap.Layout[coord.Y, coord.X]; if (tileChar != '.' && tileChar != '\'' && !(tileChar >= 'a' && tileChar <= 'i') && !(tileChar >= '1' && tileChar <= '9')) { return(false); } else { a += dir; } } else { return(false); } } return(true); }
//---------------------------Methods---------------------------------------- public void FindPath() { Point currentTile = ParentMap.ToMapCoordinate(Location); if (ParentMap.GoalPoints.Length > 0 && GoalPointIndex < ParentMap.GoalPoints.Length) { //ParentMap.Pathfinder.InitializeTiles(); Path = ParentMap.Pathfinder.FindPath(currentTile, ParentMap.GoalPoints[GoalPointIndex]); OrigPath.Clear(); OrigPath.AddRange(Path); if (Path.Count > 1) { nextWaypoint = 1; } else { nextWaypoint = 0; } } }