bool Heroes::Move(bool fast) { if(Modes(ACTION)) ResetModes(ACTION); // move hero if(path.isValid() && (isEnableMove() || (GetSpriteIndex() < 45 && GetSpriteIndex() % 9) || GetSpriteIndex() >= 45)) { // fast move for hide AI if(fast) { direction = path.GetFrontDirection(); MoveStep(true); return true; } else { // if need change through the circle if(GetDirection() != path.GetFrontDirection()) { AngleStep(path.GetFrontDirection()); } else // move if(MoveStep()) { if(isFreeman()) return false; return true; } } } else { SetMove(false); } return false; }
void GameLayer::update(float dt){ if (!HeadCollideBody(head->getDirec()) && !OutofRange()) { MoveStep(); if(ifGetFood()){ AddBody(); SetFood(); } lastbodyposi = body.at(body.size()-1)->getPosition(); } else{ GameOver(); } }
//执行地图角色精灵移动动作,在传入的回调函数中执行之后的任务 void BattleCharacter::Move(SEL_CallFuncND callFuncND) { //锁定视角 m_pMap->LockCharacterView(this); //停止之前的动画 m_pMapSprite->stopAllActions(); m_pMapShadow->stopAllActions(); m_pHPBar->stopAllActions(); m_pHPBarOff->stopAllActions(); m_pMapActions->removeAllObjects(); m_pMapShadowFollowActions->removeAllObjects(); m_pHPBarOffFollowActions->removeAllObjects(); m_pHPBarFollowActions->removeAllObjects(); InitStep(); while(!m_tPaths.empty()) { twards_enum tward = m_tPaths.back(); m_tPaths.pop_back(); MoveStep(tward); } if(callFuncND!=NULL) { m_pMapActions->addObject(CCCallFuncND::create(m_pStatus,callFuncND,(void*)m_pStatus)); } CCAction* pActions = CCSequence::create(m_pMapActions); m_pMapSprite->runAction(pActions); if(m_pHPBarFollowActions->count()!=0) { m_pHPBar->runAction(CCSequence::create(m_pHPBarFollowActions)); m_pHPBarOff->runAction( CCSequence::create(m_pHPBarOffFollowActions)); m_pMapShadow->runAction( CCSequence::create(m_pMapShadowFollowActions)); } m_nCommandFlag = COMM_NONE; //自身已经移动过了 m_bMoved = true; }
#include "BehaviorDefine.h" const MoveStep GMoveSteps[] = { MoveStep(0,1), MoveStep(0,-1), MoveStep(-1,0), MoveStep(1,0), MoveStep(-1,1), MoveStep(1,1), MoveStep(-1,-1), MoveStep(1,-1), MoveStep(0,0), };