Write a SRPG game with cocos2d3.0-the implementation of the moving part

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.