bool MainMenu::init() { if ( !CCLayerColor::initWithColor(ccc4(0, 0, 0, 200)) ) { return false; } CCLabelTTF *title = CCLabelTTF::create("Rabbit Run", FONT_NAME, 70); title->setPosition(ccp(SCREEN_CX, SCREEN_HEIGHT - 80)); this->addChild(title); CCMenuItemFont::setFontName(FONT_NAME); CCMenuItemFont::setFontSize(50); char* text[] = {"Score", "Power", "Effect", "+10", "+20%", "--", "+20", "+40%", "grow up", "+10", "+0", "lose weight", "+0", "+0","hiding"}; for(int i = 0; i < 15; i++) { CCLabelTTF *label = CCLabelTTF::create(text[i], FONT_NAME, 50); label->setPosition(ccp(400 + i%3*300, 550 - i/3*85)); this->addChild(label); } char* img[] = {"cabbage.png", "carrot.png", "carrot_ice.png", "carrot_sterlth.png"}; for(int i = 0; i < 4; i++) { CCSprite *sprite = CCSprite::create(img[i]); sprite->setScale(0.2f); sprite->setPosition(ccp(250, 450 - i*80)); this->addChild(sprite); } CCMenuItemFont *startGame = CCMenuItemFont::create("Play", this, menu_selector(MainMenu::startGame)); startGame->setColor(ccc3(0, 255,51)); startGame->setPositionX(-90); CCMenuItemFont *exitGame = CCMenuItemFont::create("Exit", this, menu_selector(MainMenu::exitGame)); exitGame->setColor(ccc3(255, 0, 0)); exitGame->setPositionX(110); CCMenu *menu = CCMenu::create(startGame, exitGame, NULL); menu->setPositionY(120); menu->setTouchPriority(-201); this->addChild(menu); CCLabelTTF *powerBy = CCLabelTTF::create("Power by cocos2d-x", FONT_NAME, 50); powerBy->setAnchorPoint(ccp(1, 0)); powerBy->setPosition(ccp(SCREEN_WIDTH, 0)); this->addChild(powerBy); this->setTouchPriority(-200); this->setTouchMode(kCCTouchesOneByOne); this->setTouchEnabled(true); return true; }
bool LevelUpPopUp::init(uint32_t level) { if (!CCLayer::init()) return false; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCSprite* back = CCSprite::create("Interfeiss/level_end/level_up_popup/level_up_main.png"); back->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2)); addChild(back); TimedSpriteAnimation* t1 = TimedSpriteAnimation::create("Interfeiss/level_end/level_up_popup/shiny_stuff.plist", 3); t1->setPosition(ccp(visibleSize.width / 2 + 100, visibleSize.height / 2)); addChild(t1); TimedSpriteAnimation* t2 = TimedSpriteAnimation::create("Interfeiss/level_end/level_up_popup/shiny_stuff.plist", 3); t2->setPosition(ccp(visibleSize.width / 2 - 100, visibleSize.height / 2)); addChild(t2); TimedSpriteAnimation* t3 = TimedSpriteAnimation::create("Interfeiss/level_end/level_up_popup/shiny_stuff.plist", 3); t3->setPosition(ccp(visibleSize.width / 2 + 20, visibleSize.height / 2 + 80)); addChild(t3); CCMenuItemImage* closeBt = CCMenuItemImage::create("Interfeiss/level_end/level_up_popup/x_btn0001.png", "Interfeiss/level_end/level_up_popup/x_btn0002.png", this, menu_selector(LevelUpPopUp::closeCallback)); CCMenu* closeMenu = CCMenu::create(closeBt, NULL); closeMenu->setPosition(ccp(640, 420)); addChild(closeMenu); CCMenuItemImage* shareBt = CCMenuItemImage::create("Interfeiss/level_end/level_up_popup/share_btn20001.png", "Interfeiss/level_end/level_up_popup/share_btn20002.png", this, menu_selector(LevelUpPopUp::shareCallback)); CCMenu* shareMenu = CCMenu::create(shareBt, NULL); shareMenu->setPositionY(170); addChild(shareMenu); CCLabelTTF* levelTxt = CCLabelTTF::create(toString(level).c_str(), FONT_SKRANJI, TITLE_FONT_SIZE*1.6, CCSize(145, 145), kCCTextAlignmentCenter, kCCVerticalTextAlignmentCenter); levelTxt->setColor(ccc3(0xFF, 0xFC, 0x00)); levelTxt->setPosition(ccp(visibleSize.width / 2+5, visibleSize.height / 2 - 28)); addChild(levelTxt); return true; }
void CMenuLayer::createMenu() { CCMenuItemFont::setFontSize( 32 ); CCMenuItemFont::setFontName("Courier New"); setTouchEnabled(true); // Font Item CCMenuItem* quit = CCMenuItemImage::create( "images/CloseNormal.png", "images/CloseSelected.png", this, menu_selector(CMenuLayer::onQuit) ); CCMenu* menu = CCMenu::create( quit, NULL); menu->alignItemsVertically(); addChild( menu ); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCSize itemSize = quit->getContentSize(); menu->setPositionX( winSize.width - itemSize.width / 2 ); menu->setPositionY( winSize.height - itemSize.height / 2 ); }
void ChallengeAgainLayer::onShow(int round, int need) { float totalWidth = 0.0; CCSize s = CCDirector::sharedDirector()->getWinSize(); CCSprite *app1 = CCSprite::create(g_sRelifeBGImage); app1->setAnchorPoint(ccp(0,0)); app1->setPositionX(30); app1->setPositionY(s.height*0.5); this->addChild(app1); totalWidth += app1->getContentSize().width; NumberSprite * roundTip = NumberSprite::create("green60",round); roundTip->setAnchorPoint(ccp(0,0)); roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4); roundTip->setPositionY(app1->getPositionY()); this->addChild(roundTip); totalWidth += 4; totalWidth += roundTip->realWidth; CCSprite *app2 = CCSprite::create(g_sGuanBGImage); app2->setAnchorPoint(ccp(0,0)); app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4); app2->setPositionY(roundTip->getPositionY()); this->addChild(app2); totalWidth += 4; totalWidth += app2->getContentSize().width; float bx = (s.width - totalWidth)*0.5; app1->setPositionX(bx); roundTip->setPositionX(app1->getPositionX()+app1->getContentSize().width+4); app2->setPositionX(roundTip->getPositionX()+roundTip->realWidth+4); CCSprite *app3 = CCSprite::create(g_sLifeNeedBGImage); app3->setAnchorPoint(ccp(0,0)); app3->setPositionX(app1->getPositionX()); app3->setPositionY(app2->getPositionY()-app2->getContentSize().height-20); this->addChild(app3); NumberSprite * needTip = NumberSprite::create("green60",need); needTip->setAnchorPoint(ccp(0,0)); needTip->setPositionX(app3->getPositionX()+app3->getContentSize().width+4); needTip->setPositionY(app3->getPositionY()); this->addChild(needTip); CCSprite *app4 = CCSprite::create(g_sLifeValueBGImage); app4->setAnchorPoint(ccp(0,0)); app4->setPositionX(needTip->getPositionX()+needTip->realWidth+4); app4->setPositionY(needTip->getPositionY()); this->addChild(app4); CCMenuItemImage* pSureMenu = CCMenuItemImage::create( g_sSureBGImage, g_sSureBGImage, this, menu_selector(ChallengeAgainLayer::onCommandSure)); pSureMenu->setAnchorPoint(ccp(0,0)); CCMenu* pMenu = CCMenu::create(pSureMenu, NULL); this->addChild(pMenu); pMenu->setTouchPriority(-1000); pMenu->setAnchorPoint(ccp(0,0)); pMenu->setPositionY(app4->getPositionY()-app4->getTextureRect().size.height-40); pMenu->setPositionX(100); CCSprite * img = CCSprite::create(g_sReturnBGImage); CCMenuItemImage* pReturnMenu = CCMenuItemImage::create( g_sReturnBGImage, g_sReturnBGImage, this, menu_selector(ChallengeAgainLayer::onCommandReturn)); pReturnMenu->setAnchorPoint(ccp(0,0)); CCMenu* pMenu2 = CCMenu::create(pReturnMenu, NULL); this->addChild(pMenu2); pMenu2->setTouchPriority(-1000); pMenu2->setAnchorPoint(ccp(0,0)); pMenu2->setPositionY(pMenu->getPositionY()); pMenu2->setPositionX(s.width-img->getTextureRect().size.width-100); }
bool DailyDaysCompletePopup::init(uint32_t days, uint32_t reward) { if (!CCLayer::init()) return false; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCSprite* back = CCSprite::create("Interfeiss/challenges/complete_popup/dont_leave.png"); back->setPosition(ccp(visibleSize.width / 2, visibleSize.height / 2)); addChild(back); CCMenuItemImage* closeBt = CCMenuItemImage::create("Interfeiss/level_end/level_up_popup/x_btn0001.png", "Interfeiss/level_end/level_up_popup/x_btn0002.png", this, menu_selector(DailyDaysCompletePopup::close)); CCMenu* closeMenu = CCMenu::create(closeBt, NULL); closeMenu->setPosition(ccp(730, 530)); addChild(closeMenu); CCMenuItemImage* shareBt = CCMenuItemImage::create("Interfeiss/challenges/complete_popup/share_btn_still0001.png", "Interfeiss/challenges/complete_popup/share_btn_still0002.png", this, menu_selector(DailyDaysCompletePopup::share)); CCMenu* shareMenu = CCMenu::create(shareBt, NULL); shareMenu->setPositionY(200); shareMenu->setPositionX(visibleSize.width / 2 + 0); addChild(shareMenu); CCLabelTTF* titleTxt = CCLabelTTF::create(("Daily challenge completed " + toString(days) + " days in a row!").c_str(), FONT_SKRANJI_BOLD, TITLE_FONT_SIZE*0.6, CCSize(320, 180), kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop); titleTxt->setColor(ccc3(0x3E, 0x16, 0x04)); titleTxt->setRotation(-2); titleTxt->setPosition(ccp(visibleSize.width / 2+80, visibleSize.height / 2 + 70)); addChild(titleTxt); // title CCLabelTTF* levelTxt = CCLabelTTF::create("reward", FONT_SKRANJI_BOLD, TITLE_FONT_SIZE*0.6, CCSize(130, 120), kCCTextAlignmentCenter, kCCVerticalTextAlignmentTop); levelTxt->setColor(ccc3(0x4F, 0x98, 0x8B)); levelTxt->setRotation(-6); levelTxt->setPosition(ccp(visibleSize.width / 2 + 40, visibleSize.height / 2 - 70)); addChild(levelTxt); // reward CCLabelTTF* rewardSh = CCLabelTTF::create(toString(reward).c_str(), FONT_SKRANJI_BOLD, TITLE_FONT_SIZE*1, CCSize(100, 55), kCCTextAlignmentRight, kCCVerticalTextAlignmentCenter); rewardSh->setAnchorPoint(ccp(0,0)); rewardSh->cocos2d::CCNode::setPosition(ccp(580, 2)); rewardSh->setColor(ccc3(0xff, 0xff, 0xff)); rewardSh->enableShadow(CCSize(3,3), 0.5, 3, true); rewardSh->setRotation(-6); rewardSh->setPosition(ccp(visibleSize.width / 2 - 70, 245)); addChild(rewardSh); CCLabelTTF* rewardT = CCLabelTTF::create(toString(reward).c_str(), FONT_SKRANJI_BOLD, TITLE_FONT_SIZE*1, CCSize(100, 55), kCCTextAlignmentRight, kCCVerticalTextAlignmentCenter); rewardT->setAnchorPoint(ccp(0,0)); rewardT->setColor(ccc3(0xff, 0xff, 0xff)); rewardT->cocos2d::CCNode::setPosition(ccp(580, 2)); rewardT->setRotation(-6); rewardT->setPosition(ccp(visibleSize.width / 2 - 70, 245)); addChild(rewardT); // animation TimedSpriteAnimation* check = TimedSpriteAnimation::create("Interfeiss/challenges/ingame_pop_up/check.plist", 3); check->setAnchorPoint(ccp(0, 1)); check->setPosition(ccp(visibleSize.width / 2 + 190, 460)); addChild(check); // icon char rewardStr[10]; std::string iconStr; sprintf(rewardStr, "+%d", reward); iconStr = "Interfeiss/challenges/award_diamond.png"; rewardSh->setString(rewardStr); rewardT->setString(rewardStr); // icon CCSprite* icon = CCSprite::create(iconStr.c_str()); icon->setAnchorPoint(ccp(0.5,0.5)); icon->setScale(0.8); icon->setPosition(ccp(visibleSize.width / 2 + 80, 280)); addChild(icon); return true; }
bool SelectLevel::init() { if(!SceneStyle::init()) return false; ADSoundManager::playMusic(InfoStyles::MENU_MUSIC); //Get curren collection const Collection* current_collection; current_collection =LevelSaves::getInstance().getCollectionById( _collection_id); //Get the screen start of cordinates const CCPoint ORIGIN = ADScreen::getOrigin(); const CCSize VISIBLE_SIZE = ADScreen::getVisibleSize(); const float SCALE = ADScreen::getScaleFactor(); float x_middle_of_sheet = (VISIBLE_SIZE.width-133/SCALE)/2 + ORIGIN.x; float padding = 25/SCALE; showBackground(BackgroundType::Dark); showButtonBack(); //window title cocos2d::CCLabelTTF* title_select_collection; title_select_collection = CCLabelTTF::create(current_collection->getName().c_str(), ADLanguage::getFontName(), InfoStyles::SIZE_MENU_TITLE); title_select_collection->setPositionX(x_middle_of_sheet+padding*2); title_select_collection->setPositionY(ORIGIN.y + + VISIBLE_SIZE.height-padding*0.25f - title_select_collection->getContentSize().height*0.5f); title_select_collection->setColor(InfoStyles::COLOR_WHITE); this->addChild(title_select_collection); //menu CCMenu* menu =CCMenu::create(); float position_menu_y = VISIBLE_SIZE.height -padding*0.25f - title_select_collection->getContentSize().height*0.5f; float collection_width = 0; float card_height = 0; float card_width = 0; int current_dificult; current_dificult = 0; for(unsigned int j = 0; j < 3; ++j) { current_dificult = j; Card* card; if (j == 0) { int star_number = SaveStarsManager::getInstance()->getStars( _collection_id, j); card = Card::create(CCSprite::create(current_collection->getCollectionPartEasy().getImage().c_str()), _("select_level.easy"), star_number,CardType::WithBorder); } else if (j == 1) { int star_number = SaveStarsManager::getInstance()->getStars( _collection_id, j); card = Card::create(CCSprite::create(current_collection->getCollectionPartMiddle().getImage().c_str()), _("select_level.middle"), star_number,CardType::WithBorder); } else if (j == 2) { int star_number = SaveStarsManager::getInstance()->getStars( _collection_id, j); card = Card::create(CCSprite::create(current_collection->getCollectionPartDifficult().getImage().c_str()), _("select_level.difficult"), star_number,CardType::WithBorder); } ADMenuItem* button_card = ADMenuItem::create(card); button_card->setAnchorPoint(ccp(0.5f,0.5f)); float one_card_width = 340/SCALE; collection_width += one_card_width; card_height = button_card->getContentSize().height; card_width = button_card->getContentSize().width; button_card->setPositionY(ORIGIN.y+button_card->getContentSize().height*0.5f); button_card->setPositionX(one_card_width*j + button_card->getContentSize().width*0.5f); CollectionID id = current_collection->getID(); button_card->setClickAction([id,current_dificult](){ CCDirector::sharedDirector()->replaceScene(LevelScene::scene(id,current_dificult)); }); menu->addChild(button_card); card->setCardColor(LevelSaves::getInstance().getColor(_collection_id)); card->setTitleColor(InfoStyles::COLOR_WHITE); if (j == 0) { card->setBorderType(BorderType::Easy); } else if (j == 1) { card->setBorderType(BorderType::Middle); } else if (j == 2) { card->setBorderType(BorderType::Difficult); } } menu->setAnchorPoint(ccp(0,0)); float position_menu_x = VISIBLE_SIZE.width -collection_width ; menu->setPositionX(ORIGIN.x +position_menu_x*0.5f); menu->setPositionY((position_menu_y-card_height)*0.5f); this->addChild(menu); return true; }
bool LayerWin::init() { bool bRet = false; do { int curTitle = Global::shareGlobal()->curTitle; CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CC_BREAK_IF(!initWithColor(ccc4(250, 248, 239,255))); CCLabelTTF* label = CCLabelTTF::create(curTitle == 11 ? "YOU WIN!" : "GREAT!","Arial Bold",32, CCSize(visibleSize.width,visibleSize.height*0.7),kCCTextAlignmentCenter); CC_BREAK_IF(!label); label->setColor(ccc3(119,110,101)); label->setPosition(ccp(origin.x+visibleSize.width/2,origin.y+visibleSize.height/2)); this->addChild(label); float rectX = visibleSize.width*0.75; float rectY = rectX*0.45; ColorRect* pRect = ColorRect::create(ccc4(236, 196, 0, 255),rectX,rectY); pRect->setPosition(origin.x + (visibleSize.width-rectX)/2,origin.y+(visibleSize.height)/2); this->addChild(pRect); CCString *ssv = CCString::createWithFormat("%d",1 << curTitle); CCLabelTTF* scoreValue = CCLabelTTF::create(ssv->getCString(),"Arial Bold",32,CCSize(rectX,rectY), kCCTextAlignmentCenter); this->addChild(scoreValue); scoreValue->setPosition(ccp(pRect->getPositionX()+rectX*0.5,pRect->getPositionY()+rectY*0.3)); CCString *sst = CCString::createWithFormat("SCORE:%d",Global::shareGlobal()->curScore); CCLabelTTF* score = CCLabelTTF::create(sst->getCString(),"Arial Bold",8,CCSize(rectX,rectY*0.5), kCCTextAlignmentCenter); this->addChild(score); score->setPosition(ccp(pRect->getPositionX()+rectX*0.5,pRect->getPositionY())); float menuX = rectX*0.45; float menuY = menuX*0.3; TitleRect *titleBack = TitleRect::create(ccc4(187, 173, 160, 255),menuX,menuY,"Back"); CCMenuItemLabel *MenuBack = CCMenuItemLabel::create(titleBack,this,menu_selector(LayerWin::menuBack)); TitleRect *titleAgain = TitleRect::create(ccc4(187, 173, 160, 255),menuX,menuY,"Try again"); CCMenuItemLabel *MenuAgain = CCMenuItemLabel::create(titleAgain,this,menu_selector(LayerWin::menuAgain)); CCMenu *menu = CCMenu::create(MenuBack,MenuAgain,NULL); menu->alignItemsHorizontallyWithPadding(rectX*0.1); menu->setPositionY(origin.y+visibleSize.height*0.2); this->addChild(menu); bRet = true; }while(0); return bRet; }