Game Development Reference
In-Depth Information
Figure 5.3 Pathfinding
Let's see how this pattern is implemented in code:
Searching for Directions
At any point, there're 4 options (forward, backward, left and right) that the monster can
choose from to move. We use Monte Carlo distance to calculate the best path that the mon-
ster can efficiently travel along to chase the raccoon.
//Monster method, returns the direction of the best path.
//Parameters:
//
hx - x coordinate of the destination
//
hy - y coordinate of the destination
//
m - the specified monster
public int searchForDirection( int hx, int hy,Monster m){
int backDir = 3-m.direction;
Search WWH ::




Custom Search