void HelpScene::tabMenuHandler(CCObject* pSender){ CCMenuItemSprite* sprMenu = (CCMenuItemSprite*)pSender; int zOrder = sprMenu->getZOrder(); helpLayers->switchTo(zOrder); helpBtn->setEnabled(true); monsterBtn->setEnabled(true); towerBtn->setEnabled(true); sprMenu->setEnabled(false); }
void LayerGoods::updateMe() { UserInfo *user_info = Topwo::getInstance()->getTopwoData()->getUserInfo(); CCMenu* menu = static_cast<CCMenu*>(this->getChildByTag(0)); //体魄 int goods_level = 0; CCMenuItemSprite* item = NULL; CCSprite* sprite = NULL; CCLabelAtlas* la = NULL; for (int i = 1; i <= 5; i++) { if (i == 1) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelTiPo()); } else if (i == 2) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelMeiLi()); } else if (i == 3) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelZhiLi()); } else if (i == 4) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelEQ()); } else if (i == 5) { goods_level = getGoodsLevel(user_info->getCurrentGoodsLevelGanXing()); } item = static_cast<CCMenuItemSprite*>(menu->getChildByTag(i)); if (goods_level >= 9) { item->setEnabled(false); item->setColor(ccc3(128, 128, 128)); } sprite = static_cast<CCSprite*>(this->getChildByTag(i)); la = static_cast<CCLabelAtlas*>(sprite->getChildByTag(0)); la->setString(CCString::createWithFormat("%d", goods_level)->getCString()); la = static_cast<CCLabelAtlas*>(sprite->getChildByTag(1)); la->setString(CCString::createWithFormat("%d", getGoodsBonus(goods_level))->getCString()); la = static_cast<CCLabelAtlas*>(sprite->getChildByTag(2)); la->setString(CCString::createWithFormat("%d", getGoodsPrice(goods_level))->getCString()); } SceneMain* scene_main = static_cast<SceneMain*>(CCDirector::sharedDirector()->getRunningScene()->getChildByTag(0)); scene_main->updateMe(); }
void PrepareLayer::heroUp(CCObject *pSender) { int upCount = CCUserDefault::sharedUserDefault()->getIntegerForKey("heropUp",0); CCUserDefault::sharedUserDefault()->setIntegerForKey("heropUp",upCount+1); if(upCount %3==0) { showFullUpgrade(); } else { int curLevel = GameConfigData::initialGameData().getCurHeroLevel(); HeroUpgradeData upHeroData = DataInitial::initialDataSource().getHeroUpgrateData(m_curShowHeroId,curLevel); int nexPriece = upHeroData.mlevelPrice; if (nexPriece <= GameConfigData::initialGameData().getCoinValue()) { int coinValue = GameConfigData::initialGameData().getCoinValue() - nexPriece; GameConfigData::initialGameData().setCoinValue(coinValue); curLevel++; GameConfigData::initialGameData().setCurHeroLevel(curLevel); playUpEffect(curLevel); if (curLevel >= HERO_MAXLEVEL) { CCMenuItemSprite *upItem = (CCMenuItemSprite*)pSender; upItem->setEnabled(false); upItem->setVisible(false); if (this->getChildByTag(1430)) { this->getChildByTag(1430)->setVisible(false); } } } else { /* JniCall::sharedJniCall()->setBuyFailedCallBack(this,callFunStr_selector(PrepareLayer::purchaseFailed)); JniCall::sharedJniCall()->setBuyCompleteCallBack(this,callFunStr_selector(PrepareLayer::purchaseSuccess)); JniCall::sharedJniCall()->purchaseByIndex(8);*/ showFullUpgrade(1); } } }
void LevelMap::adjustMap(bool isResetLevel) { int num = floor(offsetY/442); currentMap = -num; int offnum = num%3; float tmpoff = offsetY - num*442; mapLayer->setPosition(ccp(0, (offnum-1)*442 + tmpoff)); if(isResetLevel) { int offlevel = 1000 + currentMap*3 -3; for (int i = 0; i < 9 ; i++) { MapItem* tmpLevelItemData = NULL; tmpLevelItemData = CData::getCData()->getConfigOfMapLevel(offlevel + i); CCMenuItemSprite* tmp = (CCMenuItemSprite*)levelSpDic->objectForKey(i); tmp->removeChildByTag(9999); if (tmpLevelItemData!= NULL && tmpLevelItemData->bid < currentLevelId) { CCSize tmpsz = tmp->getContentSize(); CCSprite* ssp = CCSprite::create(); int num = data["citylist"][tmpLevelItemData->bid - 1000].asInt(); for (int k = 0; k<num; k++) { CCSprite * star = CCSprite::create("zjm_star.png"); star->setPosition(ccp(k*30, 0)); ssp->addChild(star); } ssp->setPosition(ccp(tmpsz.width/2-15*num+15, 0)); ssp->setTag(9999); tmp->addChild(ssp, 0); } if(tmpLevelItemData != NULL) { if(tmpLevelItemData->bid > currentLevelId) { tmp->setEnabled(false); } else { tmp->setEnabled(true); } tmp->setUserObject(tmpLevelItemData); } //for (int j = 1001; j<=1005; j++) //{ CCLabelTTF* tmpName = (CCLabelTTF*)(tmp->getChildByTag(1002)); if(tmpLevelItemData) { tmpName->setString(tmpLevelItemData->nickname.c_str()); } //} } } levelsMenu->setPosition(ccp(0, -442 + tmpoff)); }
void CNFRockerLayer::update( float delta ) { do { //得到主角 CNFProtagonist * pPro = dynamic_cast<CNFProtagonist *>(m_p3DLayer->getChildByTag(enTagProtagonist)); if (pPro!=NULL) { //得到摇杆 CCSprite * pRockerBg = dynamic_cast<CCSprite *>(getChildByTag(enTagRockerBg)); CC_BREAK_IF(pRockerBg==NULL); CCSprite * pRocker = dynamic_cast<CCSprite *>(getChildByTag(enTagRocker)); CC_BREAK_IF(pRocker==NULL); //若正在触摸 if (m_bIsTouching==true) { pRocker->setOpacity(255.f); pRockerBg->setOpacity(255.f); //触摸点与摇杆背景的距离 float fRockerDisX = m_ptTouching.x - pRockerBg->getPositionX(); float fRockerDisY = m_ptTouching.y - pRockerBg->getPositionY(); float fLen = sqrt(pow(fRockerDisX,2)+pow(fRockerDisY,2)); //触摸点与摇杆背景的角度 float fRate = (float)CC_RADIANS_TO_DEGREES( atanf(fRockerDisX/fRockerDisY) ); if(fRockerDisY<0) fRate += 180.f; else if(fRockerDisX<0) fRate += 360.f; //触摸点的实际位置 CCPoint ptRockerMoveTo; if (fLen >= m_fRockerMaxDis) fLen = m_fRockerMaxDis; ptRockerMoveTo.x = sin(fRate/180*3.1415)*fLen + pRockerBg->getPositionX(); ptRockerMoveTo.y = cos(fRate/180*3.1415)*fLen + pRockerBg->getPositionY(); //触摸点与摇杆的距离 float fDisX = ptRockerMoveTo.x - pRocker->getPositionX(); float fDisY = ptRockerMoveTo.y - pRocker->getPositionY(); float fLength = sqrt(pow(fDisX,2)+pow(fDisY,2)); //出发每次移动的条件:距离至少大于速度。 防止颤动 if (fLength > m_fRockerSpeed) { //触摸点与摇杆的角度 float fRateRocker = (float)CC_RADIANS_TO_DEGREES( atanf(fDisX/fDisY) ); if(fDisY<0) fRateRocker += 180.f; else if(fDisX<0) fRateRocker += 360.f; ptRockerMoveTo.x = sin(fRateRocker/180*3.1415)*m_fRockerSpeed + pRocker->getPositionX(); ptRockerMoveTo.y = cos(fRateRocker/180*3.1415)*m_fRockerSpeed + pRocker->getPositionY(); pRocker->setPosition(ptRockerMoveTo); } else //距离小于速度,则直接命中 { pRocker->setPosition(ptRockerMoveTo); } //主角移动 pPro->OnCtrlMoveByRotation(fRate); } //若触摸结束 else { pRocker->setOpacity(100.f); pRockerBg->setOpacity(100.f); pPro->OnCtrlStop(); //移动距离 float fDisX = pRockerBg->getPositionX() - pRocker->getPositionX(); float fDisY = pRockerBg->getPositionY() - pRocker->getPositionY(); float fLen = sqrt(pow(fDisX,2)+pow(fDisY,2)); //若距离大于速度,则移动 if (fLen > m_fRockerSpeed) { float at = (float)CC_RADIANS_TO_DEGREES( atanf(fDisX/fDisY) ); if(fDisY<0) at += 180.f; else if(fDisX<0) at += 360.f; CCPoint ptRockerMoveTo; ptRockerMoveTo.x = sin(at/180*3.1415)*m_fRockerSpeed + pRocker->getPositionX(); ptRockerMoveTo.y = cos(at/180*3.1415)*m_fRockerSpeed + pRocker->getPositionY(); pRocker->setPosition(ptRockerMoveTo); } else //若距离小雨速度,则直接命中 { pRocker->setPosition(pRockerBg->getPosition()); } } //若为副本,则执行按钮逻辑 if (m_nStageID >= _NF_TOWN_OR_BATTLE_ID_ && m_nStageID <_NF_TOWN_FB_ID_) { //得到菜单 CCMenu * pMenu = dynamic_cast<CCMenu *>(getChildByTag(enTagMenu)); CC_BREAK_IF(pMenu==NULL); //遍历按钮,同步CD for (int i=enTagBtnSkill1;i<=enTagBtnSkill5;i++) { //技能CD CCProgressTimer* pProgress = dynamic_cast<CCProgressTimer *>(getChildByTag(i+100)); CC_BREAK_IF(pProgress==NULL); //得到按钮 CCMenuItemSprite * pBtn = dynamic_cast<CCMenuItemSprite *>(pMenu->getChildByTag(i)); CC_BREAK_IF(pBtn==NULL); switch (i) { case enTagBtnSkill1: { //同步技能CD pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_1().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_1().nSkill_CD_Time ); //判断按钮是否可按 if (pPro->GetSkillInfo_1().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill2: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_2().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_2().nSkill_CD_Time ); if (pPro->GetSkillInfo_2().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill3: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_3().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_3().nSkill_CD_Time ); if (pPro->GetSkillInfo_3().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill4: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_4().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_4().nSkill_CD_Time ); if (pPro->GetSkillInfo_4().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; case enTagBtnSkill5: { pProgress->setPercentage( 100*(float)pPro->GetSkillInfo_5().nSkill_CD_Time_Temp/(float)pPro->GetSkillInfo_5().nSkill_CD_Time ); if (pPro->GetSkillInfo_5().nSkill_CD_Time_Temp == 0 && m_bIsPublicCD==false) pBtn->setEnabled(true); else pBtn->setEnabled(false); }break; } } CCProgressTimer* pProgressCom = dynamic_cast<CCProgressTimer *>(getChildByTag(enTagCommonAttackCD)); if(pProgressCom!=NULL){ pProgressCom->setPercentage( 100*pPro->GetCommonAttackCDBFB()); } CCLabelBMFont* pComonFont = dynamic_cast<CCLabelBMFont *>(getChildByTag(enTagCommonAttackFont)); if(pComonFont!=NULL){ if(pPro->GetCommonAttackStatus()!=0){ pComonFont->setString(CCString::createWithFormat("%d",pPro->GetCommonAttackStatus())->m_sString.c_str()); } } //判断是否有技能刚释放 bool bIsSkillStart = false; if (pPro->GetSkillInfo_1().nSkill_CD_Time_Temp==pPro->GetSkillInfo_1().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_2().nSkill_CD_Time_Temp==pPro->GetSkillInfo_2().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_3().nSkill_CD_Time_Temp==pPro->GetSkillInfo_3().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_4().nSkill_CD_Time_Temp==pPro->GetSkillInfo_4().nSkill_CD_Time-1) bIsSkillStart = true; if (pPro->GetSkillInfo_5().nSkill_CD_Time_Temp==pPro->GetSkillInfo_5().nSkill_CD_Time-1) bIsSkillStart = true; //若有技能刚释放 if (bIsSkillStart==true) { m_bIsPublicCD = true; this->runAction(CCSequence::create(CCDelayTime::create(1.f),CCCallFunc::create(this,callfunc_selector(CNFRockerLayer::OnSkillPublicCallBack)),NULL)); for (int i=enTagBtnSkill1;i<=enTagBtnSkill5;i++) { //判断是否显示公共CD bool bIsSkillPublicCD = false; if (i==enTagBtnSkill1 && pPro->GetSkillInfo_1().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill2 && pPro->GetSkillInfo_2().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill3 && pPro->GetSkillInfo_3().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill4 && pPro->GetSkillInfo_4().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; else if (i==enTagBtnSkill5 && pPro->GetSkillInfo_5().nSkill_CD_Time_Temp==0) bIsSkillPublicCD = true; //若显示公共CD if (bIsSkillPublicCD==true) { //显示公共CD CCProgressTimer* pProgress = dynamic_cast<CCProgressTimer *>(getChildByTag(i+200)); CC_BREAK_IF(pProgress==NULL); pProgress->setVisible(true); pProgress->setPercentage(99.f); pProgress->runAction(CCSequence::create(CCProgressTo::create(_NF_PUBLIC_SKILL_CD_,0),NULL)); } } } } } return ; } while (false); CCLog("Fun CNFRockerLayer::update Error!"); }
bool PrepareLayer::init() { CCSize size = ToolsFun::sharedTools()->getSceneSize(); //背景 CCSprite *spBkg = CCSprite::create("ui/shared/bkg.png"); this->addChild(spBkg,-1); spBkg->setPosition(size/2); //放置人物设定背景 CCSprite *spBkgHero = CCSprite::create("ui/prepareUI/mainbkg.png"); this->addChild(spBkgHero,-1); spBkgHero->setPosition(ccp(size.width/2,size.height - spBkgHero->getContentSize().height/2 - 50*gScaleY)); //购物 CCSprite *spBkgTop = CCSprite::create("ui/shared/top.png"); this->addChild(spBkgTop,0,108); spBkgTop->setPosition(ccp(size.width/2,size.height - spBkgTop->getContentSize().height/2)); //人物游戏记录背景 CCSprite *spRecoreBkg = CCSprite::create("ui/prepareUI/recordbkg.png"); this->addChild(spRecoreBkg,-1); spRecoreBkg->setPosition(ccp(315*gScaleX,600*gScaleY)); //spRecoreBkg->setScale(PRE_SCALE); //宠物,道具背景 for (int i=0;i!=1;++i) { CCSprite *sp = CCSprite::create("ui/shared/placeboard.png"); this->addChild(sp,-1); sp->setPosition(ccp(size.width/4 + i * size.width/2,165*gScaleY)); sp->setScale(1.10f); } int level = GameConfigData::initialGameData().getCurLevel(); int killTotal = 0; killTotal = atoi( GameConfigData::initialGameData().getKillTotal().c_str()); char buf[64]; sprintf(buf,"%d",killTotal); int levelMaxStr = GameConfigData::initialGameData().getMaxUnLockLevel(); string strs[4] = { GameConfigData::initialGameData().getHScores(), GameConfigData::initialGameData().getHLenght(), string(buf), ToolsFun::sharedTools()->intToString(levelMaxStr) }; for (int i=0;i!=4;++i) { CCLabelBMFont *hScores = CCLabelBMFont::create(strs[i].c_str() ,"font/white_30.fnt"); spRecoreBkg->addChild(hScores); hScores->setPosition(ccp(150*gScaleX,(165-8-38*i))*gScaleY); hScores->setAnchorPoint(ccp(0,0.5f)); } m_menu = CCMenu::create(); this->addChild(m_menu,1); m_menu->setPosition(CCPointZero); //所有按钮的放置 const char* fName[9] = { "ui/shared/back.png",//返回 "ui/shared/coinplus.png",//添加金币 "ui/prepareUI/head.png",//主角头像 "ui/prepareUI/upgrade.png",//升级按钮 "ui/shared/shop_item.png",//宠物1 "ui/shared/shop_item.png",//宠物2 "ui/shared/shop_item.png",//道具1 // "ui/shared/shop_item.png",//道具2 "ui/shared/confirm.png"//确定开始游戏 }; const CCPoint posArray[9] = { ccp(37*gScaleX,size.height-37*gScaleY),ccp(430*gScaleX,size.height-30*gScaleY),ccp(290*gScaleX,435*gScaleY),ccp(360*gScaleX,335*gScaleY), ccp(54*gScaleX,145*gScaleY),ccp(144*gScaleX,145*gScaleY),ccp(355*gScaleX,145*gScaleY),ccp(235*gScaleX,40*gScaleY),ccp(235*gScaleX,40*gScaleY) }; for (int i=0;i!=8;++i) { CCSprite *spNml = CCSprite::create(fName[i]); CCSprite *spSel = CCSprite::create(fName[i]); spSel->setColor(ccc3(80,80,80)); CCMenuItemSprite *itemSp = CCMenuItemSprite::create(spNml,spSel, this,menu_selector(PrepareLayer::menuTouch)); if(i==2) { m_menu->addChild(itemSp,1,100+i); itemSp->setPosition(posArray[i]); itemSp->setScale(0.8f); } else if(i ==3) { m_menu->addChild(itemSp,1,100+i); itemSp->setPosition(posArray[i]); itemSp->setScale(PRE_SCALE); CCLabelBMFont *upGrade = CCLabelBMFont::create(gGetLanguageDesc(K.UPGRADE_DES).c_str(),"font/upgrade_des.fnt"); itemSp->addChild(upGrade); upGrade->setPosition(ccp(80*gScaleX,-25*gScaleY)); } else { m_menu->addChild(itemSp,1,100+i); itemSp->setPosition(posArray[i]); } } int curLevel = GameConfigData::initialGameData().getCurHeroLevel(); if (curLevel >= HERO_MAXLEVEL) { CCMenuItemSprite *upItem = (CCMenuItemSprite*)m_menu->getChildByTag(103); upItem->setEnabled(false); upItem->setVisible(false); if (this->getChildByTag(1430)) { this->getChildByTag(1430)->setVisible(false); } } //金币放置最上方商城 CCSprite *coinIcon = CCSprite::create("ui/shared/coin.png"); this->addChild(coinIcon,2,1429); coinIcon->setPosition(ccp(280 * gScaleX, size.height - 30 * gScaleY)); m_moneyLabel = CCLabelBMFont::create("10000000","font/level_big.fnt"); this->addChild(m_moneyLabel,4); m_moneyLabel->setAnchorPoint(ccp(0,0.5f)); m_moneyLabel->setPosition(ccp(300*gScaleX,size.height-25*gScaleY)); m_moneyLabel->setScale(0.6F); setCoin(); //升级所需金币数 m_nextLevelPriceLabel = CCLabelBMFont::create("1000000000","font/level_big.fnt"); this->addChild(m_nextLevelPriceLabel,2); m_nextLevelPriceLabel->setPosition(ccp(345*gScaleX,342*gScaleY)); m_nextLevelPriceLabel->setScale(0.45); int curHeroId = GameConfigData::initialGameData().getCurHeroId(); int heroLevel = GameConfigData::initialGameData().getCurHeroLevel(); //名字label m_heroNameLabel = CCLabelBMFont::create("name","font/hero_name.fnt"); this->addChild(m_heroNameLabel,10); m_heroNameLabel->setPosition(ccp(390*gScaleX,475*gScaleY)); m_heroNameLabel->setScale(0.8f); //主角现在等级 CCSprite* curHeroLevel=CCSprite::create("ui/prepareUI/level.png"); this->addChild(curHeroLevel,2); curHeroLevel->setPosition(ccp(370*gScaleX,445*gScaleY)); curHeroLevel->setScale(0.8f); //数字改变部分 m_curHeroLevel = CCLabelBMFont::create("10000000",GOLD_FONT); this->addChild(m_curHeroLevel,2); m_curHeroLevel->setPosition(ccp(420*gScaleX,445*gScaleY)); string levelStr = ToolsFun::sharedTools()->intToString(heroLevel); m_curHeroLevel->setString((levelStr).c_str()); m_curHeroLevel->setScale(0.8f); //点击头像改变 CCSprite* changeName=CCSprite::create("ui/prepareUI/changename.png"); this->addChild(changeName,2); changeName->setPosition(ccp(390*gScaleX,400*gScaleY)); changeName->setScale(0.8f); CCSprite *itemBkg = CCSprite::create("ui/shared/itemBkg.png"); this->addChild(itemBkg); itemBkg->setPosition(ccp(360,145)); initPet(0); initPet(1); initHeroSp(GameConfigData::initialGameData().getCurHeroId()); initItem(0); //initItem(1); playUpEffect(heroLevel,false); registerNDK(); return true; }