void Store::addUpgradeBar(CCNode* sender,int level, int num) { CCSprite *sprite; sprite = CCSprite::create("ctm_Store_LitPurchaseBar.png"); if(level==1) sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+290-120,POWER_UP_BAR_OFFSET_Y+20)); if(level==2) sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+305-120,POWER_UP_BAR_OFFSET_Y+20)); if(level==3) sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+320-120,POWER_UP_BAR_OFFSET_Y+20)); sender->addChild(sprite); m_UpgradeCosts[num]->removeFromParentAndCleanup(true); CCSize dim; dim.width = 50.0f; dim.height = 20.0f; char currencyStr[32]; if(s_UpgradeItemCost[num][level] > 0) sprintf(currencyStr,"$%d", s_UpgradeItemCost[num][level]); else sprintf(currencyStr,"Max"); dim.width = 400.0f; dim.height = 18.0f; sender->removeChildByTag(15,true); CCLabelTTF* label = CCLabelTTF::create(s_UpgradeItemDesc[num][level],"Jacoby ICG Black.ttf",15,dim,kCCTextAlignmentLeft); label->setColor(ccc3(230,230,230)); label->setPosition(ccp(DESC_X,DESC_Y)); sender->addChild(label,0,15); CCLabelBMFont *BMfontLabel = CCLabelBMFont::create(currencyStr,"JacobyICGBlack18pnt.fnt"); BMfontLabel->setAnchorPoint(ccp(1.0f,0.5f)); BMfontLabel->setPosition(ccp(COST_X,COST_Y)); sender->addChild(BMfontLabel); m_UpgradeCosts[num] = BMfontLabel; }
bool GameOverLayer::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); CCSize winSize=CCDirector::sharedDirector()->getWinSize(); // add gameover_background CCSprite* background=CCSprite::create(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("gameover.png")); background->setPosition(ccp(winSize.width/2,winSize.height/2)); this->addChild(background); // add BackMenu CCSprite* normalBackToGame=CCSprite::create(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png")); CCSprite* pressedBackToGame=CCSprite::create(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png")); CCMenuItemImage* pBackItem=CCMenuItemImage::create(); pBackItem->initWithNormalSprite(normalBackToGame,pressedBackToGame,NULL,this,menu_selector(GameOverLayer::menuBackCallback)); pBackItem->setPosition(ccp(winSize.width-normalBackToGame->getContentSize().width/2-10,normalBackToGame->getContentSize().height/2+10)); CCMenu *menuBack=CCMenu::create(pBackItem,NULL); menuBack->setPosition(CCPointZero); this->addChild(menuBack); // show score CCString *strScore = CCString::createWithFormat("%d", score); CCLabelBMFont * finalScore = CCLabelBMFont::create(strScore->m_sString.c_str(), "font.fnt"); finalScore->setColor(ccc3(143, 146, 147)); finalScore->setPosition(ccp(winSize.width/2, winSize.height/2)); this->addChild(finalScore); if (CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()) { CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic(); } CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("game_over.mp3"); bRet = true; } while (0); return bRet; }
void ComicScene::cleanPages() { if ( currentPage == 1 || currentPage > this->totalPages) { return; } int textTag; int imageTag; if ( currentPage == 2 ) { imageTag = 1; textTag = 2; } else if ( currentPage == 3 ) { imageTag = 3; textTag = 4; } CCSprite* currentImage = (CCSprite*)this->getChildByTag(imageTag); CCLabelBMFont* currentText = (CCLabelBMFont*)this->getChildByTag(textTag); currentImage->stopAllActions(); currentImage->setOpacity(0); currentText->stopAllActions(); currentText->setOpacity(0); }
void GameScene::showScore() { //スコア CCLabelBMFont* score = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagScore)); if (score) { score->removeFromParent(); } CCLabelBMFont* label = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagScoreLabel)); CCString* gameScore = CCString::createWithFormat("%d", getScore()); score = CCLabelBMFont::create(gameScore->getCString(), FONT_ORANGE); score->setScale(TEXT_SCALE); score->setAnchorPoint(CCPointZero); score->setPosition( label->getPositionX() + label->getContentSize().width * TEXT_SCALE + 10, label->getPositionY()); score->setTag(kTagScore); this->addChild(score); }
KDvoid CScrGame::onEnterTransitionDidFinish ( KDvoid ) { CCLayer::onEnterTransitionDidFinish ( ); CCFiniteTimeAction* pAction = CCSequence::create ( CCSpawn ::create ( CCScaleTo ::create ( 0.7f, 3 ), CCFadeIn::create ( 0.7f ), KD_NULL ), CCRepeat::create ( CCSequence::create ( CCFadeOut::create ( 0.5f ), CCFadeIn ::create ( 0.5f ), KD_NULL ), 3 ), CCSpawn ::create ( CCScaleTo ::create ( 0.7f, 10 ), CCFadeOut::create ( 0.7f ), KD_NULL ), CCCallFuncN::create ( this, callfuncN_selector ( CScrGame::onStart ) ), CCCallFuncN::create ( this, callfuncN_selector ( CScrGame::onRemove ) ), KD_NULL ); CCLabelBMFont* pStart = g_pResMgr->getLabel ( this, "Game Start !!!" ); pStart->setPosition ( ccpMid ( CCDirector::sharedDirector ( )->getWinSize ( ) ) ); pStart->setScale ( 10 ); pStart->setOpacity ( 0 ); pStart->runAction ( pAction ); }
CCMenuItemSprite * CCMenuItemDynamic::dynamicItemWithText(const char* text, const char* font, const CCSize &minSize, const char*normalImage, const char *selectedImage, CCObject* target, SEL_MenuHandler selector, const CCRect& centerRegion, GLubyte opacity) { //Create the label CCLabelBMFont *label = CCLabelBMFont ::labelWithString(text ,font); label ->setOpacity(opacity); //Calculate the Dynamic Button size float minWidth = label->getContentSize().width>minSize.width?label->getContentSize().width:minSize.width; float minHeight = label->getContentSize().height>minSize.height?label->getContentSize().height:minSize.height; CCSize size(minWidth+30,minHeight+24); label->setPosition(ccp(size.width*0.5f, size.height*0.5f)); //Sprite normal CCScale9Sprite *normalSprite = CCScale9Sprite::scale9SpriteWithFile(normalImage, centerRegion); normalSprite ->setContentSize(size); normalSprite ->setOpacity(opacity); //Sprite selected CCScale9Sprite *selectedSprite = NULL; if(selectedImage){ selectedSprite = CCScale9Sprite::scale9SpriteWithFile(selectedImage, centerRegion); selectedSprite ->setContentSize(size); selectedSprite->setOpacity(opacity); } //Create the CCMenuItemSprite CCMenuItemSprite* returnItem = CCMenuItemSprite::itemFromNormalSprite(normalSprite,selectedSprite,target, selector); returnItem->addChild(label); return returnItem; }
void HelloWorld::endScene( EndReason endReason ) { if (_gameOver) return; _gameOver = true; CCSize winSize = CCDirector::sharedDirector()->getWinSize(); /* char message[10] = "You Win"; if ( endReason == KENDREASONLOSE) strcpy(message,"You Lose"); */ char message[12] = { 0 }; sprintf(message, "Score: %d", _score); CCLabelBMFont * label ; label = CCLabelBMFont::create(message, "fonts/Arial.fnt"); label->setScale(0.1); label->setPosition(ccp(winSize.width/2 , winSize.height*0.6)); this->addChild(label); CCLabelBMFont * restartLabel; strcpy(message,"Restart"); restartLabel = CCLabelBMFont::create(message, "fonts/Arial.fnt"); CCMenuItemLabel *restartItem = CCMenuItemLabel::create(restartLabel, this, menu_selector(HelloWorld::restartTapped) ); restartItem->setScale(0.1); restartItem->setPosition( ccp(winSize.width/2, winSize.height*0.4)); CCMenu *menu = CCMenu::create(restartItem, NULL); menu->setPosition(CCPointZero); this->addChild(menu); // clear label and menu restartItem->runAction(CCScaleTo::create(0.5, 1.0)); label ->runAction(CCScaleTo::create(0.5, 1.0)); // Terminate update callback this->unscheduleUpdate(); }
void OptionLayer::setViews() { setBackGroundImage("loading.png"); CCSprite *title = CCSprite::create("menuTitle.png",CCRectMake(0,0,135,35)); title->setAnchorPoint(ccp(0.5,1)); title->setPosition(ccp(getWinSize().width/2,getWinSize().height-20)); this->addChild(title); CCMenuItemToggle *music_trigger = CCMenuItemToggle::createWithTarget(this,menu_selector(OptionLayer::music_triggerCallback), CCMenuItemFont::create("Music : On"),CCMenuItemFont::create("Music : Off"),NULL); music_trigger->setPosition(ccp(getWinSize().width/2,getWinSize().height/2)); if(SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying()) { music_trigger->setSelectedIndex(1); } else { music_trigger->setSelectedIndex(0); } //menu->setPosition(ccp(getWinSize().width/2,getWinSize().height/2)); CCLabelBMFont *back = CCLabelBMFont::create("back","arial-14.fnt"); back->setScale(1.25f); CCMenuItemLabel *backLable = CCMenuItemLabel::create(back,this,menu_selector(OptionLayer::backCallback)); backLable->setAnchorPoint(ccp(0.5,1)); backLable->setPosition(ccp(getWinSize().width/2,50)); CCMenu *menu = CCMenu::create(music_trigger,backLable,NULL); menu->setPosition(CCPointZero); this->addChild(menu); }
bool LevelCompleteLayer::init() { bool pRet = false; if (CCLayer::init()) { // Accept touch input this->setIsTouchEnabled(true); hasBeenSkipped = false; // If Viking is dead, reset him and show the tombstone, // Any touch gets you back to the main menu bool didPlayerDie = GameManager::sharedGameManager()->getHasPlayerDied(); CCSprite *background = NULL; if (didPlayerDie) { background = CCSprite::spriteWithFile("Menus/LevelComplete/LevelCompleteDead.png"); } else { background = CCSprite::spriteWithFile("Menus/LevelComplete/LevelCompleteAlive.png"); } background->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT/2)); this->addChild(background); // Add the text for level complete. CCLabelBMFont *levelLabelText = CCLabelBMFont::labelWithString("Level Complete", "Fonts/VikingSpeechFont64.fnt"); levelLabelText->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT * 0.9f)); this->addChild(levelLabelText); char killNumber[100] = {0}; sprintf(killNumber, "Kill Count: %d", GameManager::sharedGameManager()->getKillCount()); CCLabelBMFont *killCountText = CCLabelBMFont::labelWithString(killNumber, "Fonts/VikingSpeechFont64.fnt"); killCountText->setPosition(ccp(SCREEN_WIDTH/2, SCREEN_HEIGHT * 0.6f)); this->addChild(killCountText); GameManager::sharedGameManager()->setKillCount(0); pRet = true; } return pRet; }
void MessageWindowSprite::delayLabelString(CCNode* sender,void* pStrLen) { //何文字目か int pos = (int)pStrLen - (display_page-1) * chars_per_row * rows_per_page; //表示する文字 CCString* Message = (CCString*)MessageStrCCArray->objectAtIndex((int)pStrLen); //文字表示部 if(cc_label_ttf_enable) { CCLabelTTF* pLabel = CCLabelTTF::create((char*)Message->getCString(), cc_label_font_name, cc_label_font_size); pLabel->setColor(cc_label_color); //X:開始位置 + (フォントサイズ * 行数 ), //Y:開始位置 - (フォントサイズ + 文字間隔 ) * 文字数) pLabel->setPosition(ccp(start_x_pos + cc_label_font_size * ( pos % chars_per_row ) , start_y_pos - (cc_label_font_size + 1) * ( pos / chars_per_row))); this->addChild(pLabel); }else if(cc_label_bmf_enable) { CCLabelBMFont* pLabel = CCLabelBMFont::create((char*)Message->getCString(), cc_label_font_file_name); //X:開始位置 + (フォントサイズ * 行数 ), //Y:開始位置 - (フォントサイズ + 文字間隔 ) * 文字数) pLabel->setPosition(ccp(start_x_pos + cc_label_font_size * ( pos % chars_per_row ) , start_y_pos - (cc_label_font_size + 1) * ( pos / chars_per_row))); this->addChild(pLabel); } //TODO rowSpriteを用意してそれに置いていけば行送りもできるはず }
// 碰撞检测 void GameScene::checkCollision() { CCSprite *bird =(CCSprite*)this->getChildByTag(TAG_BIRD); CCRect birdRect =bird->boundingBox(); if (bird->getPositionY()<ground1->boundingBox().size.height) { gameState=GameOver; score=0; this->birdFallAction(); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/lh_hit.ogg"); return; } for(int i=0;i<hose->hoseList->count();i++) { CCSprite *hoseSprite =(CCSprite*)hose->hoseList->objectAtIndex(i); CCRect hoseRect =hoseSprite->boundingBox(); if (birdRect.intersectsRect(hoseRect)) { gameState=GameOver; score=0; this->birdFallAction(); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/lh_hit.ogg"); break; } // 更新分数 int pPosX =hoseSprite->getPositionX()+hoseSprite->getContentSize().width*hoseSprite->getScaleX(); int birdX =bird->getPositionX()-bird->getContentSize().width*bird->getScaleX(); if (pPosX==birdX) { score++; CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/lh_point.ogg"); CCLabelBMFont* scoreSprite =(CCLabelBMFont*)this->getChildByTag(TAG_SCORE); CCString *strScore =CCString::createWithFormat("%d",score/2); scoreSprite->setString(strScore->m_sString.c_str()); } } updatehightestRecord(); }
void World::showLevel() { /*添加显示板*/ CCSprite* sprite = CCSprite::create("displayLevel.png"); addChild(sprite); CCLabelBMFont* label = CCLabelBMFont::create("Level", "testChinese.fnt"); sprite->addChild(label); CCString* string; if (CCUserDefault::sharedUserDefault()->getBoolForKey("ifEndlessMode")) { string = CCString::createWithFormat("Level %d", Interface::sharedInterface()->level); } else { string = CCString::createWithFormat("Level %d", Interface::sharedInterface()->level1); } label->setString(string->getCString()); label->setPosition(ccp(sprite->boundingBox().size.width * 0.5, sprite->boundingBox().size.height * 0.5)); sprite->setPosition(ccp(size.width * 0.5, size.height - sprite->boundingBox().size.height * 0.3)); sprite->setScale(0.5); sprite->setTag(tag_sprite); }
bool Settings::initWithFile(const char * pszFilename) { Button::initWithFile(pszFilename); setScaleWhenTouch(false); setName("settings"); CCSprite * settingsText = CCSprite::create("ui/settings_text.png"); settingsText->setAnchorPoint(ccp(0.5,1.0)); settingsText->setPosition(ccp(getContentSize().width/2, getContentSize().height-size(2.5))); addChild(settingsText); CCLabelBMFont * musicLabel = CCLabelBMFont::create("Background Music", "font/item_count.fnt"); musicLabel->setAnchorPoint(ccp(0.5, 0.0)); musicLabel->setPosition(ccp(center(this).x, size(345))); addChild(musicLabel); m_buttonBGMOn = new Button; m_buttonBGMOn->initWithFile("ui/settings_on.png"); m_buttonBGMOn->setAnchorPoint(ccp(1.0, 0.0)); m_buttonBGMOn->setPosition(ccp(center(this).x-size(10), size(280))); m_buttonBGMOn->setActID(BUTTON_BGM_ON); addChild(m_buttonBGMOn); addButton(m_buttonBGMOn); m_buttonBGMOff = new Button; m_buttonBGMOff->initWithFile("ui/settings_off.png"); m_buttonBGMOff->setAnchorPoint(ccp(0.0, 0.0)); m_buttonBGMOff->setPosition(ccp(center(this).x+size(10), size(280))); m_buttonBGMOff->setActID(BUTTON_BGM_OFF); addChild(m_buttonBGMOff); addButton(m_buttonBGMOff); CCLabelBMFont * msgLabel = CCLabelBMFont::create("Notifications", "font/item_count.fnt"); msgLabel->setAnchorPoint(ccp(0.5, 0.0)); msgLabel->setPosition(ccp(center(this).x, size(210))); addChild(msgLabel); m_buttonMsgOn = new Button; m_buttonMsgOn->initWithFile("ui/settings_on.png"); m_buttonMsgOn->setAnchorPoint(ccp(1.0, 0.0)); m_buttonMsgOn->setPosition(ccp(center(this).x-size(10), size(145))); m_buttonMsgOn->setActID(BUTTON_MSG_ON); addChild(m_buttonMsgOn); addButton(m_buttonMsgOn); m_buttonMsgOff = new Button; m_buttonMsgOff->initWithFile("ui/settings_off.png"); m_buttonMsgOff->setAnchorPoint(ccp(0.0, 0.0)); m_buttonMsgOff->setPosition(ccp(center(this).x+size(10), size(145))); m_buttonMsgOff->setActID(BUTTON_MSG_OFF); addChild(m_buttonMsgOff); addButton(m_buttonMsgOff); update(); return true; }
FMUIBooster::FMUIBooster() : m_parentNode(NULL), m_amountLabel(NULL), m_boosterIcon(NULL), m_boosterCount(NULL), m_willClose(false), m_recharging(false), m_unlockLabel(NULL), m_newBoostLabel(NULL) { m_ccbNode = FMDataManager::sharedManager()->createNode("UI/FMUIBooster.ccbi", this); addChild(m_ccbNode); CCLabelBMFont * title = (CCLabelBMFont *)m_parentNode->getChildByTag(3); #if (CC_TARGET_PLATFORM != CC_PLATFORM_ANDROID) title->setAlignment(kCCTextAlignmentCenter); #endif NEAnimNode * booster = (NEAnimNode *)m_parentNode->getChildByTag(1); booster->releaseControl("Clock"); booster->releaseControl("Booster"); NEAnimNode * boosterIcon = (NEAnimNode *)booster->getNodeByName("Booster"); m_boosterIcon = boosterIcon; NEAnimNode * boosterClock = (NEAnimNode *)booster->getNodeByName("Clock"); boosterClock->setVisible(false); NEAnimNode * boosterCount = (NEAnimNode *)booster->getNodeByName("Count"); boosterCount->releaseControl("Label", kProperty_StringValue); m_boosterCount = boosterCount; m_amountLabel = (CCLabelBMFont *)boosterCount->getNodeByName("Label"); CCAnimButton * priceButton = (CCAnimButton *)m_parentNode->getChildByTag(15); priceButton->getAnimNode()->releaseControl("Label", kProperty_StringValue); }
void GameOver::initData() { // clean Txt CCSprite* cleanSprite = CCSprite::createWithSpriteFrameName(rewardUI[kTypeClearn]); cleanSprite->setPosition(ccpAdd(m_ptCenter, ccp( 150, 100))); cleanSprite->setTag(kTypeClearn); cleanSprite->setOpacity(0); this->addChild(cleanSprite); // reward background CCSprite* rewardBGSprite = CCSprite::createWithSpriteFrameName(rewardUI[kTypeNomalBG]); rewardBGSprite->setPosition(ccpSub(m_ptCenter, ccp(0, 100))); rewardBGSprite->setTag(kTypeNomalBG); rewardBGSprite->setOpacity(0); this->addChild(rewardBGSprite); //reward score CCLabelBMFont * rewardScore = CCLabelBMFont::create("0", rewardUI[ktypeScore]); rewardScore->setAnchorPoint(ccp(0.5f, 0.5f)); rewardScore->setPosition(ccpSub(m_ptCenter, ccp(0, 200))); rewardScore->setTag(ktypeScore); rewardScore->setOpacity(0); this->addChild(rewardScore); }
void StatusLabel::setTextAndColor(std::string text, GemUtils::GemColor c) { if(bg) bg->removeFromParentAndCleanup(true); bg = GetSprite(ColorToStatusBG(c)); bg->setAnchorPoint(ccp(0.5f, 0.5f)); root->addChild(bg); // set zorder explicitly below text CCLabelBMFont* old = textLabel; textLabel = CCLabelBMFont::create(text.c_str(), ColorToStatusFont(c)); textLabel->setAnchorPoint(ccp(0.5f, 0.5f)); textLabel->setPosition(ccp(-3.0f, -1.5f)); textLabel->setScale(contentScale()*0.9f); root->addChild(textLabel); root->setScale(0.0f); // COCOS2DX BUG: remove after new sprite batch is created // THIS is remedied by changing CC_ENABLE_GL_STATE_CACHE to 0 // in ccConfig.h if(old) old->removeFromParentAndCleanup(true); }
void CommonButton::setFontSize(float fontSize) { CCLabelBMFont * bmFont = dynamic_cast<CCLabelBMFont * >(m_label); CCLabelBMFont * bmFont1 = dynamic_cast<CCLabelBMFont * >(m_pBottomlabel); if (bmFont) { float scale = fontSize/24; bmFont->setScale(scale); } else { CCLabelTTF * ttf = dynamic_cast<CCLabelTTF * >(m_label); if (ttf) { ttf->setFontSize(fontSize); } } if (bmFont1) { float scale = fontSize/24; bmFont1->setScale(scale); } else { CCLabelTTF * ttf = dynamic_cast<CCLabelTTF * >(m_pBottomlabel); if (ttf) { ttf->setFontSize(fontSize); } } }
bool MenuLayer::initWithEntryID(int entryId) { CCSize s = CCDirector::sharedDirector()->getWinSize(); m_entryID = entryId; setIsTouchEnabled( true ); Box2DView* view = Box2DView::viewWithEntryID( entryId ); addChild(view, 0, kTagBox2DNode); view->setScale(15); view->setAnchorPoint( ccp(0,0) ); view->setPosition( ccp(s.width/2, s.height/3) ); #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE) CCLabelBMFont* label = CCLabelBMFont::labelWithString(view->title().c_str(), "fonts/arial16.fnt"); #else CCLabelTTF* label = CCLabelTTF::labelWithString(view->title().c_str(), "Arial", 28); #endif addChild(label, 1); label->setPosition( ccp(s.width/2, s.height-50) ); CCMenuItemImage *item1 = CCMenuItemImage::itemFromNormalImage("Images/b1.png", "Images/b2.png", this, menu_selector(MenuLayer::backCallback) ); CCMenuItemImage *item2 = CCMenuItemImage::itemFromNormalImage("Images/r1.png","Images/r2.png", this, menu_selector(MenuLayer::restartCallback) ); CCMenuItemImage *item3 = CCMenuItemImage::itemFromNormalImage("Images/f1.png", "Images/f2.png", this, menu_selector(MenuLayer::nextCallback) ); CCMenu *menu = CCMenu::menuWithItems(item1, item2, item3, NULL); menu->setPosition( CCPointZero ); item1->setPosition( ccp( s.width/2 - 100,30) ); item2->setPosition( ccp( s.width/2, 30) ); item3->setPosition( ccp( s.width/2 + 100,30) ); addChild(menu, 1); return true; }
void GameScene::showBallRemain() { //残りボール数 CCLabelBMFont* remain = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagBallRemainCount)); if (remain) { this->removeChild(remain); } CCLabelBMFont* label = dynamic_cast<CCLabelBMFont*>(this->getChildByTag( kTagBallRemainLabel)); CCString* ballRemain = CCString::createWithFormat("%d", getBallRemain()); remain = CCLabelBMFont::create(ballRemain->getCString(), FONT_ORANGE); remain->setScale(TEXT_SCALE); remain->setAnchorPoint(CCPointZero); remain->setPosition( label->getPositionX() + label->getContentSize().width * TEXT_SCALE + 10, label->getPositionY()); remain->setTag(kTagBallRemainCount); this->addChild(remain); }
Issue1343::Issue1343() { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLabelBMFont* bmFont = new CCLabelBMFont(); bmFont->init(); bmFont->setFntFile("fonts/font-issue1343.fnt"); bmFont->setString("ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890abcdefghijklmnopqrstuvwxyz.,'"); this->addChild(bmFont); bmFont->release(); bmFont->setScale(0.3f); bmFont->setPosition(ccp(s.width/2,s.height/4*2)); }
BMFontInit::BMFontInit() { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLabelBMFont* bmFont = new CCLabelBMFont(); bmFont->init(); bmFont->autorelease(); //CCLabelBMFont* bmFont = [CCLabelBMFont create:@"Foo" fntFile:@"arial-unicode-26.fnt"]; bmFont->setFntFile("fonts/helvetica-32.fnt"); bmFont->setString("It is working!"); this->addChild(bmFont); bmFont->setPosition(ccp(s.width/2,s.height/4*2)); }
Atlas6::Atlas6() { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLabelBMFont* label = NULL; label = CCLabelBMFont::labelWithString("FaFeFiFoFu", "fonts/bitmapFontTest5.fnt"); addChild(label); label->setPosition( ccp(s.width/2, s.height/2+50) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ) ; label = CCLabelBMFont::labelWithString("fafefifofu", "fonts/bitmapFontTest5.fnt"); addChild(label); label->setPosition( ccp(s.width/2, s.height/2) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ); label = CCLabelBMFont::labelWithString("aeiou", "fonts/bitmapFontTest5.fnt"); addChild(label); label->setPosition( ccp(s.width/2, s.height/2-50) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ); }
Atlas6::Atlas6() { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLabelBMFont* label = NULL; //中国 label = CCLabelBMFont::labelWithString("中国", "fonts/bitmapFontChinese.fnt", CCTextAlignmentRight, 200); addChild(label); label->setPosition( ccp(s.width / 2.0f, s.height / 2.0f + 50) ); label->setAnchorPoint( ccp(1.0f, 0.5f) ) ; label = CCLabelBMFont::labelWithString("fafefifofu", "fonts/bitmapFontTest5.fnt"); addChild(label); label->setPosition( ccp(s.width/2, s.height/2) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ); label = CCLabelBMFont::labelWithString("aeiou", "fonts/bitmapFontTest5.fnt"); addChild(label); label->setPosition( ccp(s.width/2, s.height/2-50) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ); }
void Store::BuildBikes(cocos2d::CCMenu* menu) { float scale = ScreenHelper::getTextureScale(); CCMenuItemImage *topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped)); topBar->setScale(scale); CCLabelTTF* label1 = CCLabelTTF::create("BIKES","Jacoby ICG Black.ttf",20); label1->setColor(ccc3(43,197,231)); label1->setPosition(ccp(-170+CATEGORY_OFFSET,17)); topBar->addChild(label1); menu->addChild(topBar); for(int i = 0; i < NUM_BIKE_ITEMS; i++) { CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png",this,menu_selector(Store::bikeButtonTapped) ); CCSprite *sprite = CCSprite::createWithSpriteFrameName(s_BikeItemImg[i]); sprite->setPosition(ccp(ICON_X,ICON_Y)); temp->addChild(sprite); CCSize dim; dim.width = 200.0f; dim.height = 25.0f; CCLabelTTF *label = CCLabelTTF::create(s_BikeItemName[i],"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentLeft); label->setColor(ccc3(237,188,0)); label->setPosition(ccp(NAME_X,NAME_Y)); temp->addChild(label); const char *status = NULL; if(SaveLoad::m_SaveData.bikes[i] & SaveLoad::SELECTED) status = "Selected"; else if(SaveLoad::m_SaveData.bikes[i] & SaveLoad::UNLOCKED) status = "Unlocked"; else status = "Locked"; dim.width = 400.0f; dim.height = 18.0f; label = CCLabelTTF::create(status,"Jacoby ICG Black.ttf",15,dim,kCCTextAlignmentLeft); label->setColor(ccc3(230,230,230)); label->setPosition(ccp(DESC_X,DESC_Y)); temp->addChild(label,0,15); m_BikeDescriptions[i] = label; if(SaveLoad::m_SaveData.bikes[i]==0) { //CGSize dim; dim.width = 50.0f; dim.height = 20.0f; char currencyStr[32]; sprintf(currencyStr,"$%d",s_BikeItemCost[i]); CCLabelBMFont *BMfontLabel = CCLabelBMFont::create(currencyStr,"JacobyICGBlack18pnt.fnt"); BMfontLabel->setAnchorPoint(ccp(1.0f,0.5f)); BMfontLabel->setPosition(ccp(COST_X,COST_Y)); temp->addChild(BMfontLabel,0,42); } temp->setScale(scale); menu->addChild(temp); m_Bikebuttons[i] = temp; } //add a bottom bar to push things up topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped)); topBar->setScale(scale); menu->addChild(topBar); }
void Store::BuildPowerUps(cocos2d::CCMenu* menu) { float scale = ScreenHelper::getTextureScale(); CCMenuItemImage *topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped)); topBar->setScale(scale); CCLabelTTF* label1 = CCLabelTTF::create("POWERUPS","Jacoby ICG Black.ttf",20); label1->setColor(ccc3(43,197,231)); label1->setPosition(ccp(-148+CATEGORY_OFFSET,17)); topBar->addChild(label1); menu->addChild(topBar); for(int i = 0; i < NUM_POWERUP_ITEMS; i++) { CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png",this,menu_selector(Store::powerupButtonTapped) ); CCSprite *sprite = CCSprite::createWithSpriteFrameName(s_PowerUpItemImg[i]); sprite->setPosition(ccp(ICON_X,ICON_Y)); temp->addChild(sprite); char labelString[32]; if(i==0) { if(SaveLoad::m_SaveData.numLevelFire) sprintf(labelString,"%s(%d)",s_PowerUpItemName[i],SaveLoad::m_SaveData.numLevelFire); else sprintf(labelString,"%s",s_PowerUpItemName[i]); } if(i==1) { if(SaveLoad::m_SaveData.numTimeSlow) sprintf(labelString,"%s(%d)",s_PowerUpItemName[i],SaveLoad::m_SaveData.numTimeSlow); else sprintf(labelString,"%s",s_PowerUpItemName[i]); } if(i==2) { if(SaveLoad::m_SaveData.numDoubleNuts) sprintf(labelString,"%s(%d)",s_PowerUpItemName[i],SaveLoad::m_SaveData.numDoubleNuts); else sprintf(labelString,"%s",s_PowerUpItemName[i]); } CCSize dim; dim.width = 200.0f; dim.height = 25.0f; CCLabelTTF *label = CCLabelTTF::create(labelString,"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentLeft); label->setColor(ccc3(237,188,0)); label->setPosition(ccp(NAME_X,NAME_Y)); temp->addChild(label); m_PowerUpNames[i] = label; dim.width = 400.0f; dim.height = 18.0f; label = CCLabelTTF::create(s_PowerUpItemDesc[i],"Jacoby ICG Black.ttf",15,dim,kCCTextAlignmentLeft); label->setColor(ccc3(230,230,230)); label->setPosition(ccp(DESC_X,DESC_Y)); temp->addChild(label,0,15); //CGSize dim; dim.width = 50.0f; dim.height = 20.0f; char currencyStr[32]; sprintf(currencyStr,"$%d",s_PowerUpItemCost[i]); CCLabelBMFont *BMfontLabel = CCLabelBMFont::create(currencyStr,"JacobyICGBlack18pnt.fnt"); BMfontLabel->setAnchorPoint(ccp(1.0f,0.5f)); BMfontLabel->setPosition(ccp(COST_X,COST_Y)); temp->addChild(BMfontLabel); temp->setScale(scale); menu->addChild(temp); m_PowerUpbuttons[i] = temp; } }
void Store::BuildUpgrades(cocos2d::CCMenu* menu) { float scale = ScreenHelper::getTextureScale(); CCMenuItemImage *topBar = CCMenuItemImage::create("ctm_UI_TransparentButton.png","ctm_UI_TransparentButton.png",this,menu_selector(Store::nullButtonTapped)); topBar->setScale(scale); CCLabelTTF* label1 = CCLabelTTF::create("UPGRADES","Jacoby ICG Black.ttf",20); label1->setColor(ccc3(43,197,231)); label1->setPosition(ccp(-150+CATEGORY_OFFSET,17)); topBar->addChild(label1); menu->addChild(topBar); int unlockLevel[NUM_UPGRADE_ITEMS]; unlockLevel[0] = SaveLoad::m_SaveData.turboLockLevel; unlockLevel[1] = SaveLoad::m_SaveData.trampLockLevel; unlockLevel[2] = SaveLoad::m_SaveData.timeLockLevel; unlockLevel[3] = SaveLoad::m_SaveData.peanutLockLevel; unlockLevel[4] = SaveLoad::m_SaveData.trickLockLevel; unlockLevel[5] = SaveLoad::m_SaveData.flipLockLevel; unlockLevel[6] = SaveLoad::m_SaveData.fireLockLevel; for(int i = 0; i < NUM_UPGRADE_ITEMS; i++) { CCMenuItem *temp = CCMenuItemImage::create("ctm_Store_GrayStrip.png","ctm_Store_GrayStrip.png","ctm_Store_LitStrip.png",this,menu_selector(Store::buyUpgradeButtonTapped) ); CCSprite *sprite; sprite = CCSprite::create("ctm_Store_PurchaseBars.png"); sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+302-120,POWER_UP_BAR_OFFSET_Y+21)); temp->addChild(sprite); if(unlockLevel[i]>=1) { sprite = CCSprite::create("ctm_Store_LitPurchaseBar.png"); sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+290-120,POWER_UP_BAR_OFFSET_Y+20)); temp->addChild(sprite); } if(unlockLevel[i]>=2) { sprite = CCSprite::create("ctm_Store_LitPurchaseBar.png"); sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+305-120,POWER_UP_BAR_OFFSET_Y+20)); temp->addChild(sprite); } if(unlockLevel[i]>=3) { sprite = CCSprite::create("ctm_Store_LitPurchaseBar.png"); sprite->setPosition(ccp(POWER_UP_BAR_OFFSET+320-120,POWER_UP_BAR_OFFSET_Y+20)); temp->addChild(sprite); } sprite = CCSprite::createWithSpriteFrameName(s_UpgradeItemImg[i]); sprite->setPosition(ccp(ICON_X,ICON_Y)); temp->addChild(sprite); CCSize dim; dim.width = 200.0f; dim.height = 25.0f; CCLabelTTF *label = CCLabelTTF::create(s_UpgradeItemName[i],"Jacoby ICG Black.ttf",20,dim,kCCTextAlignmentLeft); label->setColor(ccc3(237,188,0)); label->setPosition(ccp(NAME_X,NAME_Y)); temp->addChild(label); dim.width = 400.0f; dim.height = 18.0f; label = CCLabelTTF::create(s_UpgradeItemDesc[i][unlockLevel[i]],"Jacoby ICG Black.ttf",15,dim,kCCTextAlignmentLeft); label->setColor(ccc3(230,230,230)); label->setPosition(ccp(DESC_X,DESC_Y)); temp->addChild(label,0,15); //CGSize dim; dim.width = 50.0f; dim.height = 20.0f; char currencyStr[32]; if(s_UpgradeItemCost[i][unlockLevel[i]] > 0) sprintf(currencyStr,"$%d",s_UpgradeItemCost[i][unlockLevel[i]]); else sprintf(currencyStr,"Max"); CCLabelBMFont *BMfontLabel = CCLabelBMFont::create(currencyStr,"JacobyICGBlack18pnt.fnt"); BMfontLabel->setAnchorPoint(ccp(1.0f,0.5f)); BMfontLabel->setPosition(ccp(COST_X,COST_Y)); m_UpgradeCosts[i] = BMfontLabel; temp->addChild(BMfontLabel); temp->setScale(scale); menu->addChild(temp); m_UpgradeButtons[i] = temp; } }
void WordPuzzleLayer::didCorrectCharacterSelected(CCArray* wordIdxArray, int index) { //맥스 콤보 업데이트 combo++; if (report.maxCombo < combo) { report.maxCombo = combo; } SimpleAudioEngine::sharedEngine()->playEffect("sound/main_card_popup.mp3"); char buf[20]; CCSprite* sprMultiplier; if (combo < 5) { sprMultiplier = NULL; multiplier = 1; } else if (combo < 10) { // x2 #if (defined PD_IPHONE) || (defined ANDROID_PHONE) sprMultiplier = CCSprite::spriteWithFile(__CONFIG_IMAGE_PATH_GAME__("effect/game_double_01.png")); #else sprMultiplier = CCSprite::spriteWithFile("game/effect/game_double_01.png"); #endif multiplier = 2; } else if (combo < 20) { // x4 #if (defined PD_IPHONE) || (defined ANDROID_PHONE) sprMultiplier = CCSprite::spriteWithFile(__CONFIG_IMAGE_PATH_GAME__("effect/game_double_02.png")); #else sprMultiplier = CCSprite::spriteWithFile("game/effect/game_double_02.png"); #endif multiplier = 4; } else if (combo < 30) { // x8 #if (defined PD_IPHONE) || (defined ANDROID_PHONE) sprMultiplier = CCSprite::spriteWithFile(__CONFIG_IMAGE_PATH_GAME__("effect/game_double_03.png")); #else sprMultiplier = CCSprite::spriteWithFile("game/effect/game_double_03.png"); #endif multiplier = 8; } else if (combo < 50) { // x16 #if (defined PD_IPHONE) || (defined ANDROID_PHONE) sprMultiplier = CCSprite::spriteWithFile(__CONFIG_IMAGE_PATH_GAME__("effect/game_double_04.png")); #else sprMultiplier = CCSprite::spriteWithFile("game/effect/game_double_04.png"); #endif multiplier = 16; } else { #if (defined PD_IPHONE) || (defined ANDROID_PHONE) sprMultiplier = CCSprite::spriteWithFile(__CONFIG_IMAGE_PATH_GAME__("effect/game_double_05.png")); #else sprMultiplier = CCSprite::spriteWithFile("game/effect/game_double_05.png"); #endif multiplier = 32; } #if (defined PD_IPHONE) || (defined ANDROID_PHONE) CCSprite* label = CCSprite::spriteWithFile(__CONFIG_IMAGE_PATH_GAME__("effect/game_up.png")); #else CCSprite* label = CCSprite::spriteWithFile("game/effect/game_up.png"); #endif label->setPosition(pointLabelPosition); this->addChild(label, 9999); if (sprMultiplier) { sprMultiplier->setAnchorPoint(ccp(0,0.5)); #if (defined PD_IPHONE) || (defined ANDROID_PHONE) sprMultiplier->setPosition(ccp(label->getContentSize().width - 5,35)); #else sprMultiplier->setPosition(ccp(175,35)); #endif label->addChild(sprMultiplier); } label->setScale(0.2); CCEaseExponentialOut * fadeout = CCEaseExponentialOut::actionWithAction( CCActionTween::actionWithDuration(1.5,"opacity",255,0) ); CCCallFuncN* callfunc = CCCallFuncN::actionWithTarget(this, callfuncN_selector(WordPuzzleLayer::onPointLabelFadeOut)); label->runAction(CCMoveBy::actionWithDuration(0.8, ccp(0,100))); label->runAction(CCEaseBounceInOut::actionWithAction(CCScaleTo::actionWithDuration(0.3,labelScaleTo))); label->runAction(CCSequence::actions(CCDelayTime::actionWithDuration(0.7),fadeout,callfunc, NULL)); if (combo > 2) { sprintf(buf, "%dCombo",combo); CCLabelBMFont* lblCombo = (CCLabelBMFont*)getChildByTag(TAG_COMBO); CCEaseExponentialOut * fadeout = CCEaseExponentialOut::actionWithAction( CCActionTween::actionWithDuration(1.5,"opacity",255,0) ); CCCallFuncN* callfunc = CCCallFuncN::actionWithTarget(this, callfuncN_selector(WordPuzzleLayer::onPointLabelFadeOut)); if (lblCombo) { lblCombo->setString(buf); lblCombo->stopAllActions(); lblCombo->setOpacity(255); lblCombo->setPosition(comboLabelPosition); lblCombo->setScale(0.2); lblCombo->runAction(CCEaseBounceInOut::actionWithAction(CCScaleTo::actionWithDuration(0.3,labelScaleTo))); lblCombo->runAction(CCSequence::actions(CCDelayTime::actionWithDuration(1.5),fadeout,callfunc, NULL)); } else { lblCombo = CCLabelBMFont::labelWithString(buf, "font/combo.fnt"); lblCombo->setPosition(comboLabelPosition); this->addChild(lblCombo, 9999, TAG_COMBO); lblCombo->setScale(0.2); lblCombo->runAction(CCEaseBounceInOut::actionWithAction(CCScaleTo::actionWithDuration(0.3,labelScaleTo))); lblCombo->runAction(CCSequence::actions(CCDelayTime::actionWithDuration(1.5),fadeout,callfunc, NULL)); } } }
GameLayer::GameLayer() { gameSuspended = true; isGameOver = false; fuelInTank = 3600; // one minute worth CCSpriteBatchNode* batchNode = dynamic_cast<CCSpriteBatchNode*>(getChildByTag(kSpriteManager)); // Initialize all the platforms. Really? They predraw all the platforms?? _initPlatforms(); // We don't need a packed sprite, we can pick individual textures. Here we are getting the sprite for the bird CCSprite* bird = CCSprite::createWithTexture(batchNode->getTexture(), CCRectMake(608, 16, 44, 32)); batchNode->addChild(bird, 4, kBird); // add the exit arrow CCSprite* exit = CCSprite::create("exit_arrow.png"); exit->setTag(kExit); exit->setVisible(false); addChild(exit); CCSize landscapeSize = CCDirector::sharedDirector()->getVisibleSize(); CCSize visibleSize = CCSize(landscapeSize.width, landscapeSize.height); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); pHealthSprite = CCSprite::create("health_bar.png"); //pHealthSprite->setPosition(ccp(origin.x + 10, visibleSize.height - 20)); pHealthSprite->setAnchorPoint(ccp(0.0, 0.0)); //pHealthSprite->setScaleY(0.02); //pHealthSprite->setScaleX(100); pHealthBar = CCProgressTimer::create(pHealthSprite); pHealthBar->setScale(0.5, 0.5); pHealthBar->setType(kCCProgressTimerTypeBar); //pHealthBar->setMidpoint(ccp(0,0)); pHealthBar->setBarChangeRate(ccp(1,0)); pHealthBar->setPercentage(100); pHealthBar->setPosition(ccp(origin.x+10, visibleSize.height - 20)); this->addChild(pHealthBar); CCSprite* bonus; // the bonus sprites which say 5, 10 etc can be picked from here for(int i = 0; i < kNumBonuses; i++) { bonus = CCSprite::createWithTexture(batchNode->getTexture(), CCRectMake(608 + i * 32, 256, 25, 25)); batchNode->addChild(bonus, 4, kBonusStartTag + i); bonus->setVisible(false); } // TODO: read the sprite for the Exit door - add the tag "Exit to it" CCLabelBMFont* scoreLabel = CCLabelBMFont::create("0", "bitmapFont.fnt"); addChild(scoreLabel, 5, kScoreLabel); scoreLabel->setPosition(ccp(160, 430)); _startGame(); scheduleUpdate(); // We don't want touch interaction setTouchEnabled(false); setAccelerometerEnabled(true); }
void GameLayer::update(float dt) { if(gameSuspended) return; // MainLayer shows the background with clouds that does just scrolls but does not interact MainLayer::update(dt); CCSpriteBatchNode* batchNode = dynamic_cast<CCSpriteBatchNode*>(getChildByTag(kSpriteManager)); CCSprite* bird = dynamic_cast<CCSprite*>(batchNode->getChildByTag(kBird)); bird_position.x += bird_velocity.x * dt; // birdLookingRight/Left is used to flip the bird in the right direction i.e. direction of the velocity // so the bird does not travel backwards if(bird_velocity.x < -30.0f && birdLookingRight) { birdLookingRight = false; // what is the point of setting scaleX? bird->setScaleX(-1.0f); } else if(bird_velocity.x > 30.0f && !birdLookingRight) { birdLookingRight = true; bird->setScaleX(1.0f); } CCSize bird_size = bird->getContentSize(); float max_x = SCREEN_WIDTH + bird_size.width * 0.5f; float min_x = -bird_size.width * 0.5f; if(bird_position.x > max_x) bird_position.x = min_x; if(bird_position.x < min_x) bird_position.x = max_x; bird_velocity.y += bird_acceleration.y * dt; bird_position.y += bird_velocity.y * dt; // TODO: (fix this hack) - just set it so that every 20 frames, we decrease the percentage by 1 // when the percentage goes below zero, the healthbar is finished and finish the game // We should show some animation that the health is over. fuelInTank--; if (fuelInTank%20 == 0) { pHealthBar->setPercentage(pHealthBar->getPercentage()-1.0); if (pHealthBar->getPercentage() <= 0) { _showHighScores(); } } CCSprite* bonus = dynamic_cast<CCSprite*>(batchNode->getChildByTag(kBonusStartTag + currentBonusType)); // check if the bonus node is visible if(bonus->isVisible()) { // check if the bird and the bonus are colliding, if so, give the bird the bonus CCPoint bonus_position = bonus->getPosition(); float range = 20.0f; if(bird_position.x > bonus_position.x - range && bird_position.x < bonus_position.x + range && bird_position.y > bonus_position.y - range && bird_position.y < bonus_position.y + range) { // TODO: Our bonuses should be more rocket fuel or additional lives switch(currentBonusType) { case kBonus5: score += 5000; break; case kBonus10: score += 10000; break; case kBonus50: score += 50000; break; case kBonus100: score += 100000; break; } CCString* scoreStr = CCString::createWithFormat("%d", score); CCLabelBMFont* scoreLabel = dynamic_cast<CCLabelBMFont*>(getChildByTag(kScoreLabel)); scoreLabel->setString(scoreStr->getCString()); CCScaleTo* action1 = CCScaleTo::create(0.2f, 1.5f, 0.8f); CCScaleTo* action2 = CCScaleTo::create(0.2f, 1.0f, 1.0f); // What are CCScaleTo and CCSequence.. what do these actions do? // Likely, this just makes the bird move up very fast without it having to collide with anything CCSequence* action3 = CCSequence::create(action1, action2, action1, action2, action1, action2, NULL); scoreLabel->runAction(action3); // what does resetBonus do? _resetBonus(); _superJump(); } } int cloudTag; int platformTag; // bird collisions with platforms are detected only when the bird is falling down if(bird_velocity.y < 0) { for(platformTag = kPlatformsStartTag; platformTag < kPlatformsStartTag + K_NUM_PLATFORMS; platformTag++) { CCSprite* platform = dynamic_cast<CCSprite*>(batchNode->getChildByTag(platformTag)); CCSize platform_size = platform->getContentSize(); CCPoint platform_position = platform->getPosition(); max_x = platform_position.x - platform_size.width * 0.5f - 10; min_x = platform_position.x + platform_size.width * 0.5f + 10; float min_y = platform_position.y + (platform_size.height + bird_size.height) * 0.5f - K_PLATFORM_TOP_PADDING; // check if the bird and the platform is colliding, if so, make the bird jump if(bird_position.x > max_x && bird_position.x < min_x && bird_position.y > platform_position.y && bird_position.y < min_y) _jump(); } // The game is endless in the original version.. when the bird falls down and is longer on the screen, call the game done and // show the high score screen if(bird_position.y < - bird_size.height) _showHighScores(); } else if(bird_position.y > SCREEN_HEIGHT * 0.5f) { float delta = bird_position.y - SCREEN_HEIGHT * 0.5f; bird_position.y = SCREEN_HEIGHT * 0.5f; currentPlatformY -= delta; for(cloudTag = kCloudsStartTag; cloudTag < kCloudsStartTag + K_NUM_CLOUDS; cloudTag++) { CCSprite* cloud = dynamic_cast<CCSprite*>(batchNode->getChildByTag(cloudTag)); CCPoint position = cloud->getPosition(); position.y -= delta * cloud->getScaleY() * 0.8f; // assuming that the clouds in the background, when they have scrolled off the screen // reset them so that they will scroll in from the bottom if(position.y < -cloud->getContentSize().height * 0.5f) { currentCloudTag = cloudTag; resetCloud(); } else { cloud->setPosition(position); } } for(platformTag = kPlatformsStartTag; platformTag < kPlatformsStartTag + K_NUM_PLATFORMS; platformTag++) { CCSprite* platform = dynamic_cast<CCSprite*>(batchNode->getChildByTag(platformTag)); CCPoint position = platform->getPosition(); position = ccp(position.x, position.y - delta); // If the platform just became invisible, reset it to just above the screen if(position.y < -platform->getContentSize().height * 0.5f) { currentPlatformTag = platformTag; _resetPlatform(); } else { // If the platform is still visible, decrease its Y coordinates so it looks like the scene is scrolling platform->setPosition(position); } } CCSprite* exit = dynamic_cast<CCSprite*>(getChildByTag(kExit)); if(exit->isVisible()) { CCPoint position = exit->getPosition(); // check if the bird and the exit are colliding, if so, finish the game float range = 20.0f; if(bird_position.x > position.x - range && bird_position.x < position.x + range && bird_position.y > position.y - range && bird_position.y < position.y + range) { // TODO: (would be nice to show an animation when exiting) _showHighScores(); } position.y -= delta; if(position.y < -exit->getContentSize().height*0.5) { // the exit just passed out of the screen... you should show a "Game Over... you lose" kind of thing here // TODO: show an animation or something like... you lose!! _showHighScores(); } exit->setPosition(position); } // if the bonus was visible and is going to become invisible, reset it. if(bonus->isVisible()) { CCPoint position = bonus->getPosition(); position.y -= delta; if(position.y < -bonus->getContentSize().height * 0.5f) { _resetBonus(); } else { bonus->setPosition(position); } } score += (int) delta; CCString* scoreStr = CCString::createWithFormat("%d", score); CCLabelBMFont* scoreLabel = dynamic_cast<CCLabelBMFont*>(getChildByTag(kScoreLabel)); scoreLabel->setString(scoreStr->getCString()); } // draw the bird at its new position bird->setPosition(bird_position); }
AtlasBitmapColor::AtlasBitmapColor() { CCSize s = CCDirector::sharedDirector()->getWinSize(); CCLabelBMFont* label = NULL; label = CCLabelBMFont::labelWithString("Blue", "fonts/bitmapFontTest5.fnt"); label->setColor( ccBLUE ); addChild(label); label->setPosition( ccp(s.width/2, s.height/4) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ); label = CCLabelBMFont::labelWithString("Red", "fonts/bitmapFontTest5.fnt"); addChild(label); label->setPosition( ccp(s.width/2, 2*s.height/4) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ); label->setColor( ccRED ); label = CCLabelBMFont::labelWithString("G", "fonts/bitmapFontTest5.fnt"); addChild(label); label->setPosition( ccp(s.width/2, 3*s.height/4) ); label->setAnchorPoint( ccp(0.5f, 0.5f) ); label->setColor( ccGREEN ); label->setString("Green"); }