void ObjHero::actionWalk(Node* target, Point des){ Point destination = getPointInMap(des); assert(rootObj); rootObj->stopAllActions(); setState(EobjState::E_WALK); if((destination.x < rootObj->getPosition().x && dir == EDIR_FORWARD) || (destination.x > rootObj->getPosition().x && dir == EDIR_BACKWARD)){ turnAround(); } Animation* walk = createAnimateWithFileNames("HeroRun%d.png", 11); walk->setDelayPerUnit(0.1); auto action = Animate::create(walk); float distance = sqrtf((destination.x - rootObj->getPositionX()) * (destination.x - rootObj->getPositionX()) + (destination.y - rootObj->getPositionY()) * (destination.y - rootObj->getPositionY())); float dur = distance / speed; setDesPoin(des); auto moveTo = MoveTo::create(dur, destination); rootObj->runAction(RepeatForever::create(action)); rootObj->runAction(CCSequence::create(moveTo, CallFunc::create( CC_CALLBACK_0(ObjHero::actionStand,this)), NULL)); //target->runAction(Follow::create(rootObj)); }
void ObjMonster::actionAttack(){ if(getState() == EobjState::E_HURT) return; if(getState() == EobjState::E_ATTACK) return; assert(rootObj); rootObj->stopAllActions(); setState(EobjState::E_ATTACK); Animation* attack = createAnimateWithFileNames("RobotAttack%d.png", 5); attack->setDelayPerUnit(0.1); auto action = Animate::create(attack); rootObj->runAction(CCSequence::create(action, CallFunc::create( CC_CALLBACK_0(ObjMonster::actionStand,this)), NULL)); }
void ObjHero::actionStand(){ assert(rootObj); if(getHP() <= 0){ die(); return; } rootObj->stopAllActions(); setDesPoin(rootObj->getPosition()); setState(EobjState::E_STAND); Animation* stand = createAnimateWithFileNames("Hero%d.png", 3); auto action = Animate::create(stand); rootObj->runAction(RepeatForever::create(action)); }
void ObjHero::actionAttack(){ if(getState() == EobjState::E_ATTACK) return; assert(rootObj); rootObj->stopAllActions(); setState(EobjState::E_ATTACK); Animation* attack = createAnimateWithFileNames("HeroAttack%d.png", 5); attack->setDelayPerUnit(0.1); auto action = Animate::create(attack); rootObj->runAction(CCSequence::create(action, CallFunc::create( CC_CALLBACK_0(ObjHero::actionStand,this)), NULL)); //scheduleOnce(schedule_selector(ObjHero::attackEffect), 0.2f); attackEffect(); }
void ObjMonster::actionStand(){ assert(rootObj); if(getHP() <= 0){ die(NULL); return; } //if(getState() == EobjState::E_HURT) return; rootObj->stopAllActions(); setState(EobjState::E_STAND); Animation* stand = createAnimateWithFileNames("Robot%d.png", 3); auto action = Animate::create(stand); rootObj->runAction(RepeatForever::create(action)); }
void ObjHero::actionRusn(){ if(getState() == EobjState::E_RUSH) return; assert(rootObj); rootObj->stopAllActions(); setState(EobjState::E_RUSH); int flag = 1; if(dir == EDIR_FORWARD) flag = 1; else flag = -1; int distance = 60; Point p = ccpAdd(rootObj->getPosition(), ccp(distance * flag, 0)); Animation* rush = createAnimateWithFileNames("HeroAttackT%d.png", 3); rush->setDelayPerUnit(0.1); auto actionRush = Animate::create(rush); rootObj->runAction(actionRush); MoveTo* moveTo = MoveTo::create(0.3, getPointInMap(p)); rootObj->runAction(CCSequence::create(moveTo, CallFunc::create( CC_CALLBACK_0(ObjHero::actionStand,this)), NULL)); attackEffect(); }