void Monster::onEnter() { Character::onEnter(); schedule(schedule_selector(Monster::onUpdate)); int MonsterIdx = m_iMonsterID - 1; setCurSpeed(GI.getMonsterConfig()[MonsterIdx].fMoveSpeed); setMaxSpeed(GI.getMonsterConfig()[MonsterIdx].fMoveSpeed); setMaxHealth(GI.getMonsterConfig()[MonsterIdx].iHP); setCurHealth(GI.getMonsterConfig()[MonsterIdx].iHP); setMoveVector(ccp(1, 0)); sprintf(CMonster, "spirit/monster/Monster%d", m_iMonsterID); std::string StrMonster(CMonster); // 设置动画 // 0.右 1.下 2.左 3.上 m_pWalkAnim[0] = CCAnimation::create(); m_pWalkAnim[0]->retain(); m_pWalkAnim[0]->addSpriteFrameWithFileName( (StrMonster + std::string("_R_1.png")).c_str() ); m_pWalkAnim[0]->addSpriteFrameWithFileName( (StrMonster + std::string("_R_2.png")).c_str() ); m_pWalkAnim[0]->setDelayPerUnit(0.5f / getCurSpeed()); m_pWalkAnim[1] = CCAnimation::create(); m_pWalkAnim[1]->retain(); m_pWalkAnim[1]->addSpriteFrameWithFileName( (StrMonster + std::string("_D_1.png")).c_str() ); m_pWalkAnim[1]->addSpriteFrameWithFileName( (StrMonster + std::string("_D_2.png")).c_str() ); m_pWalkAnim[1]->setDelayPerUnit(0.5f / getCurSpeed()); m_pWalkAnim[2] = CCAnimation::create(); m_pWalkAnim[2]->retain(); m_pWalkAnim[2]->addSpriteFrameWithFileName( (StrMonster + std::string("_L_1.png")).c_str() ); m_pWalkAnim[2]->addSpriteFrameWithFileName( (StrMonster + std::string("_L_2.png")).c_str() ); m_pWalkAnim[2]->setDelayPerUnit(0.5f / getCurSpeed()); m_pWalkAnim[3] = CCAnimation::create(); m_pWalkAnim[3]->retain(); m_pWalkAnim[3]->addSpriteFrameWithFileName( (StrMonster + std::string("_U_1.png")).c_str() ); m_pWalkAnim[3]->addSpriteFrameWithFileName( (StrMonster + std::string("_U_2.png")).c_str() ); m_pWalkAnim[3]->setDelayPerUnit(0.5f / getCurSpeed()); // 设置技能 m_pSkill = Skill::create(GI.getMonsterConfig()[MonsterIdx].iSkillID); addChild(m_pSkill); // 冰冻 m_bIsFrozen = false; m_bForceToStop = false; m_bDropItemAfterDeath = true; }
void Hero::onEnter() { Character::onEnter(); schedule(schedule_selector(Hero::onUpdate)); // 设置速度 setCurSpeed(GI.HeroInitSpeed); setMaxSpeed(GI.HeroMaxSpeed); // 设置动画 // 0.下 1.左 2.上 3.右 m_pWalkAnim[0] = CCAnimation::create(); m_pWalkAnim[0]->retain(); m_pWalkAnim[0]->addSpriteFrameWithFileName("Hero1_1.png"); m_pWalkAnim[0]->addSpriteFrameWithFileName("Hero1_2.png"); m_pWalkAnim[0]->setDelayPerUnit(0.5 / getCurSpeed()); }
bool Hero::changeSpeed(bool isSpeedUp) { bool isSpeedChange = true; if (isSpeedUp && speedLevel < MAX_SPEED_LEVEL) { speedLevel++; } else if (!isSpeedUp && speedLevel>0) { speedLevel--; } else { isSpeedChange = false; } if (isSpeedChange) { if (speedLevel == 0) { this->stopAllActions(); } else { AnimData *p = (AnimData*)g_Control.m_Resource["Hero"]; CCAnimation *animation = AnimationUtils::createAnimationWithSpriteFrames(p->hero_speed, speedLevel); this->setIdleAction(CCRepeatForever::create(CCAnimate::create(animation))); setCurSpeed(speedLevel); this->idle(); CCLog("speed level = %d", speedLevel); } } return isSpeedChange; }
bool Hero::init() { bool bRet = false; do { AnimData *p = (AnimData*)g_Control.m_Resource["Hero"]; char ch[32] = {0}; sprintf(ch, p->hero_speed.m_strPath.c_str(), speedLevel, 0); this->initWithFile(ch); this->setPosition(p->hero_speed.m_Position); CCAnimation *animation = AnimationUtils::createAnimationWithSpriteFrames(p->hero_speed, speedLevel); this->setIdleAction(CCRepeatForever::create(CCAnimate::create(animation))); setCurSpeed(speedLevel); animation = AnimationUtils::createAnimationWithSpriteFrames(p->hero_hit); this->setHitAction(CCRepeatForever::create(CCAnimate::create(animation))); //CCFiniteTimeAction *actionOne = CCSequence::create( // CCAnimate::create(animation), // CCCallFunc::create(this, callfunc_selector(Monster::idle)), // NULL // ); //this->setHitAction(actionOne); animation = AnimationUtils::createAnimationWithSpriteFrames(p->hero_speed_up); CCFiniteTimeAction *actionOne = CCSequence::create( CCAnimate::create(animation), CCCallFunc::create(this, callfunc_selector(Monster::idle)), NULL ); this->setSpeedUpAction(actionOne); bRet = true; } while (0); return bRet; }