Example #1
0
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;
}
void PauseLayer::createLabel(const char *labelName, const char *labelNameValue, CCPoint position, CCSprite *objective) {
    float scale = Utility::isIPad() ? 1 : 0.5;
    CCLabelBMFont *label = CCLabelBMFont::create(labelName, kFontChubby,  0, kCCTextAlignmentLeft);
    label->setPosition(position);
    label->setScale(scale);
    label->setAnchorPoint(ccp(0, 1));
    objective-> addChild(label, 10);
    CCLabelBMFont *labelText = CCLabelBMFont::create(labelNameValue, kFontChubby, winSize.width * 0.4);
    //    labelText->
    labelText->setPosition(ccp(label->getPositionX(), label->getPositionY() - winSize.height * 0.078 ));
    labelText->setScale(scale * 0.65);
    labelText->setAnchorPoint(ccp(0, 1));
    objective->addChild(labelText, 10);
}
void GuessSpellItem::showGift()
{
    m_showNode = CCNode::create();
    std::string imgName;
    PropDef::getVirtualPropsName(m_giftType,imgName);
    imgName += ".png";
    CCSprite *giftSprite = CCSprite::createWithSpriteFrameName(imgName.data());
    std::stringstream ss;
    ss << "x" << m_giftCount;
    CCLabelBMFont *giftNum = CCLabelBMFont::create(ss.str().data(),"fonts/font20.fnt");
    CCSize giftSize = giftSprite->getContentSize();
    CCSize numSize = giftNum->getContentSize();
    CCSize size = CCSizeMake(MAX(giftSize.width,numSize.width),giftSize.height + numSize.height);
    m_showNode->setContentSize(size);
    m_showNode->addChild(giftSprite);
    m_showNode->addChild(giftNum);
    giftSprite->setAnchorPoint(ccp(0,1.0));
    giftSprite->setPosition(ccp(0,size.height));
    giftNum->setAnchorPoint(ccp(0.5,0));
    giftNum->setPosition(ccp(size.width/2,0));
    this->CCNode::addChild(m_showNode,100);
    m_showNode->setAnchorPoint(ccp(0.5,0.5));
    m_showNode->setPosition(ccp(m_anchorWidth/2,m_anchorHeight/2));
    m_showNode->setVisible(true);
    m_showNode->runAction(CCSequence::create(CCScaleTo::create(0.5,10),
                          CCCallFuncN::create(this,callfuncN_selector(GuessSpellItem::onShowGiftFinished)),0));
}
Example #4
0
CCNode* KCardActor::ShowHit(const char* slot,K3DActionParam* param,float scale,bool bGood)
{
	int val = param->GetVal(m_card->GetRealId());

	UIWidget* widget = GetWidget(slot);
	char msg[64];
	if(val >0){
		sprintf(msg,"+%d",val);
	}else{
		if(bGood){
			sprintf(msg,"+%d",val);
		}else{
			if(val==0)
				sprintf(msg,"-%d",val);
			else
				sprintf(msg,"%d",val);
		}
	}
	CCLabelBMFont* bmFont = CCLabelBMFont::create(msg,"GUI/num_1.fnt");
	bmFont->setAnchorPoint(ccp(0.50f,0.50f));
	bmFont->setPosition(widget->getWorldPosition());
	KUIAssist::_activeSceneLayer()->addChild(bmFont,100);

	bmFont->setScale(scale);
	m_objectDict.setObject(bmFont, "hit_text");
	return bmFont;
}
Example #5
0
Atlas5::Atlas5()
{
	CCLabelBMFont *label = CCLabelBMFont::labelWithString("abcdefg", "fonts/bitmapFontTest4.fnt");
	addChild(label);
	
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	
	label->setPosition( ccp(s.width/2, s.height/2) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
}
Example #6
0
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) ); 
}
Example #7
0
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) ); 
}
Example #8
0
//------------------------------------------------------------------
//
// Atlas4
//
//------------------------------------------------------------------
Atlas4::Atlas4()
{
	m_time = 0;

	// Upper Label
	CCLabelBMFont *label = CCLabelBMFont::labelWithString("Bitmap Font Atlas", "fonts/bitmapFontTest.fnt");
	addChild(label);
	
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	
	label->setPosition( ccp(s.width/2, s.height/2) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
	
	
	CCSprite* BChar = (CCSprite*) label->getChildByTag(0);
	CCSprite* FChar = (CCSprite*) label->getChildByTag(7);
	CCSprite* AChar = (CCSprite*) label->getChildByTag(12);
	
	
	CCActionInterval* rotate = CCRotateBy::actionWithDuration(2, 360);
	CCAction* rot_4ever = CCRepeatForever::actionWithAction(rotate);
	
	CCActionInterval* scale = CCScaleBy::actionWithDuration(2, 1.5f);
	CCActionInterval* scale_back = scale->reverse();
	CCFiniteTimeAction* scale_seq = CCSequence::actions(scale, scale_back,NULL);
	CCAction* scale_4ever = CCRepeatForever::actionWithAction((CCActionInterval*)scale_seq);
	
	CCActionInterval* jump = CCJumpBy::actionWithDuration(0.5f, CCPointZero, 60, 1);
	CCAction* jump_4ever = CCRepeatForever::actionWithAction(jump);
	
	CCActionInterval* fade_out = CCFadeOut::actionWithDuration(1);
	CCActionInterval* fade_in = CCFadeIn::actionWithDuration(1);
	CCFiniteTimeAction* seq = CCSequence::actions(fade_out, fade_in, NULL);
	CCAction* fade_4ever = CCRepeatForever::actionWithAction((CCActionInterval*)seq);
	
	BChar->runAction(rot_4ever);
	BChar->runAction(scale_4ever);
	FChar->runAction(jump_4ever);
	AChar->runAction(fade_4ever);
	
	
	// Bottom Label
	CCLabelBMFont *label2 = CCLabelBMFont::labelWithString("00.0", "fonts/bitmapFontTest.fnt");
	addChild(label2, 0, kTagBitmapAtlas2);
	label2->setPosition( ccp(s.width/2.0f, 80) );
	
	CCSprite* lastChar = (CCSprite*) label2->getChildByTag(3);
	lastChar->runAction( (CCAction*)(rot_4ever->copy()->autorelease()) );
	
	schedule( schedule_selector(Atlas4::step), 0.1f);
}
Example #9
0
void TimeLayer::setupViews()
{
	do
	{
		CCLabelBMFont* pFnt = CCLabelBMFont::create("Time : 0s", "arial-14.fnt");
		pFnt->setAnchorPoint(CCPointZero);
		pFnt->setPosition(ccp(0, 0));
		pFnt->setScale(1.5);
		addChild(pFnt, 0, TIME_BM_FONT_TAG);

		schedule(schedule_selector(TimeLayer::tmWaste_Func), 1.0f);
	}
	while(0);
	
}
Example #10
0
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");
}
Example #11
0
AtlasFastBitmap::AtlasFastBitmap()
{
		// Upper Label
		for( int i=0 ; i < 100;i ++ ) 
		{
            char str[6] = {0};
            sprintf(str, "-%d-", i);
			CCLabelBMFont* label = CCLabelBMFont::labelWithString(str, "fonts/bitmapFontTest.fnt");
			addChild(label);
			
			CCSize s = CCDirector::sharedDirector()->getWinSize();

			CCPoint p = ccp( CCRANDOM_0_1() * s.width, CCRANDOM_0_1() * s.height);
			label->setPosition( p );
			label->setAnchorPoint(ccp(0.5f, 0.5f));
		}
}
Example #12
0
//设置武将
void GeneralHeadItem::setGeneral(boost::shared_ptr<General> general) {
    //頭像
    char namePath[50] = {0};
    sprintf(namePath, GENERAL_HEAD_FORMAT_PATH, general->getName().c_str());
    int originX = IMAGE_WIDTH - width_;
    originX = originX!=0 ? originX / 2: originX;
    CCSprite* head = CCSprite::create(namePath, CCRect(originX,0, width_, IMAGE_HEIGHT));
    head->setPosition(CCPointZero);
    head->setAnchorPoint(CCPointZero);
    this->addChild(head);


    //FRAME
    char framePath[50] = {0};
    sprintf(framePath, GENERAL_FRAME_FORMAT_PATH, general->getKingdom().c_str());


    CCSprite* frame = CCSprite::create(framePath);
    frame->setPosition(ccp(width_, IMAGE_HEIGHT));
    frame->setAnchorPoint(ccp(1,1));

    this->addChild(frame);

    //国标
    char kingdomPath[50] = {0};
    sprintf(kingdomPath, GENERAL_KINGDOM_FORMAT_PATH, general->getKingdom().c_str());


    CCSprite* kingdom = CCSprite::create(kingdomPath);
    kingdom->setPosition(ccp(width_ + 3, IMAGE_HEIGHT));
    kingdom->setAnchorPoint(ccp(1,1));

    this->addChild(kingdom);


    //名字
    CCLabelBMFont* chineseNameLabel = CCLabelBMFont::create(general->getChineseName().c_str(), GENERAL_BMFONT_PATH);

    chineseNameLabel->setPosition(ccp(width_ - 5, IMAGE_HEIGHT - 20));
    chineseNameLabel->setAnchorPoint(ccp(1,1));

    this->addChild(chineseNameLabel);
}
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;
}
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);
}
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);
}
Example #16
0
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);
}
Example #17
0
bool GameLayer::init(void)
{
	bool bRet = false;
	do 
	{
		CC_BREAK_IF(!CCLayer::init());

		// 游戏场景背景图
		CCSprite *bg = CCSprite::spriteWithFile("Space.png");
		CC_BREAK_IF(!bg);
		bg->setAnchorPoint(CCPointZero);
		// 为了突出游戏场景中的精灵,将背景色彩变淡
		bg->setOpacity(100);
		this->addChild(bg, 0, 1);

		// 使用位图字体显示游戏时间
		CCLabelBMFont* lbScore = CCLabelBMFont::labelWithString("Time: 0", "font09.fnt");
		CC_BREAK_IF(!lbScore);
		lbScore->setAnchorPoint(ccp(1, 1));
		lbScore->setScale(0.6f);
		this->addChild(lbScore, 1, 3);
		lbScore->setPosition(ccp(310, 450));

		// 载入飞船图像集
		CCSpriteBatchNode* mgr = CCSpriteBatchNode::batchNodeWithFile("flight.png", 5);
		CC_BREAK_IF(!mgr);
		this->addChild(mgr, 0, 4);

		// 在状态栏显示一个飞船的图标
		CCSprite* sprite = CCSprite::spriteWithTexture(mgr->getTexture(), CCRectMake(0, 0, 31, 30));
		CC_BREAK_IF(!sprite);
		mgr->addChild(sprite, 1, 5);
		sprite->setScale(1.1f);
		sprite->setAnchorPoint(ccp(0, 1));
		sprite->setPosition(ccp(10, 460));

		// 显示当前飞船生命条数
		CCLabelBMFont* lbLife = CCLabelBMFont::labelWithString("3", "font09.fnt");
		CC_BREAK_IF(!lbLife);
		lbLife->setAnchorPoint(ccp(0, 1));
		lbLife->setScale(0.6f);
		this->addChild(lbLife, 1, 6);
		lbLife->setPosition(ccp(50, 450));

		// 设定时间回调函数,修改游戏用时显示
		this->schedule(schedule_selector(GameLayer::step), 1.0f);

		// 显示飞船,飞船有不断闪烁的火焰喷射效果
		flight = CCSprite::spriteWithTexture(mgr->getTexture(), CCRectMake(0, 0, 31, 30));
		CC_BREAK_IF(!flight);
		flight->setPosition(ccp(160, 30));
		flight->setScale(1.6f);
		mgr->addChild(flight, 1, 99);

		// 设定动画每一帧的内容
		CCAnimation* animation = CCAnimation::animation();
		CC_BREAK_IF(!animation);
		animation->setName("flight");
		animation->setDelayPerUnit(0.2f);
		for (int i = 0; i < 3; ++i)
		{
			int x = i % 3;
			animation->addSpriteFrameWithTexture(mgr->getTexture(), CCRectMake(x*32, 0, 31, 30));
		}

		// 基于动画创建动作
		CCAnimate* action = CCAnimate::actionWithAnimation(animation);
		CC_BREAK_IF(!action);

		// 主角精灵不断重复动作,实现动态飞行效果
		flight->runAction(CCRepeatForever::actionWithAction(action));

		// accept touch now
		this->setTouchEnabled(true);

		bRet = true;
	} while (false);

	return bRet;
}
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::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::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;
	}
}
Example #21
0
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 GameOver::finishGetScores(JsonBox::Object js)
{
//	ostringstream oss;
//	oss << js << endl;
//	CCLog("**********************************************************************\n%s", oss.str().c_str());
	
	try {
		KS::KSLog("%", js);
		KS::KSLog("%", js["state"].getString().c_str());
		if(js["state"].getString() != "ok")
			throw string(gt("retrying").c_str());
		mediator->incLoadCount();
		CCLabelBMFont* allUsers = CCLabelBMFont::create(KS_Util::stringWithFormat("%d", js["alluser"].getInt()).c_str(), "main1.fnt");
//		allUsers->setColor(ccc3(0,0,0));
		allUsers->setPosition(ccp(226, 264));
		thiz->addChild(allUsers, 2);
		
		
		
		JsonBox::Array jList = js["list"].getArray();
		int st = js["timestamp"].getInt();
		int z = jList.size();

		float myrank = js["myrank"].getInt();
		int myscore = 0;
		int week = playInfo->currentWeek;
		for(int i=0; i<jList.size() && i < 10; i++)
		{
			JsonBox::Object entry = jList[i].getObject();
			string nick = entry["nick"].getString();
			int score = entry["score"].getInt();
			int duration;
			int rank = entry["rank"].getInt();
			
			duration = entry["playtime"].getInt();
//			if(entry["etime"].getInt() == 0) // 안끝났다면
//			{
//				duration = st - entry["stime"].getInt();
//			}
//			else
//			{
//				duration = entry["etime"].getInt() - entry["stime"].getInt();
//			}

			string mmss;
			if(duration < 3600)
			{
				mmss = KS_Util::stringWithFormat("%2d'%2d\"", (int)(duration / 60), duration % 60);
			}
			else
			{
				int hours = duration / 3600;
				if(hours > 100)
					mmss = KS_Util::stringWithFormat("inf", hours);
				else if(hours > 1)
					mmss = KS_Util::stringWithFormat("%d hrs", hours);
				else
					mmss = KS_Util::stringWithFormat("%d hr", hours);
			}
			
			CCLabelTTF* rankFnt;
			if(!(1 <= rank && rank <= 3))
			{
				rankFnt = CCLabelTTF::create(KS_Util::stringWithFormat("%d", entry["rank"].getInt()).c_str(), defaultFont, 12.f);
				rankFnt->setColor(ccc3(0, 0, 0));
				rankFnt->setPosition(position.rank[i]);
				thiz->addChild(rankFnt, 2);
			}
			CCSprite* flag = CCSprite::createWithSpriteFrameName(KS_Util::stringWithFormat("%s.png", entry["flag"].getString().c_str()).c_str());
			if(flag)
			{
				flag->setPosition(position.flag[i]);
				thiz->addChild(flag, 2);
				flag->setScale(0.9f);
			}
			CCLabelTTF* nickTTF = CCLabelTTF::create(nick.c_str(), defaultFont, 12.f);
			nickTTF->setColor(ccc3(0, 0, 0));
			nickTTF->setAnchorPoint(ccp(0.f, 0.5f));
			nickTTF->setPosition(position.user[i]);
			
			
			thiz->addChild(nickTTF, 2);
			
			CCLabelBMFont* scoreFnt = CCLabelBMFont::create(KS_Util::stringWithFormat("%d", score).c_str(), "rankscore.fnt");
			scoreFnt->setPosition(position.score[i]);
			scoreFnt->setAnchorPoint(ccp(1.f, 0.5f));
			
			
			thiz->addChild(scoreFnt, 2);
			
			CCLabelTTF* timeFnt = CCLabelTTF::create(mmss.c_str(), defaultFont, 12.f);
			timeFnt->setColor(ccc3(0, 0, 0));
			timeFnt->setPosition(position.time[i]);
			if(entry["isme"].getBoolean())
			{
				scoreFnt->setColor(ccc3(255, 0, 0));
				nickTTF->setColor(ccc3(255, 0, 0));
				timeFnt->setColor(ccc3(255, 0, 0));
				if(!(1 <= rank && rank <= 3))
					rankFnt->setColor(ccc3(255, 0, 0));
				myscore = score;
			}
			thiz->addChild(timeFnt, 2);
		}

		if(playInfo->currentGame == "AC")
		{
			putScore(playInfo->acscore, myscore, playInfo->acweekly, myrank, mediator);
		}
		else if(playInfo->currentGame == "AK")
		{
			putScore(playInfo->akscore, myscore, playInfo->akweekly, myrank, mediator);
		}
		else if(playInfo->currentGame == "BS")
		{
			putScore(playInfo->bsscore, myscore, playInfo->bsweekly, myrank, mediator);
		}
		else if(playInfo->currentGame == "HW")
		{
			putScore(playInfo->hwscore, myscore, playInfo->hwweekly, myrank, mediator);
		}
		else if(playInfo->currentGame == "SK")
		{
			putScore(playInfo->skscore, myscore, playInfo->skweekly, myrank, mediator);
		}
		else if(playInfo->currentGame == "HG")
		{
			putScore(playInfo->hgscore, myscore, playInfo->hgweekly, myrank, mediator);
		}
		else  if(playInfo->currentGame == "WORLDCUP")
		{
			putScore(playInfo->wcscore, myscore, playInfo->wcweekly, myrank, mediator);
		}
		CCLog("%d", playInfo->skscore);
		mediator->sendFacebookScore();
		rankPercent.init(1.f, (myrank / (float)js["alluser"].getInt()), 2.f);
		KS::KSLog("% % % ", position.endRankPosition.x, (position.beginRankPosition.x - position.endRankPosition.x), (myrank / (float)js["alluser"].getInt()));
		rankX.init(me->getPosition().x, position.endRankPosition.x + (position.beginRankPosition.x - position.endRankPosition.x) * (myrank / (float)js["alluser"].getInt()),
				   2.f);
		

		


		
	} catch (const string& msg) {
		mediator->showFailedGameOver(msg);
		
	}
	
	
	
}
Example #23
0
bool SecondLevel::init()
{
	if (!CCLayer::init())
	{
		return false;
	}

	isRemoved = false;
	isDone = false;
	CCSize winSize = CCDirector::sharedDirector()->getVisibleSize();

	CCSprite *bg = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/background.png"));
	bg->setPosition(ccp(winSize.width / 2, winSize.height / 2));
	this->addChild(bg, 0);

	rule_img = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/level2.png"));
	rule_img->setPosition(ccp(winSize.width / 2, winSize.height / 2));
	rule_img->setScale(0.4f);
	rule_img->setTag(10);
	this->addChild(rule_img, 1);

	forward_button = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/forward.png"));
	forward_button->setPosition(ccp(350,
		forward_button->getContentSize().height / 2 + CCDirector::sharedDirector()->getVisibleOrigin().y));
	rule_img->addChild(forward_button);

	key_img = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/level2_key_face.png"));
	key_img->setPosition(ccp(winSize.width / 2, winSize.height / 2));
	key_img->setVisible(false);
	this->addChild(key_img, 1);

	candidatite_img = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/level2_condaditate_faces.png"));
	candidatite_img->setPosition(ccp(winSize.width / 2, winSize.height / 2));
	candidatite_img->setScale(0.5f);
	candidatite_img->setVisible(false);
	this->addChild(candidatite_img, 1);


	result = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/result.png"));
	result->setPosition(ccp(winSize.width / 2, winSize.height / 2));
	result->setVisible(false);
	this->addChild(result, 1);

	CCSprite *back = CCSprite::createWithTexture(IMAGEPOOL->textureForKey("/pic/back.png"));
	back->setPosition(ccp(60, 100));
	back->setScale(0.7f);
	result->addChild(back);



	CCLabelBMFont *lbLife = CCLabelBMFont::create("20", "/word/font09.fnt");
	lbLife->setAnchorPoint(ccp(0, 1));
	lbLife->setScale(0.6f);
	lbLife->setPosition(ccp(winSize.width - 70, winSize.height - 1));
	lbLife->setVisible(false);
	this->addChild(lbLife, 1, 15);

	this->setTouchEnabled(true);
	this->setTag(0);
	return true;
}
Example #24
0
bool GameLayer::init()
{
    if (!CCLayer::init()) {
        return false;
    }
    // 开启触摸
    this->setTouchEnabled(true);
    
    // 创建数组,需要retain一下
    play_bullet = CCArray::create();
    play_bullet->retain();
    
    enemy_bullet = CCArray::create();
    enemy_bullet->retain();
    
    enemy_items = CCArray::create();
    enemy_items->retain();
    
    m_state = statePlaying;//statePlaying=0
    
    Enemy::sharedEnemy();
    Effect::sharedExplosion();
    
    Config::sharedConfig()->resetConfig();
    
    winSize = CCDirector::sharedDirector()->getWinSize();
    m_levelManager = new LevelManager(this);
    
    //初始化背景
    initBackground();

    m_screenRec = CCRectMake(0, 0,  winSize.width, winSize.height + 10);
    
    // score
	CCLabelBMFont *scoreLabel = CCLabelBMFont::create("SCORE: ", s_arial14_fnt);
	scoreLabel->setAnchorPoint(ccp(0, 0));
	addChild(scoreLabel, 1000);
	scoreLabel->setColor(ccc3(255, 240, 188));
	scoreLabel->setPosition(100, winSize.height - 30);
	{
		//  1 1 000
		m_lbScore1 = CCLabelBMFont::create("", s_arial14_fnt);
		m_lbScore1->setAnchorPoint(ccp(0, 0));
		m_lbScore1->setColor(ccc3(200,0,200));
		addChild(m_lbScore1, 1000);
		m_lbScore1->setPosition(scoreLabel->getPositionX()+scoreLabel->getContentSize().width, scoreLabel->getPositionY());
		//
		m_lbScore2 = CCLabelBMFont::create("", s_arial14_fnt);
		m_lbScore2->setAnchorPoint(ccp(0, 0));
		m_lbScore2->setColor(ccYELLOW);
		addChild(m_lbScore2, 1000);
		m_lbScore2->setPosition(m_lbScore1->getPositionX()+m_lbScore1->getContentSize().width, m_lbScore1->getPositionY());
		//
		m_lbScore3 = CCLabelBMFont::create("", s_arial14_fnt);
		m_lbScore3->setAnchorPoint(ccp(0, 0));
		addChild(m_lbScore3, 1000);
		m_lbScore3->setPosition(m_lbScore2->getPositionX()+m_lbScore2->getContentSize().width, m_lbScore2->getPositionY());
	}
    
    // ship life
    CCTexture2D *shipTexture = CCTextureCache::sharedTextureCache()->addImage(s_ship01);
    CCSprite *life = CCSprite::createWithTexture(shipTexture, CCRectMake(0, 0, 60, 38));
    life->setScale(0.6);
    life->setPosition(ccp(30,winSize.height-23));
    addChild(life, 1, 5);
    
    // ship life count
    char lifecount[2];
    sprintf(lifecount, "%d",Config::sharedConfig()->getLifeCount()-1);
    m_lifeCount = CCLabelTTF::create(lifecount, "Arial", 20);
    m_lifeCount->setPosition(ccp(60, winSize.height-20));
    m_lifeCount->setColor(ccc3(255,0, 0));
    addChild(m_lifeCount, 1000);
    
    // ship
    m_ship = Ship::create();
    addChild(m_ship, m_ship->getZoder(), 1001);
    
	//pause
    CCMenuItemImage *pause = CCMenuItemImage::create("pause.png", "pause.png", this, menu_selector(GameLayer::doPause));
    pause->setAnchorPoint(ccp(1, 1));
	pause->setScale(0.8);
	pause->setPosition(ccp(winSize.width, winSize.height));
    CCMenu *menu = CCMenu::create(pause, NULL);
    menu->setAnchorPoint(ccp(0, 0));
    addChild(menu, 1, 10);
    menu->setPosition(CCPointZero);
    
    // 调 update函数
    scheduleUpdate();
    
    // 每秒调一次 scoreCounter函数
    schedule(schedule_selector(GameLayer::scoreCounter), 1);
    
    if (Config::sharedConfig()->getAudioState()) {
        SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_bgMusic, true);
    }
    
    return true;
}