Determine the moving range of a person in SRPG,
I am using a silly example,
In fact, it is to determine whether the characters can be moved at every point of the movable length,
Then, based on the level of obstacle that the terrain affects the characters,
Each step requires less obstacle-level walking ability.
Specific Code
Void SearchPathForSLG: init (TMXTiledMap * map, Point heroIndex, int runLength, bool movePath [] [255]) {
Point mapSize = Point (map-> getMapSize (). width, map-> getMapSize (). height );
// Reset the movable range
For (int I = 0; I <255; I ++ ){
For (int j = 0; j <255; j ++ ){
MovePath [I] [j] = false;
}
}
// Set the obstacle level of movement
For (int I = 0; I <255; I ++ ){
For (int j = 0; j <255; j ++ ){
ObstacleLevel [I] [j] = TMXMapHelper: getMapTiledObstacleLevel (TMXMapHelper: getMapTiledType (Point (I, j), map ));
}
}
// Start searching
Search (heroIndex, runLength, movePath, mapSize );
}
// Search for the movable range. The sequence is top, bottom, left, and 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 whether the corresponding location is movable
Bool SearchPathForSLG: searchPath (Point heroIndex, int count, bool movePath [] [255], Point mapSize ){
Point thisPoint = heroIndex;
// If this location does not cross the border, continue the disk
If (thisPoint. x> = 0 & thisPoint. y> = 0 & thisPoint. x
Int pointX = (int) thisPoint. x;
Int pointY = (int) thisPoint. y;
// Obtain the obstacle level for this position
Int thisObstacleLevel = obstacleLevel [pointX] [pointY];
// If the obstacle level is 99, the location cannot be changed.
If (thisObstacleLevel = 99)
Return false;
// If the current mobility capability can be moved after the obstacle level is reduced, continue searching
If (count-thisObstacleLevel)> = 0 ){
MovePath [pointX] [pointY] = true;
Search (thisPoint, count-thisObstacleLevel, movePath, mapSize );
}
}
Return false;
}
You can see the figure for the effect.