Jacob Roman
Dec 6th, 2011, 06:53 PM
You won't find code like this anywhere. I have here a very fast and easy to understand A* Pathfinding algorithm (pronounced A Star) that can easily be ported to any game you are making. It finds the fastest route from the starting point which is your predator to the ending point which is your prey. I have ran into other A* programs in VB and found them to be very ugly. Ran into one I found too dependent on values I did not wanna use and found it wasn't the proper A* structure (not to mention it was nearly impossible to port into my game), and another that was easy to understand, but locks up in certain areas on the map and was hideously slow. Sadly I used that slow and easy method on my Bosskillers game which will be corrected. I organized my code to easily break it down and have it commented. For more documentation on A* Pathdfinding, refer to this website:
A* Pathfinding for Beginners (http://www.policyalmanac.org/games/aStarTutorial.htm)
[EDIT] Massive improvements have been made and this is probably the ONLY A* Pathfinding program that actually includes the monster following the path! And you can move your player through the map. It even has collision for the walls. For optimization purposes, the A* Pathfinding only needs to be computed when the monster moves to a new map coordinate.
[EDIT] Another Improvement has been made. I noticed 2 things. One, that the path disappears once in awhile for a split second even though the predator continues to follow the path. Turns out the player needed a role as well in enabling Compute_AStar_Pathfinding. So whenever the player moves to a new map coordinate, it fires AStar. The other problem was that very very rarely it locked up. Having the player play a roll in Compute_Astar_Pathfinding fixed this as well. No more lock ups. Lockups tend to be the biggest problem with AStar samples and can cause your program to hang. I also changed the order it was in the Game_Loop. So it is now this order:
Keyboard Controls
Clear Screen
Collision
AStar Pathfinding
Follow AStar Path
Render Map
Draw AStar Path
Draw Monster
Draw Player
Lock_Framerate 60
DoEvents
Also another improvement I made is that if the monster trys to leave the map screen, itll stop at the edge. However you can leave the map screen with no problem. Itll stop computing AStar when the player is out of the map boundry and the monster continues following the path it has created for itself. AStar samples I tested had Subscript out of range errors for doing so! So my AStar seems to be the best out there so far on the web. I may port this to VB.Net as well and make other improvements such as how the monster interpolates from one tile to the other. Currently although it works, it has issues when the next path for it to follow is at an angle and theres a wall there so it drags along the wall till it goes to that tile.
A* Pathfinding for Beginners (http://www.policyalmanac.org/games/aStarTutorial.htm)
[EDIT] Massive improvements have been made and this is probably the ONLY A* Pathfinding program that actually includes the monster following the path! And you can move your player through the map. It even has collision for the walls. For optimization purposes, the A* Pathfinding only needs to be computed when the monster moves to a new map coordinate.
[EDIT] Another Improvement has been made. I noticed 2 things. One, that the path disappears once in awhile for a split second even though the predator continues to follow the path. Turns out the player needed a role as well in enabling Compute_AStar_Pathfinding. So whenever the player moves to a new map coordinate, it fires AStar. The other problem was that very very rarely it locked up. Having the player play a roll in Compute_Astar_Pathfinding fixed this as well. No more lock ups. Lockups tend to be the biggest problem with AStar samples and can cause your program to hang. I also changed the order it was in the Game_Loop. So it is now this order:
Keyboard Controls
Clear Screen
Collision
AStar Pathfinding
Follow AStar Path
Render Map
Draw AStar Path
Draw Monster
Draw Player
Lock_Framerate 60
DoEvents
Also another improvement I made is that if the monster trys to leave the map screen, itll stop at the edge. However you can leave the map screen with no problem. Itll stop computing AStar when the player is out of the map boundry and the monster continues following the path it has created for itself. AStar samples I tested had Subscript out of range errors for doing so! So my AStar seems to be the best out there so far on the web. I may port this to VB.Net as well and make other improvements such as how the monster interpolates from one tile to the other. Currently although it works, it has issues when the next path for it to follow is at an angle and theres a wall there so it drags along the wall till it goes to that tile.