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 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));
}
Пример #3
0
//定时执行分数自动增减
void CFScoreBoard::doAutoScore(ccTime dt){
    if(scorePerSec == 0 && ((int)dt%60)!=0){
        return;
    }
    this->score+=scorePerSec;
    int num = cun(score);
    for(int i = 0; i < num;i++){
        int slot = pow(10.0,i);
        int digital = (score/slot)%10;
        char* buffer = new char[5];
        sprintf(buffer, "%d", digital);
        CCLabelBMFont* pLabel =(CCLabelBMFont*) this->getChildByTag(i);
        if(!pLabel){
            pLabel =  CCLabelBMFont::labelWithString(buffer,"fonts/fonts.fnt");
            CCSize labelsize = pLabel->getContentSize();
            pLabel->setPosition(ccp(width-i*20,height/2));
            pLabel->setTag(i);
            this->addChild(pLabel);
        }else{
            pLabel->setString(buffer);
        }
        this->doChangeAnimation(scorePerSec);
        delete[] buffer;
    }
}
void SpellIntroPage::initItem()
{
    ResourceMgr *mgr = ResourceMgr::getInstance();
    LangDef *lang = mgr->getLangDef();
    m_scroll = new VerScrollWidget();
    this->addChild(m_scroll);
    m_scroll->setFill("parent");
    const std::vector<std::string> &props = mgr->propsNames();
    int introstart = StringEnum::StormIntro;
    float width = m_anchorWidth * 0.9;
    std::string animName,first;
    for(unsigned int i = 0;i < props.size();i++){
        const std::string &prop = props[i];
        animName = prop + "exec";
        first = animName;
        mgr->getFrameSpriteFirstFrame(first);
        if(first.empty())
            continue;
        BasAnimSprite *anim = new BasAnimSprite(animName,first);
        anim->setAnimFinishCB(this,callfuncND_selector(SpellIntroPage::onSpellFinished));
        m_animMap.insert(std::make_pair(prop,anim));
        std::string logoName = prop + ".png";
        CCSprite *spellLogo = CCSprite::createWithSpriteFrameName(logoName.data());
        CCSize animSize = spellLogo->getContentSize();
        spellLogo->addChild(anim);
        anim->setAnchorPoint(ccp(0.5,0.5));
        anim->setPosition(ccp(animSize.width/2,animSize.height/2));
        anim->setVisible(false);

        const std::string introContent = lang->getStringById(introstart + i);
        CCLabelBMFont *introSprite = CCLabelBMFont::create(introContent.data(),"fonts/font20.fnt",width*0.6,kCCTextAlignmentLeft);
        CCSize fontSize = introSprite->getContentSize();
        CCSize size = CCSizeMake(width,MAX(animSize.height,fontSize.height));

        FSizeNullDelegate *dele = new FSizeNullDelegate(size);
        FSizeCCNodeDelegate *animDele = new FSizeCCNodeDelegate(spellLogo);
        animDele->setCanTouch(true);
        animDele->setClickCB(this,callfuncND_selector(SpellIntroPage::onSpellClicked));
        animDele->setName(prop);
        dele->addChild(animDele);
        animDele->setVertical("parent",0.5);
        animDele->setHorizontal("parent",0.2);

        FSizeCCNodeDelegate *fontDele = new FSizeCCNodeDelegate(introSprite);
        dele->addChild(fontDele);
        fontDele->setVertical("parent",0.5);
        fontDele->setHorizontal("parent",0.7);
        m_scroll->addFixedSizeWidget(dele);
    }
    m_scroll->setSpacing(10);
}
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);
}
Пример #7
0
KDbool CScrGame::init ( KDvoid )
{    
	if ( !CCLayer::init ( ) )
	{
		return KD_FALSE;
	}
    
	const CCSize&  tWinSize = CCDirector::sharedDirector ( )->getWinSize ( );

    m_uiDamaged = g_pResMgr->getSprite ( this, eIMG_Effect_Damaged );
    m_uiDamaged->setPosition ( ccpMid ( tWinSize ) );
    m_uiDamaged->setVisible ( KD_FALSE );
       
    m_uiEmergency = g_pResMgr->getSprite ( this, eIMG_Effect_Low_HP );
    m_uiEmergency->setPosition ( ccpMid ( tWinSize ) );
    m_uiEmergency->setVisible ( KD_FALSE );
    
    m_uiLayer = CCLayer::create ( );
    this->addChild ( m_uiLayer );
    
    m_uiEnergy = g_pResMgr->getProgress ( m_uiLayer, eIMG_Player_HP_Red );
    {
        const CCSize&  tSize = m_uiEnergy->getContentSize ( );
        
        m_uiEnergy->setPosition ( ccp ( tWinSize.cx - tSize.cx - 20, tWinSize.cy - tSize.cy / 2 - 20 ) );        
        m_uiEnergy->setAnchorPoint ( ccp ( 0, 0.5f ) );
        m_uiEnergy->setType ( kCCProgressTimerTypeBar );
        m_uiEnergy->setMidpoint ( ccp ( 1, 0 ) );
        m_uiEnergy->setBarChangeRate ( ccp ( 1, 0 ) );
        m_uiEnergy->setPercentage ( 100 );  
        
        CCLabelBMFont*  uiLabel = g_pResMgr->getLabel ( m_uiEnergy, "H" );        
        uiLabel->setPosition ( ccp ( -uiLabel->getContentSize ( ).cx / 2 - 10, tSize.cy / 2 ) );
    }
    
    m_uiScore = g_pResMgr->getLabel ( m_uiLayer, "Score : 0" );
    m_uiScore->setPosition ( ccp ( tWinSize.cx / 2 - 30, tWinSize.cy - m_uiScore->getContentSize ( ).cy ) );
    
    m_uiMode  = g_pResMgr->getLabel ( m_uiLayer, "Touch Mode " );
    m_uiMode->setAnchorPoint ( ccp ( 0, 0.5f ) );
    m_uiMode->setPosition ( ccp ( 150, tWinSize.cy - m_uiScore->getContentSize ( ).cy ) );
    
    m_uiRader = g_pResMgr->getSprite ( m_uiLayer, eIMG_BTN_Pad_BG );
    {
        const CCSize&  tSize = m_uiRader->getContentSize ( );
        
        m_uiRader->setPosition ( ccp ( tSize.cx / 2 + 20 , tWinSize.cy - tSize.cy / 2 - 90 ) );
    }
    
    m_uiWeapon = g_pResMgr->getSprite ( m_uiLayer, eIMG_Icon_Weapons, 0 );
    {
        const CCSize&  tSize = m_uiWeapon->getContentSize ( );
        
        m_uiWeapon->setPosition ( ccp ( tWinSize.cx - tSize.cx / 2 - 20 , tWinSize.cy - tSize.cy / 2 - 60 ) );
    }
    
	CCMenuItemSprite*  pPause = g_pResMgr->getMenuItemSprite
    (
        m_uiLayer, eIMG_BTN_Pause_Nor, ePath_Null, this, menu_selector ( CScrGame::onPause )
    );
    {
        const CCSize&  tSize = pPause->getContentSize ( );
        
        pPause->setPosition ( ccp ( tSize.cx / 2 + 20, tWinSize.cy - tSize.cy / 2 - 20 ) );    
    }
    
	CCMenuItemSprite*  pMode = g_pResMgr->getMenuItemSprite
    (
        m_uiLayer, eIMG_BTN_Pause_Nor, ePath_Null, this, menu_selector ( CScrGame::onMode )
    );
    {
        const CCSize&  tSize = pMode->getContentSize ( );
        
        pMode->setPosition ( ccp ( tSize.cx / 2 + 90, tWinSize.cy - tSize.cy / 2 - 20 ) );    
    }
    
    for ( KDuint i = 0; i < 2; i++ )
    {
        CCSprite*  uiBullet = g_pResMgr->getSprite ( m_uiLayer, eIMG_Bullet );
        {
            const CCSize&  tSize = uiBullet->getContentSize ( );
            
            uiBullet->setPosition ( ccp ( tWinSize.cx - tSize.cx / 2 - 20 , tWinSize.cy - tSize.cy / 2 - ( i == 0 ? 150 : 190 ) ) );        
            
            m_uiBulletNum[i] = g_pResMgr->getLabel ( uiBullet, "  6 x" );        
            m_uiBulletNum[i]->setPosition ( ccp ( - tSize.cx / 2, tSize.cy / 2 ) );
        }
        
        m_uiTarget[i][0] = g_pResMgr->getSprite( m_uiLayer, eIMG_Target_Out );
        m_uiTarget[i][1] = g_pResMgr->getSprite( m_uiTarget[i][0], eIMG_Target_In );        
        m_uiTarget[i][0]->setPosition ( ccp ( tWinSize.cx / 2 + ( i == 0 ? -10 : 10 ), tWinSize.cy / 2 ) );
        m_uiTarget[i][1]->setPosition ( ccpMid ( m_uiTarget[i][0]->getContentSize ( ) ) );      
        m_uiTarget[i][1]->setVisible ( KD_FALSE );
        
        m_uiPad[i][0] = g_pResMgr->getSprite ( this, eIMG_BTN_Pad_BG );
        m_uiPad[i][1] = g_pResMgr->getSprite ( m_uiPad[i][0], eIMG_BTN_Pad_Nor );
        m_uiPad[i][2] = g_pResMgr->getSprite ( m_uiPad[i][0], eIMG_BTN_Pad_Sel );
        {
            const CCSize&  tSize = m_uiPad[i][0]->getContentSize ( );
            
            m_uiPad[i][0]->setPosition ( ccp ( i == 0 ? tSize.cx / 2 + 20 : tWinSize.cx - tSize.cx / 2 - 20, tSize.cy / 2 + 20 ) );
            m_uiPad[i][1]->setPosition ( ccpMid ( tSize ) );
            m_uiPad[i][2]->setPosition ( ccpMid ( tSize ) );
            m_uiPad[i][1]->setTag ( i );
            m_uiPad[i][2]->setVisible ( KD_FALSE );
        }        
        
        CCMenuItemSprite*  uiReload = g_pResMgr->getMenuItemSprite
        (
            m_uiLayer, eIMG_BTN_Reload_Nor, ePath_Null, this, menu_selector ( CScrGame::onReload )
        );        
        {
            const CCSize&  tSize = uiReload->getContentSize ( );
            
            uiReload->setPosition ( ccp ( i == 0 ? tSize.cx / 2 + 20 : tWinSize.cx - tSize.cx / 2 - 20, tSize.cy / 2 + 160 ) );
            uiReload->setTag ( i );            
        }
    }
    
    CCMenuItemSprite*  uiChange = g_pResMgr->getMenuItemSprite
    (
        m_uiLayer, eIMG_BTN_Change_Nor, ePath_Null, this, menu_selector ( CScrGame::onChange )
    );        
    {
        const CCSize&  tSize = uiChange->getContentSize ( );
        
        uiChange->setPosition ( ccp ( tWinSize.cx - tSize.cx / 2 - 160, tSize.cy / 2 + 20 ) );
    }    
    
    // Clear Scene
    g_pEngMgr->getScene ( )->clear ( );
    g_pEngMgr->getTimer ( )->stop  ( );
    
    // Create World
    m_pWorld    = new CWorld   ( );
    m_pWeapon   = new CWeapon  ( );
    m_pTarget   = new CTarget  ( );
    m_pBullet   = new CBullet  ( );
    m_pEnemies  = new CEnemies ( );
    
    m_pWorld  ->init ( );
    m_pWeapon ->init ( );
    m_pTarget ->init ( m_pWorld->getNode ( ) );
    m_pEnemies->init ( m_pWorld->getPosition ( ), m_pWorld->getSpawnDist ( ), m_uiRader );
    
    g_pResMgr->getSound ( eSND_Effect_Heart );
    g_pResMgr->getSound ( eSND_Player_Harm );
    g_pResMgr->getSound ( eSND_Player_Dead );
    
    this->setTouchMode ( kCCTouchesOneByOne );
    this->setTouchEnabled ( KD_TRUE );
    this->setEventEnabled ( KD_TRUE );
    this->setClipping     ( KD_TRUE );
    
    m_bUseSensor   = KD_FALSE;    
    m_bTargetCtl   = KD_FALSE;
    m_uWeaponIndex = 0;
    
    g_pEnvMgr->setScore ( 0 );
    g_pEnvMgr->setEnergy ( 100 );
    
    for ( KDint i = 0; i < 2; i++ )
    {
        m_uBulletNum[i][0] = m_uBulletNum[i][1] = m_pWeapon->getBulletNum ( i );
    }
    
    refreshBulletLabel ( 0 );
    refreshBulletLabel ( 1 );
    
	return KD_TRUE;
}
Пример #8
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;
}