Determine the range of movement of a SRPG character,
I'm using a rather silly method of poor lifting,
In fact, the character can move the length of each point to determine whether you can move,
Then, depending on the level of barriers to the influence of the terrain on people,
With each step, one less obstacle level of walking capacity.
Specific look at the code
void SEARCHPATHFORSLG:: Init (tmxtiledmap* map, point heroindex,int runlength, BOOL movepath[][255]) {
Point mapsize=Point (map->getmapsize(). Width,map->getmapsize(). height);
// Reset removable Range
for (int i=0; i<255; i++) {
for (int j=0; j<255; j + +) {
Movepath[i][j]=false;
}
}
// Set the mobility barrier level
for (int i=0; i<255; i++) {
for (int j=0; j<255; j + +) {
obstaclelevel[i][j]=tmxmaphelper::getmaptiledobstaclelevel(tmxmap Helper::getmaptiledtype(point(I,J), map));
}
}
// start Search
Search (heroindex,runlength,movepath,mapsize);
}
// find movable range - order for top, bottom, left, right
BOOL SEARCHPATHFORSLG:: Search ( point heroindex,int count,bool movepath[][255 ], point mapsize) {
SearchPath (Point (heroindex. x, Heroindex. y-1), count,movepath,mapsize);
SearchPath (Point (heroindex. x, Heroindex. y+1), count,movepath,mapsize);
SearchPath (Point (heroindex. X-1, Heroindex. y), count,movepath,mapsize);
SearchPath (Point (heroindex. X+1, Heroindex. y), count,movepath,mapsize);
return false;
}
// Find out if the corresponding location is movable
BOOL SEARCHPATHFORSLG:: SearchPath ( point heroindex,int count,bool movepath[][ 255], point mapsize) {
Point Thispoint=heroindex;
// If the position is not out of bounds, continue the disk but
if (Thispoint. x>=0&&thispoint. y>=0&&thispoint. x<mapsize. x&&thispoint. y<mapsize. y) {
int pointx= (int) thispoint. x;
int pointy= (int) thispoint. y;
// get an obstacle level for this location
int thisobstaclelevel=obstaclelevel[Pointx][pointy];
// If the barrier level is a description of the change of position is not movable
if (thisobstaclelevel==)
return false;
// If the current mobility can be moved after losing the barrier level, continue to find
if ((count-thisobstaclelevel) >=0) {
Movepath[pointx][pointy]=true;
Search (thispoint,count-thisobstaclelevel,movepath,mapsize);
}
}
return false;
}
The effect can be seen in the picture.
Write a SRPG game with cocos2d3.0-the implementation of the moving part