bool BattleScene::checkingHero() { bool heroAlive=true; auto activeLayer = this->getCurrentStageLayer(); auto stage = (ObstacleStage *)activeLayer->getChildByTag(activeLayer->getStageNum()); auto boxList = stage->getBoxList(); for (int i=0; i<boxList->size(); i++) { auto box = boxList->at(i); Vec2 worldPoint = (box->getParent())->convertToWorldSpace(box->getPosition()); auto boxRect = Rect(worldPoint.x, worldPoint.y, BOX_SIZE*GAME_SCALE, BOX_SIZE*GAME_SCALE); if (boxRect.intersectsRect(hero->getBoundingBox())) { heroAlive=false; break; } } return heroAlive; }
//增加下一个地图的步骤 void addNxtStep(struct sokomap *header,struct sokomap **currentTail,struct sokomap *current,struct mappos * boxPos,int boxCount) { //计算人所在的列表 if(current->pos==NULL) { current->pos = personCanWalkPoint(current); } getBoxList(current,boxPos); //进行循环判断箱子可以移动的方向 for(int i=0;i < boxCount;i++) { int x = boxPos[i].x; int y = boxPos[i].y; //向上推的操作 if(isCanPushUp(current,x,y)) { if(isInMappos(current->pos,boxPos[i].x,boxPos[i].y+1)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushUp(tmpMap,x,y); //判断地图是否已经棍了,没棍的话就加入到尾步 if(isMapDead(tmpMap,x,y+1,UP)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } //向下推的操作 if(isCanPushDown(current,boxPos[i].x,boxPos[i].y)) { if(isInMappos(current->pos,boxPos[i].x,boxPos[i].y - 1)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushDown(tmpMap,x,y); //判断地图是否已经棍了,没棍的话加入到尾部 if(isMapDead(tmpMap,x,y-1,DOWN)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } //向左推的操作 if(isCanPushLeft(current,boxPos[i].x,boxPos[i].y)) { if(isInMappos(current->pos,boxPos[i].x + 1,boxPos[i].y)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushLeft(tmpMap,x,y); //判断地图是否已经棍了,没棍的话加入到尾部 if(isMapDead(tmpMap,x - 1,y,LEFT)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } //向右推的操作 if(isCanPushRight(current,boxPos[i].x,boxPos[i].y)) { if(isInMappos(current->pos,boxPos[i].x - 1,boxPos[i].y)) { struct sokomap * tmpMap = copyMap(current); tmpMap ->parent = current; pushRight(tmpMap,x,y); //判断地图是否已经棍了,没棍的话加入到尾部 if(isMapDead(tmpMap,x + 1,y,RIGHT)) { freeMap(tmpMap); }else if(isInSokoMap(header,tmpMap))//已经在列表中,就把这个新地图删除 { freeMap(tmpMap); }else { (*currentTail)->next = tmpMap; *currentTail = tmpMap; } } } } }