public List <MapCell> JPSPlus(MapCell cell1, MapCell cell2) { List <MapCell> path = new List <MapCell>(); List <GridPos> lpath = new List <GridPos>(); if (cell1.MapId != cell2.MapId) { return(path); } JumpPointParameters.Reset(new GridPos(cell1.X, cell1.Y), new GridPos(cell2.X, cell2.Y)); List <GridPos> resultPathList = JumpPointFinder.FindPath(JumpPointParameters); lpath = JumpPointFinder.GetFullPath(resultPathList); Debug.WriteLine($"From X: {cell1.X} Y: {cell1.Y}, To X: {cell2.X} Y: {cell2.Y}, Paths: {resultPathList.Count}, LPath: {lpath.Count}"); if (lpath.Count > 0) { foreach (GridPos item in lpath) { path.Add(new MapCell { X = Convert.ToInt16(item.x), Y = Convert.ToInt16(item.y), MapId = cell1.MapId }); } } return(path); }
public static List <GridPos> JPSPlus(JumpPointParam JumpPointParameters, GridPos cell1, GridPos cell2) { if (JumpPointParameters != null) { JumpPointParameters.Reset(cell1, cell2); return(JumpPointFinder.GetFullPath(JumpPointFinder.FindPath(JumpPointParameters))); } return(new List <GridPos>()); }
public List <GridPos> JPSPlus(GridPos cell1, GridPos cell2) { List <GridPos> lpath = new List <GridPos>(); JumpPointParameters.Reset(cell1, cell2); List <GridPos> resultPathList = JumpPointFinder.FindPath(JumpPointParameters); lpath = JumpPointFinder.GetFullPath(resultPathList); Debug.WriteLine($"From X: {cell1.x} Y: {cell1.y}, To X: {cell2.x} Y: {cell2.y}, Paths: {resultPathList.Count}, LPath: {lpath.Count}"); return(lpath); }
public List <GridPos> JPSPlus(JumpPointParam JumpPointParameters, GridPos cell1, GridPos cell2) { List <GridPos> lpath = new List <GridPos>(); if (JumpPointParameters != null) { JumpPointParameters.Reset(cell1, cell2); List <GridPos> resultPathList = JumpPointFinder.FindPath(JumpPointParameters); lpath = JumpPointFinder.GetFullPath(resultPathList); } return(lpath); }
public static List <GridPos> GetPath(Point2D start, Point2D end) { BaseGrid searchGrid = new StaticGrid(gridSize, gridSize, MovableMatrix); var startGridPos = GetGridPosByPoint2d(start, gridStep); var endGridPos = GetGridPosByPoint2d(end, gridStep); JumpPointParam jpParam = new JumpPointParam(searchGrid, startGridPos, endGridPos); var result = JumpPointFinder.FindPath(jpParam); result = JumpPointFinder.GetFullPath(result); DrawPath(result, gridStep); return(result); }
private void monsterUpdate(object sender, MonsterUpdateEventArgs e) { PlayerSeen = canSeePlayer(e.engine.map.mGrid, e.playerPos); if (moves.Count == 0) { if (PlayerSeen) { JumpPointParam jParam = new JumpPointParam(e.engine.searchgrid, false, false); jParam.Reset(new GridPos(pos.X, pos.Y), new GridPos(e.playerPos.X, e.playerPos.Y)); List <GridPos> resultPathList = JumpPointFinder.FindPath(jParam); resultPathList = JumpPointFinder.GetFullPath(resultPathList); if (moves.Count != 0) { moves.Clear(); } for (int i = 0; i < resultPathList.Count; i++) { moves.Enqueue(new Vector2(resultPathList[i].x, resultPathList[i].y)); } } } if (moves.Count != 0) { var dxdy = e.engine.map.getDxDy(pos, moves.Dequeue()); if (!e.engine.checkEntity(pos, e.playerPos, dxdy.X, dxdy.Y)) { move(dxdy.X, dxdy.Y); } } if (PlayerSeen == false) { Vector2 a = rndMoves[rnd.Next(rndMoves.Count)]; if (e.engine.map.canMove(pos, a.X, a.Y)) { move(a.X, a.Y); } } if (isPlayerNear(e.playerPos)) { attack(e.engine.player); } }