bool ProceedController::init(){ if (!CCLayer::init()) { return false; } CCSize size = CCDirector::sharedDirector()->getWinSize(); //暂停按钮 CCMenuItemSprite *pause = this->instanceButton("pause1.png", "pause2.png", menu_selector(ProceedController::gamePauseFunc)); pause->setScale(1.5f); pause->setPosition(ccp(size.width - pause->getContentSize().width, size.height - pause->getContentSize().height)); //跳跃按钮 CCMenuItemSprite *jump = this->instanceButton("control_btn1.png", "control_btn2.png", menu_selector(ProceedController::gameJumpFunc)); jump->setScale(1.6f); jump->setPosition(ccp(size.width - jump->getContentSize().width - 50, 100)); //fever按钮 CCMenuItemSprite *fever = this->instanceButton("Fever_1_1.png", "Fever_1_1.png",menu_selector(ProceedController::gameFeverFunc)); fever->setScale(1.5f); fever->setOpacity(0.0f); fever->setPosition(ccp(jump->getPosition().x - fever->getContentSize().width * 2.0, jump->getPosition().y)); CCMenu *menu = CCMenu::create(pause,jump,fever,NULL); menu->setPosition(0, 0); this->addChild(menu,80); return true; }
bool testEffect::init(){ if ( !CCLayer::init() ){return false;} CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("0.GeneralPart.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("MikuFight.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("SheldonFight.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("IronManFight.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LichKingFight.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("BladeMasterFight.plist"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("FightGeneral.plist"); ASBotFightLayer* aaa = ASBotFightLayer::createAsFightLayer(2, 4,true,1000,1,10000,6,10000,10); aaa->setPosition(CCPointZero); addChild(aaa,9999,9999); CCMenu* menu = CCMenu::create(); for (int i = 1; i < 7 ; i++) { string tmp = "card_" + int2string(i) + ".png"; CCSprite* repeatSprite = CCSprite::createWithSpriteFrameName(tmp.c_str()); CCMenuItemSprite* repeat = CCMenuItemSprite::create(repeatSprite,repeatSprite,this,menu_selector(testEffect::Repeat)); repeat->setScale(0.45); repeat->setPosition(ccp(size.width/7 + size.width*(i-1)/7,size.height/8)); repeat->setTag(i); menu->addChild(repeat); } menu->setPosition(CCPointZero); addChild(menu,10000); return true; }
void GameLayer::instructionButtonClick(CCObject *sender){ if (bPaused) { return; } bPaused = true; CCLayer *layer2 = new CCLayer(); CCSprite* dialog_bk = ThemeManager::sharedInstance()->spriteWithImageFile("dialog_intro.png"); dialog_bk->setScaleX(SCREEN_WIDTH/dialog_bk->getContentSize().width); dialog_bk->setScaleY(SCREEN_WIDTH/dialog_bk->getContentSize().width); dialog_bk->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)); layer2->addChild(dialog_bk,11); CCSprite* cancelNormal = ThemeManager::sharedInstance()->spriteWithImageFile("btn_know.png"); CCSprite* cancelSelected = ThemeManager::sharedInstance()->spriteWithImageFile("btn_know.png"); //CCMenuItemSprite* pcancelItemSprite = CCMenuItemSprite::itemWithNormalSprite(cancelNormal, cancelSelected, this, menu_selector(GameLayer::theme3useButtonClick)); CCMenuItemSprite* pcancelItemSprite = CCMenuItemSprite::itemWithNormalSprite(cancelNormal, cancelSelected, this, menu_selector(GameLayer::cancelButtonClick)); pcancelItemSprite->setScale(0.6*LL_SCREEN_SCALE_VALUE); CCMenu* pcancelMenu = CCMenu::menuWithItems(pcancelItemSprite,NULL); pcancelMenu->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT*0.28)); layer2->addChild(pcancelMenu, 12); layer2->setTag(1000); CCActionInterval* largeto = CCScaleBy::create(0.2, 2); layer2->setScale(0.5); layer2->runAction(largeto); this->addChild(layer2, 10); }
void ASGame::energyBarAnimation(){ //1.显示行动力的圆形底座 CCSprite* energyBall = CCSprite::createWithSpriteFrameName("newEnergyContainer.png"); energyBall->setPosition(ccp(size.width*17.38/80,size.height*77.85/90+winDif*2*alpha*alpha)); addChild(energyBall,4); //2.行动力数量 string perStr = int2string(moveCount); CCLabelTTF* per = CCLabelTTF::create(perStr.c_str(),"Arial Rounded MT bold",32); per->setPosition(ccp(size.width*17.38/80,size.height*77.85/90+winDif*2*alpha*alpha)); addChild(per,5,1*10000000+26); //3.能量条 CCSprite* energyBarSprite = CCSprite::createWithSpriteFrameName("newEnergyBar.png"); CCProgressTimer* energyBar = CCProgressTimer::create(energyBarSprite); energyBar->setPosition(ccp(size.width*8.45/80,size.height*79.89/90+winDif*2*alpha*alpha)); energyBar->setType(kCCProgressTimerTypeRadial); energyBar->setPercentage(moveCount*20); addChild(energyBar,4,1*10000000+20); //4.攻击按钮底座 CCSprite* containerSprite = CCSprite::createWithSpriteFrameName("energyContainer.png"); CCSprite* containerSprite_s = CCSprite::createWithSpriteFrameName("energyContainer.png"); CCMenuItemSprite* energyContainer = CCMenuItemSprite::create(containerSprite,containerSprite_s,this,menu_selector(ASGame::enterFightLayer)); energyContainer->setScale(1.05); energyContainer->setPosition(ccp(size.width*179.5/200,size.height*10.25/135)); CCMenu* energyContainerMenu = CCMenu::create(energyContainer,NULL); energyContainerMenu->setPosition(CCPointZero); if (moveCount < moveToFight) energyContainerMenu->setTouchEnabled(false); addChild(energyContainerMenu,2,1*10000000+27); //5.攻击按钮充值槽 CCSprite* barSprite = CCSprite::createWithSpriteFrameName("energyBar.png"); CCProgressTimer* attackButton = CCProgressTimer::create(barSprite); attackButton->setScale(1.05); attackButton->setPosition(ccp(size.width*179.04/200,size.height*10/135)); attackButton->setType(kCCProgressTimerTypeBar); attackButton->setMidpoint(ccp(0.5, 0)); attackButton->setBarChangeRate(ccp(0, 1)); attackButton->setPercentage(100*moveCount/moveToFight); addChild(attackButton,3,1*10000000+25); //4.能量的盖子 CCSprite* energyBarCover = CCSprite::createWithSpriteFrameName("energyBarCover.png"); energyBarCover->setPosition(ccp(size.width*179.5/200,size.height*10.25/135)); energyBarCover->setOpacity(0); //addChild(energyBarCover,4,1*10000000+28); }
bool GameScene::init() { screenSize = CCDirector::sharedDirector()->getWinSize(); int r = CCRANDOM_0_1() * 10; CCSprite* bg = NULL; if (r >= 5) { bg = CCSprite::createWithSpriteFrameName("bg_day.png"); } else { bg = CCSprite::createWithSpriteFrameName("bg_night.png"); } bg->setAnchorPoint(ccp(0, 0)); bg->setPosition(ccp(0, 0)); addChild(bg, 0); CCSprite* land0 = CCSprite::createWithSpriteFrameName("land.png"); land0->setAnchorPoint(ccp(0, 0)); land0->setPosition(ccp(0, 0)); addChild(land0, 3, TAG_LAND); CCMoveBy* move = CCMoveBy::create(1.0f, ccp(-land0->getContentSize().width * 0.25f, 0)); CCCallFuncN* call = CCCallFuncN::create(this, callfuncN_selector(GameScene::removeNodeSelf)); CCSequence* seq = CCSequence::create(move, call, NULL); land0->runAction(seq); randomValue = 0; gameScore = 0; isGameOver = false; isShowingHint = true; pipeArray = CCArray::create(); CC_SAFE_RETAIN(pipeArray); hitCheckArray = CCArray::create(); CC_SAFE_RETAIN(hitCheckArray); createBird(); showHint(); CCMenuItemSprite* pauseItem = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("button_pause.png"), NULL, this, menu_selector(GameScene::touchPauseCallBack)); pauseItem->setPosition(ccp(screenSize.width * 0.92f, screenSize.height * 0.95f)); pauseItem->setScale(2.0f); CCMenu* m = CCMenu::create(pauseItem, NULL); m->setPosition(CCPointZero); addChild(m, 10); M3AudioManager::shareInstance(); return true; }
bool RPGMapItemsMenuLayer::init(cocos2d::CCDictionary *stringList, CppSQLite3DB *db, float width, float height) { if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height)) { this->m_stringList = stringList; this->m_stringList->retain(); this->m_db = db; this->m_itemsList = new CCArray(); this->m_itemsList->init(); CCTMXTiledMap *mainBg = CCTMXTiledMap::create(CCString::createWithFormat("map_menu3_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString()); mainBg->setPosition(CCPointZero); mainBg->setTag(kRPGMapItemsMenuLayerTagBg); this->addChild(mainBg); CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapItemsMenuLayerTagMainMenu); mainMenu->setAnchorPoint(CCPointZero); mainMenu->setPosition(CCPointZero); this->addChild(mainMenu); CCMenuItemSprite *menuBack = (CCMenuItemSprite*)mainMenu->getChildByTag(kRPGMapItemsMenuLayerTagMainMenuBack); if(!menuBack) { menuBack = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapItemsMenuLayer::onMenu)); menuBack->setPosition(ccp(40, 600)); menuBack->setTag(kRPGMapItemsMenuLayerTagMainMenuBack); menuBack->setScale(0.5); mainMenu->addChild(menuBack); } CCTableView *tableView = CCTableView::create(this, CCSizeMake(900, 570)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(ccp(80, 30)); tableView->setDelegate(this); tableView->setVerticalFillOrder(kCCTableViewFillTopDown); tableView->setTag(kRPGMapItemsMenuLayerTagItemListTable); this->addChild(tableView); this->loadItemsData(); return true; } return false; }
//private void RPGMapSceneLayer::startPlay(float delay) { CCTMXTiledMap *bgMap = (CCTMXTiledMap*)this->getChildByTag(kRPGMapSceneLayerTagBgMap); //数据库部分,读取npc数据 CppSQLite3Query query = this->m_db.execQuery(CCString::createWithFormat(NPC_QUERY, this->m_mapData.mapId)->getCString()); while(!query.eof()) { float x = (stringToNumber<float>(query.getStringField("tmx_x")) + 0.5) * GAME_TMX_ROLE_WIDTH; float y = (stringToNumber<float>(query.getStringField("tmx_y")) + 0.5) * GAME_TMX_ROLE_HEIGHT; bool autoMove = query.getIntField("auto_move") == 1 ? true : false; RPGMapNPCRoleSprite *npc = RPGMapNPCRoleSprite::create(query.getIntField("id"), CCString::create(query.getStringField("map_texture")), CCString::create("head_texture"), CCString::create(query.getStringField("name_cns")), CCString::create(query.getStringField("content_cns")), 1, autoMove); npc->setTag(kRPGMapSceneLayerTagNPC + query.getIntField("id")); npc->setPosition(ccp(x, y)); bgMap->addChild(npc); query.nextRow(); } query.finalize(); //player int defaultSpriteFrameIndex = 1; //默认为向下 if(this->m_mapData.playerDirection.compare("up") == 0) { defaultSpriteFrameIndex = 10; } else if(this->m_mapData.playerDirection.compare("left") == 0) { defaultSpriteFrameIndex = 4; } else if(this->m_mapData.playerDirection.compare("right") == 0) { defaultSpriteFrameIndex = 7; } RPGMapRoleSprite *player = RPGMapRoleSprite::create(CCString::create("actor4_0.png"), CCString::create("Player"), true, defaultSpriteFrameIndex); player->setPosition(ccp(this->m_mapData.playerToX * GAME_TMX_ROLE_WIDTH, this->m_mapData.playerToY * GAME_TMX_ROLE_HEIGHT)); player->setTag(kRPGMapSceneLayerTagPlayer); player->m_type = kRPGMapRoleSpriteTypePlayer; bgMap->addChild(player); CCSprite *spJoystick = CCSprite::createWithSpriteFrameName("Ball.png"); CCSprite *joystickBg = CCSprite::createWithSpriteFrameName("Dock.png"); OzgJoystickLayer *joystick = OzgJoystickLayer::layerActivityJoystick(50, spJoystick, joystickBg, false); joystick->setTag(kRPGMapSceneLayerTagJoystick); joystick->m_target = this; joystick->m_endedSelector = callfunc_selector(RPGMapSceneLayer::joystickEndedFunc); this->addChild(joystick); //menu CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapSceneLayerTagMainMenu); mainMenu->setAnchorPoint(ccp(0.5, 0.5)); mainMenu->setPosition(CCPointZero); mainMenu->setContentSize(bgMap->getContentSize()); bgMap->addChild(mainMenu); CCMenuItemSprite *menuCommand = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapSceneLayer::onMenu)); menuCommand->setPosition(ccp(mainMenu->getContentSize().width - 35, mainMenu->getContentSize().height - 35)); menuCommand->setTag(kRPGMapSceneLayerTagMainMenuCommand); menuCommand->setRotation(180); menuCommand->setScale(0.75); mainMenu->addChild(menuCommand); // CCTextureCache::sharedTextureCache()->dumpCachedTextureInfo(); CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 1, true); this->scheduleUpdate(); }
Loading::Loading() { glClearColor(0.0f/255.0f, 0.0f/255.0f, 0.0f/255.0f, 1.0f); setTouchEnabled( true ); float scale = ScreenHelper::getTextureScale(); float scaleX = ScreenHelper::getTextureScaleX(); float scaleY = ScreenHelper::getTextureScaleY(); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Buttons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Buttons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("ctm_Icons.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ctm_Icons.plist"); CCTextureCache::sharedTextureCache()->addPVRImage("LoadingScreen.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LoadingScreen.plist"); CCPoint scalePoint; scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.y += -5*scale; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_Screen_ver2.png"); sprite->setScale(scale); sprite->setPosition(scalePoint); addChild(sprite); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_ProgressScroll_Graphic.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY*1.2f); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_LEFT,-140.0f,-50.0f)); loadingBar = sprite; addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopPanel.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-55.0f)); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_TopOverlay.png"); sprite->setScaleX(scaleX); sprite->setScaleY(scaleY); sprite->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("BackgroundPlate.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += -97.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); sprite = CCSprite::createWithSpriteFrameName("BronzeText.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += -97.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); CCLabelTTF *label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(0,0,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,2.0f,-44.0f)); label = CCLabelTTF::create(LevelSelect::getLevelName(), "impact.ttf", 42*scale); addChild(label, 2); label->setColor(ccc3(237,188,0)); label->setPosition(ScreenHelper::getAnchorPointPlusOffset(ScreenHelper::ANCHOR_TOP_CENTER,0.0f,-42.0f)); int currentLevel = LevelSelect::getCurrentLevel(); if(currentLevel >= BONUS_LEVELSTART) g_isTrickLevel = true; else g_isTrickLevel = false; int medalLevel = SaveLoad::m_SaveData.medalLockLevel; int showMedal = 0; if(medalLevel==0) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::ONE_COCONUT) showMedal = 1; } if(medalLevel==1) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::TWO_COCONUT) showMedal = 2; } if(medalLevel==2) { if(SaveLoad::m_SaveData.levelflags[currentLevel] & SaveLoad::THREE_COCONUT) showMedal = 3; } if(!showMedal) { CCSize dimensions; dimensions.width = 100*scale; dimensions.height = 25*scale; label = CCLabelTTF::create("Time:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += 50.0f*scale; label->setPosition(scalePoint); char tempLabelStr[32]; sprintf(tempLabelStr,"%.2f",LevelSelect::getLevelGoals()->time); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+150.0f)*scale; scalePoint.y += 50.0f*scale; label->setPosition(scalePoint); label = CCLabelTTF::create("Peanuts:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += 20.0f*scale; label->setPosition(scalePoint); sprintf(tempLabelStr,"%d",LevelSelect::getLevelGoals()->peanuts); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+170.0f)*scale; scalePoint.y += 20.0f*scale; label->setPosition(scalePoint); label = CCLabelTTF::create("Points:", "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(237,188,0)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+90.0f)*scale; scalePoint.y += -10.0f*scale; label->setPosition(scalePoint); sprintf(tempLabelStr,"%d",LevelSelect::getLevelGoals()->points); label = CCLabelTTF::create(tempLabelStr, "impact.ttf", 21*scale,dimensions,kCCTextAlignmentLeft); addChild(label, 2); label->setColor(ccc3(255,255,255)); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += (-240.0f+160.0f)*scale; scalePoint.y += -10.0f*scale; label->setPosition(scalePoint); } else { CCTextureCache::sharedTextureCache()->addPVRImage("LoadingScreen2.pvr.ccz"); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("LoadingScreen2.plist"); if(showMedal == 1) sprite = CCSprite::createWithSpriteFrameName("ctm_BronzeMedalBig.png"); if(showMedal == 2) sprite = CCSprite::createWithSpriteFrameName("ctm_SilverMedalBig.png"); if(showMedal == 3) sprite = CCSprite::createWithSpriteFrameName("ctm_Loading_LargeGold.png"); sprite->setScale(scale); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += -135.0f*scale; scalePoint.y += 5.0f*scale; sprite->setPosition(scalePoint); addChild(sprite,2); } CCMenuItem *StoreButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("ctm_Button_17.png"), CCSprite::createWithSpriteFrameName("ctm_Button_17_Down.png"), this, menu_selector(Loading::storeButtonTapped)); StoreButton->setScale(scale); scalePoint = ccp(0,0); scalePoint.x += 85.0f*scale; scalePoint.y += -100.0f*scale; StoreButton->setPosition(scalePoint); CCMenu* menu = CCMenu::create(StoreButton, NULL); menu->setPosition(ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER)); addChild(menu,4); CCMenuItemSprite *items[3]; //if(SaveLoad::m_SaveData.numDoubleNuts) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::nutsButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use 2X Peanuts","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[1] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_17_2X-peanuts.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numDoubleNuts) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } //if(SaveLoad::m_SaveData.numLevelFire) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::fireButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use Permanent Fire","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[2] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_18_Fire.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numLevelFire) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } //if(SaveLoad::m_SaveData.numTimeSlow) { CCSize dim; dim.width = 200.0f; dim.height = 35.0f; CCSprite *barImage = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); CCSprite *barImageSel = CCSprite::create("ctm_UI_smallGreyStrip_ver1.png"); barImage->setOpacity(0); barImageSel->setOpacity(0); CCMenuItemSprite *menuImage = CCMenuItemSprite::create(barImage,barImageSel,this,menu_selector(Loading::timeButtonTapped)); CCLabelTTF *blabel = CCLabelTTF::create(" Use Slow Clock","Jacoby ICG Black.ttf",18,dim,kCCTextAlignmentLeft); blabel->setColor(ccc3(237,188,0)); blabel->setPosition(ccp(157.0f,18.0f)); menuImage->addChild(blabel,0,1234); items[0] = menuImage; CCSprite *sprite = CCSprite::createWithSpriteFrameName("ctm_icon_Store_16_Slow-Clock.png"); sprite->setPosition(ccp(30,23)); sprite->setScale(0.925f); menuImage->addChild(sprite,0,4321); menuImage->setScale(scale); if(!SaveLoad::m_SaveData.numTimeSlow) { //[menuImage setIsEnabled:NO]; blabel->setColor(ccc3(237/2,188/2,0)); sprite->setColor(ccc3(128,128,128)); } } CCMenu *powerUpMenu = CCMenu::create(items[0], items[1], items[2], NULL); powerUpMenu->alignItemsVerticallyWithPadding(-10.0); scalePoint = ScreenHelper::getAnchorPoint(ScreenHelper::ANCHOR_CENTER); scalePoint.x += 100.0f*scale; scalePoint.y += 10.0f*scale; powerUpMenu->setPosition(scalePoint); addChild(powerUpMenu); m_TimeOut = 3.0f; scheduleUpdate(); }
bool LeaderBoard::init() { if (!CCLayer::init()) return false; //float iMenuWidthOffset = 0.55; SCREEN_WIDTH = CCDirector::sharedDirector()->getWinSize().width; SCREEN_HEIGHT = CCDirector::sharedDirector()->getWinSize().height; CCSprite* bgsprite =ThemeManager::sharedInstance()->spriteWithImageFile("leaderboard.png"); bgsprite->setScaleX(SCREEN_WIDTH/bgsprite->getContentSize().width); bgsprite->setScaleY(SCREEN_HEIGHT/bgsprite->getContentSize().height); bgsprite->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)); this->addChild(bgsprite,1); CCSprite* updateNicknamelb =ThemeManager::sharedInstance()->spriteWithImageFile("btn_update_nickname.png"); CCSprite* updateNicknameSelectedlb =ThemeManager::sharedInstance()->spriteWithImageFile("btn_update_nickname.png"); updateNicknameSelectedlb->setScale(1.1); CCMenuItemSprite* pupdateNicknameItemSpritelb = CCMenuItemSprite::itemWithNormalSprite(updateNicknamelb, updateNicknameSelectedlb, this, menu_selector(LeaderBoard::updateNicknameClick)); pupdateNicknameItemSpritelb->setScale(LL_BUTTON_SCALE_VALUE); CCMenu* pupdateNicknameMenu = CCMenu::menuWithItems(pupdateNicknameItemSpritelb,NULL); pupdateNicknameMenu->setPosition(ccp(SCREEN_WIDTH*0.3, SCREEN_HEIGHT*0.15)); this->addChild(pupdateNicknameMenu, 3); CCSprite* back2menuNormallb =ThemeManager::sharedInstance()->spriteWithImageFile("back2menu.png"); CCSprite* back2menuSelectedlb =ThemeManager::sharedInstance()->spriteWithImageFile("back2menu.png"); back2menuSelectedlb->setScale(1.1); CCMenuItemSprite* pback2menuItemSpritelb = CCMenuItemSprite::itemWithNormalSprite(back2menuNormallb, back2menuSelectedlb, this, menu_selector(LeaderBoard::back2menuClick)); pback2menuItemSpritelb->setScale(LL_BUTTON_SCALE_VALUE); CCMenu* pback2menuMenu = CCMenu::menuWithItems(pback2menuItemSpritelb,NULL); pback2menuMenu->setPosition(ccp(SCREEN_WIDTH*0.7, SCREEN_HEIGHT*0.15)); this->addChild(pback2menuMenu, 3); CCLayer *bg = CCLayer::create(); bg->setContentSize(CCSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT*0.58)); bg->setAnchorPoint(ccp(0,0)); bg->setPosition(ccp(0,0)); char buff[16]; *buff = 0; for(int i=0;i<10;i++){ int offsetHeight = SCREEN_HEIGHT*(0.63125-0.0583*i-0.08); sprintf(buff,"%d ",i+1); scoreLabel=CCLabelTTF::labelWithString(buff,CCSizeMake(300*LL_SCREEN_SCALE_VALUE,32), kCCTextAlignmentLeft,kCCVerticalTextAlignmentCenter,ThemeManager::sharedInstance()->getFontName(),36*LL_SCREEN_SCALE_VALUE); scoreLabel->setPosition(ccp(SCREEN_WIDTH*0.43,offsetHeight)); scoreLabel->setColor(ThemeManager::sharedInstance()->getColor()); bg->addChild(scoreLabel, 4); scoreLabel=CCLabelTTF::labelWithString(getNicknameByRank(i+1),CCSizeMake(300*LL_SCREEN_SCALE_VALUE,32), kCCTextAlignmentLeft,kCCVerticalTextAlignmentCenter,ThemeManager::sharedInstance()->getFontName(),36*LL_SCREEN_SCALE_VALUE); scoreLabel->setPosition(ccp(SCREEN_WIDTH*0.50,offsetHeight)); scoreLabel->setColor(ThemeManager::sharedInstance()->getColor()); bg->addChild(scoreLabel, 4); sprintf(buff,"%d ",getScore(i+1)); scoreLabel=CCLabelTTF::labelWithString(buff,CCSizeMake(150*LL_SCREEN_SCALE_VALUE,32), kCCTextAlignmentRight,kCCVerticalTextAlignmentCenter,ThemeManager::sharedInstance()->getFontName(),36*LL_SCREEN_SCALE_VALUE); scoreLabel->setPosition(ccp(SCREEN_WIDTH*0.78,offsetHeight)); scoreLabel->setColor(ThemeManager::sharedInstance()->getColor()); bg->addChild(scoreLabel, 4); } CCScrollView * view = CCScrollView::create(CCSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT*0.35), bg); view->setDirection(kCCScrollViewDirectionVertical); view->setContentSize( CCSizeMake(SCREEN_WIDTH,SCREEN_HEIGHT*0.58) ); view->setContentOffset(ccp(0,-SCREEN_HEIGHT*0.226)); view->setAnchorPoint(ccp(0,0)); view->setPosition(0,SCREEN_HEIGHT*0.305); this->addChild(view,4); sprintf(buff,"%d ",getBestScore()); scoreLabel=CCLabelTTF::labelWithString(buff,CCSizeMake(150*LL_SCREEN_SCALE_VALUE,32), kCCTextAlignmentRight,kCCVerticalTextAlignmentCenter,ThemeManager::sharedInstance()->getFontName(),36*LL_SCREEN_SCALE_VALUE); scoreLabel->setPosition(ccp(SCREEN_WIDTH*0.78,SCREEN_HEIGHT*(0.62725-0.0583*6))); scoreLabel->setColor(ThemeManager::sharedInstance()->getColor()); this->addChild(scoreLabel, 4); scoreLabel=CCLabelTTF::labelWithString(getNickname(),CCSizeMake(300*LL_SCREEN_SCALE_VALUE,32), kCCTextAlignmentLeft,kCCVerticalTextAlignmentCenter,ThemeManager::sharedInstance()->getFontName(),36*LL_SCREEN_SCALE_VALUE); scoreLabel->setPosition(ccp(SCREEN_WIDTH*0.51,SCREEN_HEIGHT*(0.62725-0.0583*6))); scoreLabel->setColor(ThemeManager::sharedInstance()->getColor()); this->addChild(scoreLabel, 4); /*char buff2[256]; *buff2 = 0; sprintf(buff2,"%d %s",getUserRank(), getNickname()); scoreLabel=CCLabelTTF::labelWithString(buff2,CCSizeMake(330*LL_SCREEN_SCALE_VALUE,32), kCCTextAlignmentLeft,kCCVerticalTextAlignmentCenter,ThemeManager::sharedInstance()->getFontName(),36*LL_SCREEN_SCALE_VALUE); scoreLabel->setPosition(ccp(SCREEN_WIDTH*0.43,SCREEN_HEIGHT*(0.63125-0.0583*7))); scoreLabel->setColor(ThemeManager::sharedInstance()->getColor()); this->addChild(scoreLabel, 4);*/ return true; }
bool StageMapLayer::init() { if(!CCLayer::init()) return false; this->ignoreAnchorPointForPosition(false); this->setAnchorPoint(AnchorPointLeftBottom); this->setTouchEnabled(true); this->setTouchMode(kCCTouchesOneByOne); const CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // Background m_Background = CCSprite::createWithSpriteFrameName("mainscene_background.png"); m_Background->retain(); m_Background->cocos2d::CCNode::setPosition(winSize.width / 2, winSize.height / 2); for(int i=0; i<5; ++i) { CCString* fileName = CCString::createWithFormat("mainscene_cloud%d.png", i+1); m_BackgroundCloud[i] = CCSprite::createWithSpriteFrameName(fileName->getCString()); m_BackgroundCloud[i]->retain(); m_Background->addChild(m_BackgroundCloud[i]); CCPoint initialPosition = CCPointMake(RandomNumberGenerator::Int(0, static_cast<INT>(winSize.width)), RandomNumberGenerator::Int(30.f, INT(winSize.height*0.9f))); m_BackgroundCloud[i]->setPosition(initialPosition); // Cloud Moving Animation const CCSize cloudSize = m_BackgroundCloud[i]->getContentSize(); const float speed = 5+ static_cast<float>(RandomNumberGenerator::Int(0, 25)); // pixel/sec const float timeToLeftEnd = (initialPosition.x+cloudSize.width*0.5f)/speed; const float timeToRepeatLeft = (winSize.width+cloudSize.width)/speed; CCSprite* cloudNode = m_BackgroundCloud[i]; CCMoveTo* moveToLeftEnd = CCMoveTo::create(timeToLeftEnd, ccp(-cloudSize.width*0.5f, initialPosition.y)); CCCallFuncL* moveToRightEnd = CCCallFuncL::create([winSize, cloudNode, cloudSize, initialPosition]() { if( cloudNode ) { cloudNode->setPosition(ccp(winSize.width+cloudSize.width*0.5f,initialPosition.y)); } }); CCMoveTo* moveToLeftEndRepeat = CCMoveTo::create(timeToRepeatLeft, ccp(-cloudSize.width*0.5f, initialPosition.y)); CCSequence* moveToRightAndLeftEnd = CCSequence::create(moveToRightEnd, moveToLeftEndRepeat, nullptr); CCRepeat* moveToRightAndLeftEndRepeat = CCRepeat::create(moveToRightAndLeftEnd, 20); CCSequence* moveSeq = CCSequence::create(moveToLeftEnd, moveToRightAndLeftEndRepeat, nullptr); cloudNode->runAction(moveSeq); // End Cloud Moving Animation } m_Top = CCSprite::createWithSpriteFrameName("mainscene_top.png"); m_Top->retain(); const CCSize topSpriteSize = m_Top->getContentSize(); m_Top->setPosition(ccp(winSize.width*0.5f, winSize.height-topSpriteSize.height*0.5f)); m_Bottom = CCSprite::createWithSpriteFrameName("mainscene_bottom.png"); m_Bottom->retain(); const CCSize bottomSpriteSize = m_Bottom->getContentSize(); m_Bottom->setPosition(ccp(winSize.width*0.5f, bottomSpriteSize.height*0.5f)); //End Background this->addChild(m_Background, StageMapLayerDepth_Background); this->addChild(m_Top, StageMapLayerDepth_UIComponents); this->addChild(m_Bottom, StageMapLayerDepth_UIComponents); // Number Of Carrots m_Carrot = CCSprite::createWithSpriteFrameName("mainscene_carrot_stat.png"); m_Carrot->retain(); const CCSize carrotSize = m_Carrot->getContentSize(); m_Carrot->setPosition(ccp( 5.f+carrotSize.width/2.f, winSize.height-carrotSize.height/2.f-5.f)); this->addChild(m_Carrot, StageMapLayerDepth_UIComponents); m_Clover = CCSprite::createWithSpriteFrameName("mainscene_clover_stat.png"); m_Clover->retain(); const CCSize cloverSize = m_Clover->getContentSize(); m_Clover->setPosition(ccp( 5.f + carrotSize.width +10.f + cloverSize.width*0.5f, winSize.height-cloverSize.height*0.5f - 5.f)); this->addChild(m_Clover, StageMapLayerDepth_UIComponents); User* myUser = GooRoomClient::Instance().GetUser(); if( myUser != nullptr ) { m_NumberOfCarrots = CCLabelTTF::create(CCString::createWithFormat("%lld",myUser->GetGold())->getCString(), fontList[0].c_str(), 13); m_NumberOfCarrots->retain(); m_NumberOfCarrots->setColor(ccBLACK); const CCSize numberOfCarrotsSize = m_NumberOfCarrots->getContentSize(); m_NumberOfCarrots->setPosition(ccp(5.f+carrotSize.width*0.5f, m_Carrot->getPositionY()-2.f)); this->addChild(m_NumberOfCarrots, StageMapLayerDepth_UIComponents); } // END BASE m_MapBase = CCNode::create(); m_MapBase->retain(); m_MapBase->setContentSize(winSize); m_MapBase->setAnchorPoint(AnchorPointMidBottom); m_MapBase->setPosition(ccp(winSize.width/2.f, 0.f)); this->addChild(m_MapBase,StageMapLayerDepth_MapBase); m_StageInfoBox = CCSprite::createWithSpriteFrameName("stagemap_info_box.png"); m_StageInfoBox->retain(); m_StageInfoBox->setAnchorPoint(AnchorPointMid); const CCSize stageInfoBoxSize = m_StageInfoBox->getContentSize(); m_StageInfoBox->setPosition(ccp(winSize.width*0.5f, stageInfoBoxSize.height*0.5f)); m_Bottom->addChild(m_StageInfoBox,StageMapLayerDepth_UIComponents); StageInfoDictionary::Instance().ForEachStageInfo([this](StageInfo* stageInfo) { this->AddStageMapPoint(*stageInfo); }); CharacterData characterData = *CharacterDictionary::Instance().GetCharacterData(GooRoomClient::Instance().GetUser()->GetSelectedCharacterType()); characterData.SetLevel(GooRoomClient::Instance().GetUser()->GetSelectedCharacterCard().GetLevel()); m_MyPlayer = PlayerNode::create(characterData, ActorID_None, GooRoomClient::Instance().GetUser()->GetUserName().c_str(), TeamType_None); m_MyPlayer->retain(); m_MyPlayer->setPosition((m_StageMapPointList.front()->getPosition()+m_PlayerPositionOffset)); m_MyPlayer->setAnchorPoint(CharacterAnchorPoint); m_MapBase->addChild(m_MyPlayer); StageInfo* stageInfo = StageInfoDictionary::Instance().FindStageInfo(0); m_MissionBox = MissionBox::create(*stageInfo); m_MissionBox->retain(); m_MissionBox->setAnchorPoint(AnchorPointLeftBottom); const CCSize missionBoxSize = m_MissionBox->getContentSize(); m_MissionBox->setPosition(ccp(missionBoxSize.width*0.5f, missionBoxSize.height*0.5f)); this->addChild(m_MissionBox, StageMapLayerDepth_UIComponents); m_TitleBox = TitleBox::create(*stageInfo); m_TitleBox->retain(); m_TitleBox->setAnchorPoint(AnchorPointLeftBottom); const CCSize titleBoxSize = m_TitleBox->getContentSize(); m_TitleBox->setPosition(ccp(winSize.width-titleBoxSize.width*0.5f, titleBoxSize.height*0.5f+5.f)); this->addChild(m_TitleBox, StageMapLayerDepth_UIComponents); // Create Button m_CreateStage = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("create_button.png"), CCSprite::createWithSpriteFrameName("create_button_pushed.png"), this, menu_selector(StageMapLayer::OnCreateStageTouch)); m_CreateStage->retain(); m_MenuCreateStage = CCMenu::create(m_CreateStage, nullptr); m_MenuCreateStage->retain(); m_MenuCreateStage->setAnchorPoint(AnchorPointMid); const CCSize menuItemSize = m_CreateStage->getContentSize(); m_MenuCreateStage->setPosition(ccp(winSize.width-menuItemSize.width/2.f-40.f, menuItemSize.height/2.f+10.f)); this->addChild(m_MenuCreateStage, StageMapLayerDepth_UIComponents); // End Create Button // Exit Button CCMenuItemSprite* exitButton = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("exit_button.png"),CCSprite::createWithSpriteFrameName("exit_button_pushed.png"), this, menu_selector(StageMapLayer::OnExitButtonTouch)); CCMenu* exitMenu = CCMenu::create(exitButton, NULL); CCSize exitButtonSize = exitButton->getContentSize(); exitMenu->setPosition(winSize.width-exitButtonSize.width/2.f-5.f, winSize.height-exitButtonSize.height/2.f-5.f); this->addChild(exitMenu, StageMapLayerDepth_UIComponents); // Shop Menu { CCSprite* shopSprite = CCSprite::createWithSpriteFrameName("mainscene_blank_button.png"); CCSprite* shopPushedSprite = CCSprite::createWithSpriteFrameName("mainscene_blank_button_pushed.png"); CCMenuItemSprite* shopButton = CCMenuItemSprite::create(shopSprite, shopPushedSprite, this, menu_selector(StageMapLayer::OnShopButtonTouch)); CCLabelTTF* shopLabel = CCLabelTTF::create("구르몽 친구들", fontList[0].c_str(), 14); shopLabel->setColor(ccBLACK); shopLabel->setAnchorPoint(AnchorPointMid); const CCSize shopSpriteSize = shopSprite->getContentSize(); shopLabel->setPosition(ccp(shopSpriteSize.width*0.5f, shopSpriteSize.height*0.5f)); shopSprite->addChild(shopLabel); shopButton->setScale(0.85f); CCMenu* shopMenu = CCMenu::create(shopButton, nullptr); shopMenu->setPosition(ccp(winSize.width-shopSpriteSize.width*0.5f - 5.f, winSize.height-exitButtonSize.height - 5.f -shopSpriteSize.height*0.5f -10.f)); this->addChild(shopMenu, StageMapLayerDepth_UIComponents); } StageLevel currentStageLevel = GooRoomClient::Instance().GetUser()->GetStageLevel(); if( currentStageLevel >= m_StageMapPointList.size() ) { currentStageLevel = m_StageMapPointList.size()-1; } this->SelectStageMapPoint(currentStageLevel-1, false); this->SelectStageMapPoint(currentStageLevel, true); this->scheduleUpdate(); return true; }
bool MainLayer::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayer::init()); ////////////////////////////////////////////////////////////////////////// // add your codes below... ////////////////////////////////////////////////////////////////////////// CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("PlayBox.plist", "PlayBox.png"); cache->addSpriteFramesWithFile("resources.plist"); // 1. Add a menu item with "X" image, which is clicked to quit the program. // Create a "close" menu item with close icon, it's an auto release object. CCMenuItemSprite *pCloseItem = CCMenuItemSprite::create( CCSprite::createWithSpriteFrameName("close.png"), NULL, this, menu_selector(MainLayer::menuCloseCallback)); CC_BREAK_IF(! pCloseItem); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); // Place the menu item bottom-right conner. pCloseItem->setPosition(ccp(winSize.width - 64, winSize.height - 64)); pCloseItem->setScale(2.0f); // Create a menu with the "close" menu item, it's an auto release object. CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); CC_BREAK_IF(! pMenu); // Add the menu to Main layer as a child layer. this->addChild(pMenu, 1); CCLabelTTF* label = CCLabelTTF::create("DreamBook", "Arial", 46); CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MainLayer::menuDreamBookCallback)); pMenu = CCMenu::create(pMenuItem, NULL); label = CCLabelTTF::create("PhysicsTech", "Arial", 46); pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MainLayer::menuPhysicsTechCallback)); pMenu->addChild(pMenuItem); label = CCLabelTTF::create("ToyBrick", "Arial", 46); pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MainLayer::menuToyBrickCallback)); pMenu->addChild(pMenuItem); label = CCLabelTTF::create("DancingBone", "Arial", 46); pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MainLayer::menuDancingBoneCallback)); pMenu->addChild(pMenuItem); label = CCLabelTTF::create("Boy Model", "Arial", 46); pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MainLayer::menuPhysicalBodyCallback)); pMenu->addChild(pMenuItem); label = CCLabelTTF::create("Kong Rong Gave Away Bigger Pear", "Arial", 46); pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MainLayer::menuKongRongCallback)); pMenu->addChild(pMenuItem); label = CCLabelTTF::create("Dock Test", "Arial", 46); pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(MainLayer::menuEFTestCallback)); pMenu->addChild(pMenuItem); pMenu->alignItemsVertically(); this->addChild(pMenu); pMenu->setPosition(ccp(winSize.width * 0.5F, winSize.height * 0.6F)); /*this->lbDebug = CCLabelTTF::create("Start", "Arial", 24); this->lbDebug->setColor(ccc3(255, 255, 1)); this->lbDebug->setPosition(ccp(0, winSize.height - 100)); this->lbDebug->setAnchorPoint(CCPointZero); this->addChild(this->lbDebug);*/ //add Whislly test start /*cocos2d::extension::Parse parse; parse.setApplicationId("n1s82tGoQDgDM09qFNm0UQkKNO7yW1gqpQSavT5n"); parse.setApiKey("Nh4K6HM2tohkmQdeu5vfN7ZWP83OMQ72uH0YMtW7"); parse.setMasterKey("doMxP88XvGkICRrI3gPcCdwWMI26QZfzPMKER33m");*/ //ParseFile* file = new ParseFile(); /*file->uploadFileCompleted.Set(this, (Delegate<FileInfo*, ParseError*>::MemberFun)&MainLayer::UploadComplet); file->uploadFile("D:", "smbios.zip");*/ //file->downloadFile("http://files.parse.com/148a2d0f-6637-47cf-b4d1-0c2083de23ef/03e0430a-ee2f-4e36-81fa-48c91607afa7-smbios.zip","D:\\Test.zip"); //file->deleteFile("03e0430a-ee2f-4e36-81fa-48c91607afa7-smbios.zip"); //file->release(); /* cocos2d::extension::ParseQuery* query = new cocos2d::extension::ParseQuery("GameTest"); query->findObjectsCompleted.Set(this, (Delegate<CCArray*, ParseError*>::MemberFun)&MainLayer::GetComplet); query->findObjects(); query->release();*/ CC_BREAK_IF(! pMenu); bRet = true; } while (0); return bRet; }
// on "init" you need to initialize your instance bool GameLayer::init() { if (!CCLayer::init()) return false; SCREEN_WIDTH = CCDirector::sharedDirector()->getWinSize().width; SCREEN_HEIGHT = CCDirector::sharedDirector()->getWinSize().height; bPaused = false; //Jerry--LB receiveRank(); CCSprite* sprite = ThemeManager::sharedInstance()->spriteWithImageFile("background.png");//ThemeManager::sharedInstance()->spriteWithImageFile("background.png"); sprite->setScaleX(SCREEN_WIDTH/sprite->getContentSize().width); sprite->setScaleY(SCREEN_HEIGHT/sprite->getContentSize().height); sprite->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)); this->addChild(sprite,1); float iMenuWidthOffset = 0.55; CCSprite* startNormal = ThemeManager::sharedInstance()->spriteWithImageFile("menu_start.png"); CCSprite* startSelected = ThemeManager::sharedInstance()->spriteWithImageFile("menu_start.png"); CCMenuItemSprite* pStartItemSprite = CCMenuItemSprite::itemWithNormalSprite(startNormal, startSelected, this, menu_selector(GameLayer::startButtonClick)); CCMenu* pStartMenu = CCMenu::menuWithItems(pStartItemSprite,NULL); pStartMenu->setPosition(ccp(SCREEN_WIDTH*iMenuWidthOffset, SCREEN_HEIGHT*0.6)); pStartItemSprite->setScale(LL_BUTTON_SCALE_VALUE); //Jerry--Action CCScaleTo* large=CCScaleTo::actionWithDuration(0.5,0.7*LL_SCREEN_SCALE_VALUE); CCScaleTo* small=CCScaleTo::actionWithDuration(0.5,LL_BUTTON_SCALE_VALUE); CCDelayTime *waiting=CCDelayTime::actionWithDuration(1.0f); CCFiniteTimeAction* action= CCSequence::actions(waiting,large,small,waiting,NULL); CCActionInterval* actionShake=CCRepeatForever::actionWithAction((CCActionInterval*)action); pStartItemSprite->stopAllActions(); pStartItemSprite->runAction(actionShake); this->addChild(pStartMenu, 3); /*CCSprite* leaderboardNormal = ThemeManager::sharedInstance()->spriteWithImageFile("menu_leaderboard.png"); CCSprite* leaderboardSelected = ThemeManager::sharedInstance()->spriteWithImageFile("menu_leaderboard.png"); CCSprite* leaderboardDisabled = ThemeManager::sharedInstance()->spriteWithImageFile("menu_leaderboard.png"); CCMenuItemSprite* pleaderboardItemSprite = CCMenuItemSprite::itemWithNormalSprite(leaderboardNormal, leaderboardSelected, leaderboardDisabled, this, menu_selector(GameLayer::levelButtonClick)); pleaderboardItemSprite->setScale(0.8); CCMenu* pleaderboardMenu = CCMenu::menuWithItems(pleaderboardItemSprite,NULL); pleaderboardMenu->setPosition(ccp(SCREEN_WIDTH*iMenuWidthOffset, SCREEN_HEIGHT*0.4)); this->addChild(pleaderboardMenu, 3);*/ CCSprite* instructionNormal = ThemeManager::sharedInstance()->spriteWithImageFile("menu_instruction.png"); CCSprite* instructionSelected = ThemeManager::sharedInstance()->spriteWithImageFile("menu_instruction.png"); CCMenuItemSprite* pinstructionItemSprite = CCMenuItemSprite::itemWithNormalSprite(instructionNormal, instructionSelected,this, menu_selector(GameLayer::instructionButtonClick)); pinstructionItemSprite->setScale(LL_BUTTON_SCALE_VALUE); CCMenu* pinstructionMenu = CCMenu::menuWithItems(pinstructionItemSprite,NULL); pinstructionMenu->setPosition(ccp(SCREEN_WIDTH*iMenuWidthOffset, SCREEN_HEIGHT*0.5)); this->addChild(pinstructionMenu, 3); CCSprite* quitNormal = ThemeManager::sharedInstance()->spriteWithImageFile("menu_quit.png"); CCSprite* quitSelected = ThemeManager::sharedInstance()->spriteWithImageFile("menu_quit.png"); quitSelected->setScale(1.1); CCMenuItemSprite* pquitItemSprite = CCMenuItemSprite::itemWithNormalSprite(quitNormal, quitSelected, this, menu_selector(GameLayer::finishButtonClick)); pquitItemSprite->setScale(LL_BUTTON_SCALE_VALUE); CCMenu* pquitMenu = CCMenu::menuWithItems(pquitItemSprite,NULL); pquitMenu->setPosition(ccp(SCREEN_WIDTH*iMenuWidthOffset, SCREEN_HEIGHT*0.2)); this->addChild(pquitMenu, 3); //Jerry--Code CCSprite* lbNormal = ThemeManager::sharedInstance()->spriteWithImageFile("menu_leaderboard.png"); CCSprite* lbSelected = ThemeManager::sharedInstance()->spriteWithImageFile("menu_leaderboard.png"); lbSelected->setScale(1.1); CCMenuItemSprite* plbItemSprite = CCMenuItemSprite::itemWithNormalSprite(lbNormal, lbSelected, this, menu_selector(GameLayer::leaderboardButtonClick)); plbItemSprite->setScale(LL_BUTTON_SCALE_VALUE); CCMenu* plbMenu = CCMenu::menuWithItems(plbItemSprite,NULL); plbMenu->setPosition(ccp(SCREEN_WIDTH*iMenuWidthOffset, SCREEN_HEIGHT*0.4)); this->addChild(plbMenu, 3); //Jerry--Code CCSprite* thNormal = ThemeManager::sharedInstance()->spriteWithImageFile("menu_theme.png"); CCSprite* thSelected = ThemeManager::sharedInstance()->spriteWithImageFile("menu_theme.png"); thSelected->setScale(1.1); CCMenuItemSprite* pthItemSprite = CCMenuItemSprite::itemWithNormalSprite(thNormal, thSelected, this, menu_selector(GameLayer::themeButtonClick)); pthItemSprite->setScale(LL_BUTTON_SCALE_VALUE); CCMenu* pthMenu = CCMenu::menuWithItems(pthItemSprite,NULL); pthMenu->setPosition(ccp(SCREEN_WIDTH*iMenuWidthOffset, SCREEN_HEIGHT*0.3)); this->addChild(pthMenu, 3); if(getFlags("INPUT_NICKNAME_FLAG") == 0) { updateNickname(NULL); setFlags("INPUT_NICKNAME_FLAG", 1); } //InitBdAd(); //showDoSplash(); PlatformManager::sharedInstance()->showBanner(); PlatformManager::sharedInstance()->showInter(); //showDoBanner(); return true; }
// on "init" you need to initialize your instance bool StartMenu::init() { ////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCTexture2D *shipTexture = CCTextureCache::sharedTextureCache()->addImage(s_ship01); // 添加Android的按键处理,这里加了全局代理 this->setKeypadEnabled(true); CostomeKeyPadDelegae *keyDelegate = new CostomeKeyPadDelegae(); keyDelegate->autorelease(); CCDirector::sharedDirector()->getKeypadDispatcher()->addDelegate(keyDelegate); ////////////////// // 2. add main menu ,logo, loading, and ships winSize = CCDirector::sharedDirector()->getWinSize(); CCSprite* sl = CCSprite::create(s_loading); sl->setAnchorPoint(ccp(0, 0)); this->addChild(sl,0,1); CCSprite* logo = CCSprite::create(s_logo); logo->setAnchorPoint(ccp(0.5, 1)); logo->setPosition(ccp(winSize.width/2, winSize.height-100)); this->addChild(logo, 10, 1); CCSprite* newGameNormal = CCSprite::create(s_menu, CCRectMake(0, 0, 126, 33)); CCSprite* newGameSelected = CCSprite::create(s_menu, CCRectMake(0, 33, 126, 33)); CCSprite* newGameDisabled = CCSprite::create(s_menu, CCRectMake(0, 33*2, 126, 33)); CCSprite* gameSettingNormal = CCSprite::create(s_menu, CCRectMake(126, 0, 126, 33)); CCSprite* gameSettingNSelected = CCSprite::create(s_menu, CCRectMake(126, 33, 126, 33)); CCSprite* gameSettingDesabled = CCSprite::create(s_menu, CCRectMake(126, 33*2, 126, 33)); CCSprite* aboutNormal = CCSprite::create(s_menu, CCRectMake(252, 0, 126, 33)); CCSprite* aboutSelected = CCSprite::create(s_menu, CCRectMake(252, 33, 126, 33)); CCSprite* aboutDesabled = CCSprite::create(s_menu, CCRectMake(252, 33*2, 126, 33)); CCMenuItemSprite* newGame = CCMenuItemSprite::create(newGameNormal, newGameSelected, newGameDisabled, this, menu_selector(StartMenu::flareEffect)); newGame->setScale(1.5f); CCMenuItemSprite* gameSetting = CCMenuItemSprite::create(gameSettingNormal, gameSettingNSelected, gameSettingDesabled, this, menu_selector(StartMenu::menuCallback)); gameSetting->setScale(1.5f); gameSetting->setTag(20); CCMenuItemSprite* about = CCMenuItemSprite::create(aboutNormal, aboutSelected, aboutDesabled, this, menu_selector(StartMenu::menuCallback)); about->setScale(1.5f); about->setTag(21); // 最后一个参数要是NULL CCMenu* menu = CCMenu::create(newGame, gameSetting, about, NULL); menu->alignItemsVerticallyWithPadding(30); this->addChild(menu, 1, 2); menu->setPosition(ccp(winSize.width / 2, winSize.height / 2 - 80)); this->schedule(schedule_selector(StartMenu::update), 0.1); // ships CCTexture2D *textCache = CCTextureCache::sharedTextureCache()->textureForKey(s_ship01); m_ship = CCSprite::createWithTexture(textCache, CCRectMake(0, 45, 60, 38)); this->addChild(m_ship, 0, 4); CCPoint position = ccp(CCRANDOM_0_1() * winSize.width, 0); m_ship->setPosition(position); m_ship->runAction(CCMoveBy::create(2, ccp(CCRANDOM_0_1() * winSize.width, position.y + winSize.height + 100))); if (Config::sharedConfig()->getAudioState()&&!Config::sharedConfig()->isOptions()&&!Config::sharedConfig()->isAbout()) { SimpleAudioEngine::sharedEngine()->setBackgroundMusicVolume(0.7); SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_mainMainMusic, true); } Config::sharedConfig()->setOptions(false); Config::sharedConfig()->setAbout(false); CCSprite* fragment = CCSprite::create(); fragment->initWithFile(s_fragment); this->addChild(fragment,1000); fragment->setPosition(ccp(240,300)); CCOrbitCamera * orbit = CCOrbitCamera::create(0.3, 1, 0, 0, 360, 0, 0);//(8, 1, 0, 0, 360, 90, -45) fragment->runAction(CCRepeatForever::create(orbit)); ///////////////////////////////////////////////////////////////////////////// CCSprite *sprite = CCSprite::create(); sprite->initWithFile(s_fire); this->addChild(sprite,10); sprite->setPosition(ccp(100,200)); CCMyParticleSun *system = CCMyParticleSun::create(); sprite->addChild(system,10); CCSize size = sprite->getContentSize(); system->setPosition(ccp(size.width/2,size.height/2)); CCMoveBy *by = CCMoveBy::create(5,ccp(400,100)); CCFiniteTimeAction *seq = CCSequence::create(by, by->reverse(), NULL); sprite->runAction(CCRepeatForever::create((CCActionInterval*)seq)); /* CCTexture2D *temp = CCTextureCache::sharedTextureCache()->addImage(s_boss_one); CCTexture2D* texture = Util::getGrayTexture(temp); // create a new CCSprite to return CCSprite* s = CCSprite::create(); s->initWithTexture(texture); addChild(s,1000); s->setPosition(ccp(200,100)); */ return true; }
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; }
void RPGBattleMenu::onMenu(cocos2d::CCObject *pObject) { CCMenuItem *menuItem = (CCMenuItem*)pObject; SimpleAudioEngine::sharedEngine()->playEffect("audio_effect_btn.wav"); switch (menuItem->getTag()) { case kRPGBattleMenuTagSkill: { CCLog("技能"); this->hideMenu(); this->m_selectedMenuTag = kRPGBattleMenuTagSkill; CCMenuItemSprite *menuCancel = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGBattleMenu::onMenu)); menuCancel->setPosition(ccp(43, 596)); menuCancel->setTag(kRPGBattleMenuTagCancel); menuCancel->setScale(0.75); this->addChild(menuCancel); CCTMXTiledMap *selectLayer = CCTMXTiledMap::create(CCString::createWithFormat("battle_select_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString()); selectLayer->setPosition(ccp((CCDirector::sharedDirector()->getWinSize().width - selectLayer->getContentSize().width) / 2, (CCDirector::sharedDirector()->getWinSize().height - selectLayer->getContentSize().height) / 2)); selectLayer->setTag(kRPGBattleSceneLayerTagSkillSelectDialog); ((RPGBattleSceneLayer*)this->m_parentNode)->addChild(selectLayer); ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(true); //显示title和分隔线 addLab(selectLayer, 199, (CCString*)this->m_stringList->objectForKey("skill_title"), 25, ccp(310, 285)); CCLabelTTF *titleLab = (CCLabelTTF*)selectLayer->getChildByTag(199); titleLab->setFontFillColor(ccc3(144, 144, 144)); CCSprite *separate = CCSprite::createWithSpriteFrameName("separate.png"); separate->setPosition(ccp(selectLayer->getContentSize().width / 2, 260)); separate->setScaleX(0.65); separate->setTag(198); selectLayer->addChild(separate); //加载技能数据 CCTableView *tableView = (CCTableView*)selectLayer->getChildByTag(197); if(!tableView) { tableView = CCTableView::create(this, ccp(selectLayer->getContentSize().width, selectLayer->getContentSize().height - 80)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(CCSizeZero); tableView->setDelegate(this); tableView->setVerticalFillOrder(kCCTableViewFillTopDown); tableView->setTag(197); selectLayer->addChild(tableView); } this->m_tableItems->removeAllObjects(); string wq = ""; JsonBox::Value json; json.loadFromString(this->m_playerData->m_skill.c_str()); JsonBox::Array jsonArr = json.getArray(); for (int i = 0; i < jsonArr.size(); i++) { char* str = (char*)malloc(10 * sizeof(char)); OzgCCUtility::itoa(jsonArr[i].getInt(), str); wq.append(str); if(i + 1 < jsonArr.size()) wq.append(", "); free(str); } if((int)wq.length() > 0) { CppSQLite3Query query = this->m_db->execQuery(CCString::createWithFormat(SKILL_QUERY, wq.c_str())->getCString()); while(!query.eof()) { RPGSkillBtnData *skill = RPGSkillBtnData::create(); skill->m_dataId = query.getIntField("id"); skill->m_name = query.getStringField("name_cns"); skill->m_MP = query.getIntField("mp"); skill->m_skillAttack = query.getIntField("skill_attack"); skill->m_type = query.getIntField("type"); skill->m_attr = query.getIntField("attr"); skill->m_enabled = true; //不能使用技能的情况 if(this->m_playerData->m_MP <= 0 || this->m_playerData->m_HP <= 0) skill->m_enabled = false; else if(this->m_playerData->m_MP < skill->m_MP) skill->m_enabled = false; this->m_tableItems->addObject(skill); query.nextRow(); } query.finalize(); } tableView->reloadData(); //加载技能数据 end ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(false); } break; case kRPGBattleMenuTagItems: { CCLog("道具"); this->hideMenu(); this->m_selectedMenuTag = kRPGBattleMenuTagItems; CCMenuItemSprite *menuCancel = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGBattleMenu::onMenu)); menuCancel->setPosition(ccp(43, 596)); menuCancel->setTag(kRPGBattleMenuTagCancel); menuCancel->setScale(0.75); this->addChild(menuCancel); CCTMXTiledMap *selectLayer = CCTMXTiledMap::create(CCString::createWithFormat("battle_select_%s.tmx", CCUserDefault::sharedUserDefault()->getStringForKey(GAME_STYLE).c_str())->getCString()); selectLayer->setPosition(ccp((CCDirector::sharedDirector()->getWinSize().width - selectLayer->getContentSize().width) / 2, (CCDirector::sharedDirector()->getWinSize().height - selectLayer->getContentSize().height) / 2)); selectLayer->setTag(kRPGBattleSceneLayerTagItemsSelectDialog); ((RPGBattleSceneLayer*)this->m_parentNode)->addChild(selectLayer); ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(true); //显示title和分隔线 addLab(selectLayer, 199, (CCString*)this->m_stringList->objectForKey("items_title"), 25, ccp(310, 285)); CCLabelTTF *titleLab = (CCLabelTTF*)selectLayer->getChildByTag(199); titleLab->setFontFillColor(ccc3(144, 144, 144)); CCSprite *separate = CCSprite::createWithSpriteFrameName("separate.png"); separate->setPosition(ccp(selectLayer->getContentSize().width / 2, 260)); separate->setScaleX(0.65); separate->setTag(198); selectLayer->addChild(separate); //加载道具数据 CCTableView *tableView = (CCTableView*)selectLayer->getChildByTag(197); if(!tableView) { tableView = CCTableView::create(this, ccp(selectLayer->getContentSize().width, selectLayer->getContentSize().height - 80)); tableView->setDirection(kCCScrollViewDirectionVertical); tableView->setPosition(CCSizeZero); tableView->setDelegate(this); tableView->setVerticalFillOrder(kCCTableViewFillTopDown); tableView->setTag(197); selectLayer->addChild(tableView); } this->m_tableItems->removeAllObjects(); CCArray *existingItems = ((RPGBattleSceneLayer*)this->m_parentNode)->m_existingItems; for (int i = 0; i < existingItems->count(); i++) this->m_tableItems->addObject(existingItems->objectAtIndex(i)); tableView->reloadData(); //加载道具数据 end ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(false); } break; case kRPGBattleMenuTagEscape: { // CCLog("逃跑"); float success = CCRANDOM_0_1(); if(success >= 0.0 && success <= 0.5) { // CCLog("逃跑成功"); this->setEnabled(false); this->removeFromParentAndCleanup(true); ((RPGBattleSceneLayer*)this->m_parentNode)->goToMap(); } else { ((RPGBattleSceneLayer*)this->m_parentNode)->showMsg((CCString*)this->m_stringList->objectForKey("escape_fail")); //重置进度条 this->m_playerData->m_progress = 0.0; CCProgressTimer *battleProgress = (CCProgressTimer*)this->m_parentNode->getChildByTag(kRPGBattleSceneLayerTagPlayerProgress + this->m_playerData->m_dataId); battleProgress->setPercentage(this->m_playerData->m_progress); ((RPGBattleSceneLayer*)this->m_parentNode)->scheduleUpdate(); CCTMXTiledMap *bgLayer = (CCTMXTiledMap*)this->m_parentNode->getChildByTag(kRPGBattleMenuTagBg); bgLayer->removeFromParentAndCleanup(true); this->removeFromParentAndCleanup(true); } } break; case kRPGBattleMenuTagCancel: { // CCLog("取消"); this->showMenu(); CCMenuItem *menuCancel = (CCMenuItem*)this->getChildByTag(kRPGBattleMenuTagCancel); menuCancel->removeFromParentAndCleanup(true); switch (this->m_selectedMenuTag) { case kRPGBattleMenuTagAttack: CCLog("取消攻击"); ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(false); ((RPGBattleSceneLayer*)this->m_parentNode)->cancelAllSelected(); break; case kRPGBattleMenuTagSkill: CCLog("取消技能列表"); if(((RPGBattleSceneLayer*)this->m_parentNode)->getChildByTag(kRPGBattleSceneLayerTagSkillSelectDialog)) ((RPGBattleSceneLayer*)this->m_parentNode)->removeChildByTag(kRPGBattleSceneLayerTagSkillSelectDialog, true); ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(false); ((RPGBattleSceneLayer*)this->m_parentNode)->cancelAllSelected(); break; case kRPGBattleMenuTagItems: CCLog("取消道具列表"); if(((RPGBattleSceneLayer*)this->m_parentNode)->getChildByTag(kRPGBattleSceneLayerTagItemsSelectDialog)) ((RPGBattleSceneLayer*)this->m_parentNode)->removeChildByTag(kRPGBattleSceneLayerTagItemsSelectDialog, true); ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(false); ((RPGBattleSceneLayer*)this->m_parentNode)->cancelAllSelected(); break; // default: // break; } } break; case kRPGBattleMenuTagCancel2: { //这个选择了一个技能或道具后,到了选择目标对象的一步,使用到的取消按钮 CCMenuItemSprite *menuCancel = (CCMenuItemSprite*)this->getChildByTag(kRPGBattleMenuTagCancel); menuCancel->setVisible(true); CCMenuItemSprite *menuCancel2 = (CCMenuItemSprite*)this->getChildByTag(kRPGBattleMenuTagCancel2); menuCancel2->removeFromParentAndCleanup(true); if(this->m_parentNode->getChildByTag(kRPGBattleSceneLayerTagItemsSelectDialog)) this->m_parentNode->getChildByTag(kRPGBattleSceneLayerTagItemsSelectDialog)->setVisible(true); if(this->m_parentNode->getChildByTag(kRPGBattleSceneLayerTagSkillSelectDialog)) this->m_parentNode->getChildByTag(kRPGBattleSceneLayerTagSkillSelectDialog)->setVisible(true); ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(false); ((RPGBattleSceneLayer*)this->m_parentNode)->cancelAllSelected(); } break; default: { CCLog("攻击"); this->hideMenu(); this->m_selectedMenuTag = kRPGBattleMenuTagAttack; CCMenuItemSprite *menuCancel = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGBattleMenu::onMenu)); menuCancel->setPosition(ccp(43, 596)); menuCancel->setTag(kRPGBattleMenuTagCancel); menuCancel->setScale(0.75); this->addChild(menuCancel); ((RPGBattleSceneLayer*)this->m_parentNode)->enabledTouched(true); } break; } }
void MyBuildingCard::init(CCSprite* buildingSprite,int cardId, int maxCount,int count, int _resourceTag, int _summaryCount, const char *name,int unlockLevel) { this->cardId = cardId; this->setTag(cardId); this->maxCount = maxCount; this->count = count; this->resourceTag->setValue(_resourceTag); this->summaryCount->setValue(_summaryCount); this->setUnlockLevel(unlockLevel); this->name = name; // CCLabelTTF* nameLabel = int level = MyUtil::getInstance()->getLevelByExperience(MyGameInfo::getInstance()->getExperience()); buildingSprite->setPosition(ccp(this->itemImage->getContentSize().width/2,itemImage->getContentSize().height/2 +24)); CCSprite* lightSprite = CCSprite::createWithSpriteFrameName("creatorLight.png"); lightSprite->setScale(0.8); lightSprite->setOpacity(153); lightSprite->setPosition(ccp(this->getContentSize().width/2,this->getContentSize().height-this->getContentSize().width/2)); CCLabelTTF* nameLabel = CCLabelTTF::create(name, "Arial", 22); nameLabel->setPosition(ccp(134,this->getContentSize().height-30)); nameLabel->setAnchorPoint(ccp(0.5,0.5)); nameLabel->setColor(ccWHITE); char str[10] = {0}; sprintf(str,"No.%d", cardId); CCLabelTTF* idLabel = CCLabelTTF::create(str, "Arial", 19); idLabel->setPosition(ccp(10,this->getContentSize().height-15)); idLabel->setAnchorPoint(ccp(0,0.5)); idLabel->setColor(ccBLACK); CCSprite* resourceIcon = MyUtil::getInstance()->getResourceIcon(getResourceTag()); resourceIcon->setScale(32/resourceIcon->getContentSize().height); resourceIcon->setPosition(ccp(55,38)); this->addChild(resourceIcon,2); sprintf(str,"%d", getSummaryCount()); CCLabelTTF* summaryLabel = CCLabelTTF::create(str, "Arial", 28); summaryLabel->setColor(ccc3(254,241,158)); summaryLabel->setPosition(ccp(this->getContentSize().width/2+13,38)); summaryLabel->setAnchorPoint(ccp(0.5,0.5)); this->addChild(summaryLabel); // } // if (_summaryIron != 0) { // CCSprite* ironIcon = CCSprite::createWithSpriteFrameName("ironIcon.png"); // ironIcon->setScale(0.6); // ironIcon->setPosition(ccp(55,38)); // this->addChild(ironIcon,2); // sprintf(str,"%d", _summaryIron); // CCLabelTTF* ironLabel = CCLabelTTF::create(str, "Arial", 28); // ironLabel->setColor(ccc3(254,241,158)); // ironLabel->setPosition(ccp(this->getContentSize().width/2+13,38)); // ironLabel->setAnchorPoint(ccp(0.5,0.5)); // this->addChild(ironLabel,2); // } CCSprite* up = CCSprite::createWithSpriteFrameName("creatordetail.png"); up->setScaleX(0.88); CCSprite* down = CCSprite::createWithSpriteFrameName("creatordetail.png"); down->setScaleX(0.88); CCMenuItemSprite* detailButton = CCMenuItemSprite::create(up,down); detailButton->setScale(0.8); detailButton->setPosition(ccp(175,68)); MyPriorityMenu* menu = MyPriorityMenu::create(-503,detailButton,NULL); menu->setPosition(ccp(0,0)), this->addChild(menu,3); this->addChild(buildingSprite,2); this->addChild(lightSprite,1); this->addChild(idLabel,2); this->addChild(nameLabel,2); if (level < unlockLevel) { CCSprite* black = CCSprite::create("whiteImage.jpg"); black->setColor(ccc3(0,0,0)); black->setScaleX(210/black->getContentSize().width); black->setScaleY(246/black->getContentSize().height); black->setPosition(ccp(210/2,246/2+2)); black->setOpacity(130); black->setTag(blackTag); this->addChild(black,20); CCSprite* lock = CCSprite::create("lock.png"); lock->setPosition(ccp(40,80)); lock->setOpacity(180); lock->setTag(lockTag); this->addChild(lock,20); // buildingSprite->setScale((itemImage->getContentSize().width-transWindowToGLInRetina(20))/buildingSprite->getContentSize().width); // CCSprite* militrayIcon = CCSprite::createWithSpriteFrameName("militaryIcon.png"); // militrayIcon->setPosition(ccp(itemImage->getContentSize().width/2 +40,94)); // militrayIcon->setScale(0.45f); // sprintf(str,"%d", summaryMilitary); // CCLabelTTF* militaryLabel = CCLabelTTF::create(str, "Arial", 30); // militaryLabel->setPosition(ccp(itemImage->getContentSize().width/2 +60,94)); // militaryLabel->setAnchorPoint(ccp(0,0.5)); // militaryLabel->setColor(ccc3(114,66,45)); // CCMenuItemSprite* sprite = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("creatorquitp.png"), CCSprite::createWithSpriteFrameName("creatorquit.png"),this, menu_selector(MyBuildingCard::displayDetail)); } if (maxCount > 0) { sprintf(str,"%d/%d",count,maxCount); CCLabelTTF* countLabel = CCLabelTTF::create(str,"Arial",20); countLabel->setPosition(ccp(175,this->getContentSize().height-57)); // countLabel->setPosition() this->addChild(countLabel,20); } // this->addChild(militrayIcon); // this->addChild(militaryLabel); }