Game Development Reference
In-Depth Information
}
else
{
return
best[(best[0]==backDir?1:0)];
}
}
return
backDir;
}
Pathfinding at a Crossway
As the monster approaches a crossway, it has to decide which direction is passable.
//Determines if the specified monster is at a crossway
//Paramters:
//
m - the specified monster
public boolean
checkIfCrossWay(Monster m){
int
mrow = m.row;
int
mcol = m.col;
switch
(m.direction){
case
DIR_DOWN:
case
DIR_UP:
if
(gv.checkIfCrossWay(mrow,mcol-1)||
gv.checkIfCrossWay(mrow,mcol+1))
return true
;
break
;
case
DIR_LEFT:
case
DIR_RIGHT:
if
(gv.checkIfCrossWay(mrow-1,mcol)||
gv.checkIfCrossWay(mrow+1,mcol))
return true
;
break
;
default
:
return true
;
}
Search WWH ::
Custom Search