void HeroEnety::GoDead(){ if(mStateEunm == StateEunm::Dead) { return; } mStateEunm = StateEunm::Dead; HeroManager::getInstance()->del(this); if (SoldierTypeID == 3) { ValueMap data; data.insert(std::make_pair("raid", Value(roadID))); bool isLeft = false; if (mRaceEunm == RaceEunm::Red) { isLeft = true; } data.insert(std::make_pair("isLeft", Value(isLeft))); std::string eventName = "missionary_dead"; EventCustom event = EventCustom(eventName); event.setUserData((void *)(&data)); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); } return; auto callback = CallFuncN::create( CC_CALLBACK_0(HeroEnety::deadcallback,this)); auto dt = DelayTime::create(1); auto fo = FadeOut::create(1); //auto d = Sequence::create((Animate*)Action_Dead, dt, callback, nullptr); auto d = Sequence::create(fo, dt, callback,nullptr); this->runAction(d); }
void HeroEnety::attainBase(RaceEunm race) { ValueMap data; float fractionOffset, humanResOffset, HPOffset; switch (mMentalEnum) { case MentalEnum::Normal: fractionOffset = SacrificeValueWhenNormal; humanResOffset = HumanPowerWhenNormal; HPOffset = HitPointWhenNormal; break; case MentalEnum::Captured: fractionOffset = SacrificeValueWhenCaptured; humanResOffset = HumanPowerWhenCaptured; HPOffset = HitPointWhenCaptured; break; default: break; } data.insert(std::make_pair("fractionOffset", Value(fractionOffset))); data.insert(std::make_pair("humanResOffset", Value(humanResOffset))); data.insert(std::make_pair("HPOffset", Value(HPOffset))); data.insert(std::make_pair("RaceEunm", Value(race))); std::string eventName = "event_arrive_base"; EventCustom event = EventCustom(eventName); event.setUserData((void *)(&data)); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); }
void PauseLayer::startGame(Ref* node) { //CCLOG("START!"); //GAMEDATA::getInstance()->init(); //Director::getInstance()->replaceScene(GameScene::create()); Node* pender = (Node*)node; int tag = pender->getTag(); CCLOG("btn tag = %d",tag); Scene* scene = (Scene*)this->getParent(); GameLayer* gameLayer = (GameLayer*)scene->getChildByTag(999); TopMenu* topMenu = (TopMenu*)gameLayer->getChildByTag(9999); Menu* menuPause = (Menu*)topMenu->getChildByTag(100); menuPause->setEnabled(true); switch (tag) { case 10: { this->removeSelfListener(); //主菜单 Director::getInstance()->replaceScene(MenuScene::create()); this->removeFromParent(); } break; case 11: { Director::getInstance()->getEventDispatcher()->removeEventListener(listener); //重新开始 EventCustom eventReset = EventCustom("Game_Reset"); Director::getInstance()->getEventDispatcher()->dispatchEvent(&eventReset); //从头来 this->removeFromParent(); } break; case 12: { Director::getInstance()->getEventDispatcher()->removeEventListener(listener); //继续游戏 this->removeFromParent(); } break; default: break; } }
void PlayerWin::registerKeyboardEvent() { auto eventDispatcher = cocos2d::Director::getInstance()->getEventDispatcher(); auto keyEvent = cocos2d::EventListenerKeyboard::create(); keyEvent->onKeyReleased = [](EventKeyboard::KeyCode key, Event*) { auto event = EventCustom("APP.EVENT"); stringstream data; data << "{\"name\":\"keyReleased\",\"data\":" << (int)key << "}"; event.setDataString(data.str()); Director::getInstance()->getEventDispatcher()->dispatchEvent(&event); }; eventDispatcher->addEventListenerWithFixedPriority(keyEvent, 1); }