Example #1
0
void SGSHero::faceTo(HERO_DIRECTION direction)
{
  setDirection(direction);
  stopAllActions();
 
  Animate* animate = getWalkAnimate(direction);
  RepeatForever* face_walk = RepeatForever::create(animate);
  this->runAction(face_walk);
}
Example #2
0
void SGSHero::moveOneStep(SGSPointList* path)
{
  if (path->empty()) {
    SGSPoint point = getMapPosition();
    log("%s finished move %d %d", this->getName().c_str(), point.x, point.y);
    SGSkirmishScene::getCurrentSkirmish()->startSkirmish(0.0f);
    return;
  } 

  SGSPoint target_pos = path->front();
  path->erase(path->begin());
  faceTo(getRelativeDirection(target_pos));
  log("%s move one step to %d %d", this->getName().c_str(), target_pos.x, target_pos.y);

  stopAllActions();
  int actualDuration = SGS_HERO_MOVE_ONE_STEP_TIME;
  FiniteTimeAction *actionMove = MoveTo::create(actualDuration, SGSPoint::mapPos2OpenGLPos(target_pos));
  __CCCallFuncND * funcall= __CCCallFuncND::create(this, callfuncND_selector(SGSHero::moveOneStepFinished, this), path);
  FiniteTimeAction* moveWithCallback = Sequence::create(actionMove, funcall, NULL);
  Animate* animate = getWalkAnimate(__direction);
  Repeat* walk = Repeat::create(animate, 300);
  Spawn * walk_one_step = Spawn::create(walk, moveWithCallback, NULL);
  this->runAction(walk_one_step);
}
Example #3
0
void Role::walk(DirectState dir)
{
    switch (dir)
    {
        case DIRECT_WALK_LEFT:
            if (!mIsFaceLeft) setFaceLeft(true);
            break;
            
        case DIRECT_WALK_RIGHT:
            if (mIsFaceLeft) setFaceLeft(false);
            break;

		default:
			return;
    }
    
    if (MOVING_WALK == mMovingState) return;
    if (EFFECT_NONE != mJumpingState) return;
    
    mMovingState = MOVING_WALK;
    stopActionByTag(ID_ACTION_MOVING);
    auto temp = runAction(RepeatForever::create(getWalkAnimate()));
    temp->setTag(ID_ACTION_MOVING);
}