void ActorData::reduceHp(float value) { if (this->isDead) return; this->actorPropertyData->currentHp -= value; int percent = actorPropertyData->currentHp / actorPropertyData->hp * 100; bloodTimer->setPercentage(percent); cocos2d::EventCustom reduceHp(ACTOR_EVENT_HURT); lofd::ActorHurtEventParam * actorHurtEventParam = new lofd::ActorHurtEventParam(); actorHurtEventParam->hurt = value; actorHurtEventParam->location = this->actorContainer->getPosition(); actorHurtEventParam->location.y += 300; reduceHp.setUserData(actorHurtEventParam); cocos2d::EventDispatcher * eventDispatcher = cocos2d::Director::getInstance()->getEventDispatcher(); eventDispatcher->dispatchEvent(&reduceHp); if (this->actorPropertyData->currentHp <= 0) { //this->dead(); constellation::BehaviorEvent * event = new constellation::BehaviorEvent(LOFD_ACTOR_BEHAVIOR_EVENT_DEAD); lofd::ActorBehaviorData * data = new lofd::ActorBehaviorData(); data->actorData = this; event->behaviorData = data; int result = this->actorBehavior->root->execute(event); if (result != 1) { cocos2d::log("死亡不成功"); } delete event; delete data; } }
void GameMissionSet::onBtnStart() { m_nHp = GameUIData::getInstance()->getIntegerForKey(cs_CurUserHp.c_str()); if (m_nHp>=5) { GameMusicControl::getInstance()->btnPlay(); reduceHp(); int id = GameUIData::getInstance()->getCurNormalMission(); DataCenter::getInstance()->initMapInfo(id); SCENE_CHANGE_NORMAL(SceneState::DDGameUILayer); } else { MessageBox("体力不足","提示"); return; } }