Sunday, September 6, 2009

break through!

my collaborative path finding algorithm is finally worked on my test program. the algorithm i used is making use of pre-calculated data and used flood fill method to 'bake' them on the scene. thanks for sean cooper giving me the hints. the basic of the algorithm is a follow

1) using A* pathfinding to find the shortest path
2) fill the path with number destination with zero and each point away from destination increment by 100.
2) draw lines on map based on the path, meaning for each path's point we draw a perpendicular line
3) fill the line with number, each point away from path point increment by 10
4) do a post filtering on the map, it is a basic blur filtering, summing 8 neighbor boxes and devide by 8, notes that only cell without any value from previous step need to gone through this.
5) calculate the 'direction of each cell, by comparing the weight of the neighbor cell, from small t big, neighbor with weight higher than 90 don;t put into dir list to prevent flow back problem

the execution:
1) spawn and creep on the staring point
2) during the game loop, read from cell's dir list, move to the first encountered empty neighbor in the dir list
3) remove the creep that have reached the end point

the result is pretty good, although still has speed factor to be taken care of, but i think i'll leave it first and start working on 2d animated trasparent sprite and 3d animated collada model first :)

No comments: