- Timestamp:
- 2015-06-09 21:12:52 (8 years ago)
- Location:
- 2015/24/ohjaajat/Dungeon/Dungeon/Dungeon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
2015/24/ohjaajat/Dungeon/Dungeon/Dungeon/Dungeon.cs
r5968 r5969 164 164 Keyboard.Listen(Key.F1, ButtonState.Pressed, Begin, null); 165 165 166 // Testi haku huoneesta (0, 0) -> (5, 5).167 Keyboard.Listen(Key.F2, ButtonState.Pressed, delegate168 {169 FindPath(new Point(0, 0), new Point(5, 5));170 }, null);171 172 166 Keyboard.Listen(Key.Space, ButtonState.Pressed, SeuraavaAalto, "Anna kivan barbaariaallon tulla"); 173 167 } … … 292 286 digArrowHead.Angle = suunta.Angle - Angle.FromDegrees(90); 293 287 } 288 294 289 base.Update(time); 295 290 } 296 291 292 protected override void Paint(Canvas canvas) 293 { 294 canvas.BrushColor = Color.Purple; 295 296 var points = FindPath(new Point(6, 0), MuunnaJypelista(Mouse.PositionOnWorld)); 297 for (int i = 0; i < points.Count - 1; i++) 298 { 299 Vector v = new Vector(points[i].X - huoneet.GetLength(0) / 2, points[i].Y - huoneet.GetLength(1) / 2) * RUUDUN_KOKO; 300 Vector v2 = new Vector(points[i+1].X - huoneet.GetLength(0) / 2, points[i+1].Y - huoneet.GetLength(1) / 2) * RUUDUN_KOKO; 301 canvas.DrawLine(v, v2); 302 } 303 304 base.Paint(canvas); 305 } 306 297 307 #region Reitinlöytö 298 308 299 void FindPath(Point alku, Point loppu) 300 { 309 List<Point> FindPath(Point alku, Point loppu) 310 { 311 if (GetRoom(alku) == null || GetRoom(loppu) == null) 312 return new List<Point>(); 313 301 314 bool[,] walkable = new bool[huoneet.GetLength(0), huoneet.GetLength(1)]; 302 315 foreach (var paikka in RuutujenPaikat()) … … 304 317 walkable[paikka.X, paikka.Y] = huoneet[paikka.X, paikka.Y].Dug; 305 318 } 306 var finder = new AStar.PathFinder(new AStar.SearchParameters(alku, loppu, walkable)); 307 List<Point> path = finder.FindPath(); 308 // Ei ota huomioon ovia :( 319 var finder = new AStar.PathFinder(new AStar.SearchParameters(alku, loppu, walkable), OviTarkistus); 320 return finder.FindPath(); 321 } 322 323 bool OviTarkistus(Point a, Point b) 324 { 325 Room ra = GetRoom(a); 326 Room rb = GetRoom(b); 327 Direction suunta = (new Vector(b.X, b.Y) - new Vector(a.X, a.Y)).Angle.MainDirection; 328 if (ra != null && rb != null) 329 { 330 return ra.Walls[suunta].Image == reikaSeinaKuva && rb.Walls[Direction.Inverse(suunta)].Image == reikaSeinaKuva; 331 } 332 return false; 309 333 } 310 334 -
2015/24/ohjaajat/Dungeon/Dungeon/Dungeon/Pathfinding/PathFinder.cs
r5967 r5969 16 16 private Node endNode; 17 17 private SearchParameters searchParameters; 18 private Func<Point, Point, bool> extraCheck; 18 19 19 20 /// <summary> … … 21 22 /// </summary> 22 23 /// <param name="searchParameters"></param> 23 public PathFinder(SearchParameters searchParameters )24 public PathFinder(SearchParameters searchParameters, Func<Point, Point, bool> extraCheck) 24 25 { 26 this.extraCheck = extraCheck; 25 27 this.searchParameters = searchParameters; 26 28 InitializeNodes(searchParameters.Map); … … 134 136 continue; 135 137 138 if (!extraCheck(fromNode.Location, location)) 139 continue; 140 136 141 // Already-open nodes are only added to the list if their G-value is lower going via this route. 137 142 if (node.State == NodeState.Open) … … 166 171 return new Point[] 167 172 { 168 new Point(fromLocation.X-1, fromLocation.Y-1),173 //new Point(fromLocation.X-1, fromLocation.Y-1), 169 174 new Point(fromLocation.X-1, fromLocation.Y ), 170 new Point(fromLocation.X-1, fromLocation.Y+1),175 //new Point(fromLocation.X-1, fromLocation.Y+1), 171 176 new Point(fromLocation.X, fromLocation.Y+1), 172 new Point(fromLocation.X+1, fromLocation.Y+1),177 //new Point(fromLocation.X+1, fromLocation.Y+1), 173 178 new Point(fromLocation.X+1, fromLocation.Y ), 174 new Point(fromLocation.X+1, fromLocation.Y-1),179 //new Point(fromLocation.X+1, fromLocation.Y-1), 175 180 new Point(fromLocation.X, fromLocation.Y-1) 176 181 };
Note: See TracChangeset
for help on using the changeset viewer.