예제 #1
0
void HelloWorld::moveBlock()
{
	int pPillar = 20; // prior pillar (block-containing pillar)
	int newTopBlock = 20;
	CCMenuItemImage* pillar = ((CCMenuItemImage*)(this->getChildByTag(selectedPillar)->getChildByTag(selectedPillar)));
	CCMenuItemImage* block = ((CCMenuItemImage*)(this->getChildByTag(selectedBlock)->getChildByTag(selectedBlock)));

	// disable pillars, set to default
	for (int i=0 ; i<3 ; i++)
	{
		//((CCMenuItemImage*)((this->getChildByTag(i))->getChildByTag(i)))->setEnabled(false);
		//((CCMenuItemImage*)((this->getChildByTag(i))->getChildByTag(i)))->setOpacity(255);
		// determine block-containing pillar via boundingBox containsPoint fxn
		if (((CCMenuItemImage*)(this->getChildByTag(i)->getChildByTag(i)))->boundingBox().containsPoint(block->getPosition()) == true)
		{
			//CCLog("block-containing pillar is %i",i);
			pPillar = i;
			break;
		}
	}

	// loop through blocks for belowBlock
	float belowBlock = block->getPositionY() - bHeight;
	for (int x=3 ; x<10 ; x++)
	{
		if (((CCMenuItemImage*)((this->getChildByTag(x))->getChildByTag(x)))->boundingBox().containsPoint(ccp(block->getPositionX(),belowBlock)) == true)
		{
			//CCLog("belowBlock is block tag %i",x);
			newTopBlock = x;
			break;
		}
	}
	block->setPosition(ccp(pillar->getPositionX(),(-150+(bHeight*numBlock[selectedPillar]))));
	
	// add to number of blocks on selectedPillar
	numBlock[selectedPillar]++;
	//CCLog("pillar %i has %i blocks",selectedPillar,numBlock[selectedPillar]);
	
	// subtract number of blocks from priorPillar
	numBlock[pPillar]--;
	//CCLog("pillar %i has %i blocks",pPillar,numBlock[pPillar]);
	
	// set topBlock for selectedPillar
	topBlock[selectedPillar] = selectedBlock;
	//CCLog("pillar %i's top block is tag %i",selectedPillar,selectedBlock);
	
	// set topBlock for priorPillar
	topBlock[pPillar] = newTopBlock;
	//CCLog("pillar %i's top block is tag %i",pPillar,newTopBlock);
}
예제 #2
0
bool QuitScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    m_Sound = CCUserDefault::sharedUserDefault()->getBoolForKey("sound", true);

    CCPoint visibleOrigin = CCDirector::sharedDirector()->getVisibleOrigin();
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint visibleCenter = visibleOrigin + visibleSize / 2;

    CCSprite *sprite = CCSprite::create("bg1.jpg");
    sprite->setPosition(visibleCenter);
    addChild(sprite);

    float yesX = visibleOrigin.x + visibleSize.width * 0.08f;
    CCMenuItemImage *pYes = LGMenuItemImage::create("quit_yes.png", NULL, this, menu_selector(QuitScene::yesCallback));
    pYes->setPosition(ccp(yesX, visibleOrigin.y + visibleSize.height * 0.225f));

    int adMRectLeft = NativeBridge::getAdMobMRectLeft();
    CCMenuItemImage *pNo = LGMenuItemImage::create("quit_no.png", NULL, this, menu_selector(QuitScene::noCallback));
    float noX = visibleOrigin.x + visibleSize.width * 0.31875f;
    noX = MIN(noX, visibleOrigin.x + adMRectLeft - 42);
    pNo->setPosition(ccp(noX, pYes->getPositionY()));

    sprite = CCSprite::create("quit_title.png");
    sprite->setScale(0.72f);
    sprite->setPosition(ccp((yesX + noX) / 2, visibleOrigin.y + visibleSize.height * 0.7875f));
    addChild(sprite);

    CCMenuItemImage *pMore = LGMenuItemImage::create("more.png", NULL, this, menu_selector(QuitScene::moreCallback));
    pMore->setPosition(ccp(sprite->getPositionX(), visibleOrigin.y + visibleSize.height * 0.50625f));

    CCMenu *pMenu = CCMenu::create(pYes, pNo, pMore, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointZero);
    addChild(pMenu);

    return true;
}
예제 #3
0
bool LayerStart::init()
{
	CCLayer::init();

	// 先加背景图片
	CCSprite* bg = CCSprite::create("ScenceStart.png");
	addChild(bg);
	bg->setPosition(ccp(winSize.width/2, winSize.height/2));
	
	// 再加一个按钮
	CCMenuItemImage* item = CCMenuItemImage::create("playgameNormal.png", "playgameClose.png", 
		this, menu_selector(LayerStart::Start));
	CCMenu* menu = CCMenu::createWithItem(item);
	addChild(menu);

	item->setPositionY(item->getPositionY() - 50);

	return true;
}
예제 #4
0
void GameScene::showRateView()
{
    if (m_pRateLayer == NULL)
    {
        m_pRateLayer = LGLayerColor::create(ccc4(0, 0, 0, 0));
        m_pRateLayer->retain();
        m_pRateLayer->setTouchMode(kCCTouchesOneByOne);
        m_pRateLayer->setTouchEnabled(true);
        m_pRateLayer->setZOrder(3);

        CCSprite *pBg = CCSprite::create("rate_bg.png");
        pBg->setPosition(m_VisibleOrigin + m_VisibleSize / 2);
        m_pRateLayer->addChild(pBg);

        float bgW = pBg->getContentSize().width, bgH = pBg->getContentSize().height;
        CCMenuItemImage *pRate = LGMenuItemImage::create("rate_rate.png", NULL, this, menu_selector(GameScene::rateCallback));
        pRate->setPosition(ccp(pBg->getPositionX() - 0.2592593f * bgW, pBg->getPositionY() - 0.6566f * bgH));

        CCMenuItemImage *pLater = LGMenuItemImage::create("rate_later.png", NULL, this, menu_selector(GameScene::laterCallback));
        pLater->setPosition(ccp(pBg->getPositionX() + 0.2592593f * bgW, pRate->getPositionY()));

        CCMenu *pMenu = CCMenu::create(pRate, pLater, NULL);
        pMenu->setAnchorPoint(CCPointZero);
        pMenu->setPosition(CCPointZero);
        m_pRateLayer->addChild(pMenu);
    }

    if (m_pRateLayer && m_pRateLayer->getParent() == NULL)
    {
        getParent()->addChild(m_pRateLayer);
        CC_SAFE_RELEASE_NULL(m_CurrentLayer);
        m_CurrentLayer = m_pRateLayer;
        m_CurrentLayer->retain();
        onShowOverlay(true);
    }
}
예제 #5
0
bool MenuLayerPlayerSelect::init()
{
	if (CCLayerColor::initWithColor(ccc4(0,0,0,0)))
	{
		

		/*CCSprite* sprite1=CCSprite::create("HelloWorld.png");
		addChild(sprite1);
		sprite1->setPosition(ccp(s.width/2,s.height/2));*/

		//左右滑屏箭头改用菜单比较好。方便回调
		/*CCSprite* leftarrow=CCSprite::create("images/b2.png");
		CCSprite* rightarrow=CCSprite::create("images/f2.png");

		addChild(leftarrow);
		addChild(rightarrow);

		leftarrow->setPosition(ccp(20+leftarrow->getContentSize().width/2,s.height/2));
		rightarrow->setPosition(ccp(s.width-20-rightarrow->getContentSize().width/2,s.height/2));
		*/

		/*飞机精灵用plist实现
		CCSprite* play1=CCSprite::create("images/pea.png");
		CCSprite* play2=CCSprite::create("	");
		addChild(play1);
		addChild(play2);
		play1->setPosition(ccp(s.width/2-100,s.height/2));
		play2->setPosition(ccp(s.width/2+100,s.height/2));
		*/


		CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("Monster.plist","Monster.png");


		pHero1=CCSprite::createWithSpriteFrameName("Monster1.png");
		pHero1->setPosition(ccp(s.width/2,s.height/2));
		//pHero1->setScale(1.5f);
		pHero1->setRotation(180);
		this->addChild(pHero1);

		pHero6=CCSprite::createWithSpriteFrameName("Monster6.png");
		pHero6->setPosition(ccp(s.width+pHero6->getContentSize().width,s.height/2));
		//pHero6->setScale(1.5f);
		pHero6->setRotation(180);
		this->addChild(pHero6);

		CCMenuItemImage *pLeftItem = CCMenuItemImage::create("images/b2.png","images/b1.png",this,	menu_selector(MenuLayerPlayerSelect::MenuLeftSlideCallBack) );
		pLeftItem->setPosition(ccp(20+pLeftItem->getContentSize().width/2,s.height/2));

		CCMenuItemImage *pRightItem = CCMenuItemImage::create("images/f2.png","images/f1.png",this,	menu_selector(MenuLayerPlayerSelect::MenuRightSlideCallBack) );
		pRightItem->setPosition(ccp(s.width-20-pRightItem->getContentSize().width/2,s.height/2));
		
		CCLabelBMFont* label_start=CCLabelBMFont::create("Start","fonts/bitmapFontTest3.fnt");
		CCMenuItemLabel* item_start=CCMenuItemLabel::create(label_start,this,menu_selector(MenuLayerPlayerSelect::MenuStartGameCallBack));
		item_start->setPosition(s.width/2,pRightItem->getPositionY()-80);

		//CCMenuItemSprite* phero1_item=CCMenuItemSprite::create(pHero1,pHero1,this,menu_selector(MenuLayerPlayerSelect::MenuHeroSelectedCallBack));

		CCMenu* menu=CCMenu::create(pLeftItem,pRightItem,item_start,NULL);

	

		this->addChild(menu);
		menu->setPosition(CCPointZero);

		/*CCSprite* sp_return=CCSprite::create("images/r1.png");
		
		addChild(sp_return);
		
		sp_return->setPosition(ccp(s.width-sp_return->getContentSize().width/2-20,sp_return->getContentSize().height/2+20));*/
		//返回主界面菜单
		CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
		CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();

		CCMenuItemImage *item_home = CCMenuItemImage::create("images/r1.png","images/r2.png",	this,menu_selector(MenuLayerPlayerSelect::menuGoHomeCallback));

		item_home->setPosition(ccp(origin.x + visibleSize.width - item_home->getContentSize().width/2 ,	origin.y + item_home->getContentSize().height/2));

		// create menu, it's an autorelease object
		CCMenu* pMenu = CCMenu::create(item_home, NULL);
		addChild(pMenu, 5);
		pMenu->setPosition(CCPointZero);
		

		this->setTouchEnabled(true);
		
		return true;
	}
	return false;

}
예제 #6
0
MainLayerStoreFrame::MainLayerStoreFrame(enumStore flag)
{
	mFlag = flag;
	mContentLayer = NULL;

	mBg = CCScale9Sprite::create("shangdian_bg.jpg");
	addChild(mBg);
	float h = mWinSize.height - BaseSprite::create("zhuangtailan_jinqian.png")->getContentSize().height
		- MainLayerBase::getCurrentMainBase()->getFooter()->getFooterSize().height;
	mBg->setContentSize(CCSize(mBg->getContentSize().width, h));
	mBg->setPosition(ccp(mWinSize.width/2,mBg->getContentSize().height/2));

	//创建按钮
	{
		CCMenuItemImage* shenbingItem = CCMenuItemImage::create(
			"shangdian_shenbin_dengdai.png",
			"shangdian_shenbin_anxia.png",
			"shangdian_shenbin_select.png",
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
// 		CCMenuItemImage* daojuItem = CCMenuItemImage::create(
// 			"shangdian_daoju_dengdai.png",
// 			"shangdian_daoju_anxia.png",
// 			"shangdian_daoju_select.png",
// 			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
		CCMenuItemImage* libaoItem = CCMenuItemImage::create(
			"shangdian_libao_dengdai.png",
			"shangdian_libao_anxia.png",
			"shangdian_libao_select.png", 
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));
		CCMenuItemImage* chongzhiItem = CCMenuItemImage::create(
			"shangdian_chongzhi_dengdai.png",
			"shangdian_chongzhi_anxia.png",
			"shangdian_chongzhi_select.png", 
			this,SEL_MenuHandler(&MainLayerStoreFrame::menuItemClicked));


		mMenu = CCMenu::create(shenbingItem, libaoItem, chongzhiItem, NULL);
//		mMenu->addChild(daojuItem);
		mBg->addChild(mMenu,1);
		mMenu->setPosition(CCPointZero);


		shenbingItem->setPosition(ccp(mBg->getContentSize().width/2-shenbingItem->getContentSize().width - 20, mBg->getContentSize().height-144));
		shenbingItem->setTag(TAG_ITEM_ShenBing);

//		daojuItem->setPosition(ccp(259,shenbingItem->getPositionY()));
//		daojuItem->setTag(TAG_ITEM_DAOJU);

		libaoItem->setPosition(ccp(mBg->getContentSize().width/2,shenbingItem->getPositionY()));
		libaoItem->setTag(TAG_ITEM_LiBao);

		chongzhiItem->setPosition(ccp(mBg->getContentSize().width/2+chongzhiItem->getContentSize().width + 20,shenbingItem->getPositionY()));
		chongzhiItem->setTag(TAG_ITEM_CHONGZHI);

	}

	//
	if(MarketManager::getManager()->itemCount() == 0)
	{
		//
		mMenu->setEnabled(false);

		//加载市场数据
		addObserver(SEL_CallFuncO(&MainLayerStoreFrame::getMarketInfoCallBack),MSG_getMarketInfoRsp);
		CmdHelper::getHelper()->cmdGetMarketInfo();
	}
	else
	{
		mFooterLayer = MainLayerBase::getCurrentMainBase();
		if (mFlag == store_ShenBing)
			menuItemClicked(mMenu->getChildByTag(TAG_ITEM_ShenBing));
		else if (mFlag == store_DaoJu)
			CCLOG("TAG_ITEM_DAOJU");
//			menuItemClicked(mMenu->getChildByTag(TAG_ITEM_DAOJU));
		else if (mFlag == store_LiBao)
			menuItemClicked(mMenu->getChildByTag(TAG_ITEM_LiBao));
		else if (mFlag == store_ChongZhi)
			menuItemClicked(mMenu->getChildByTag(TAG_ITEM_CHONGZHI));
	}
	
}
예제 #7
0
CCMenuItemImage * GafFeatures::addBtn(const char * text, float px, float py, SEL_MenuHandler handler, float k)
{
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	
	CCMenuItemImage *res = CCMenuItemImage::create(
														  "CloseNormal.png",
														  "CloseSelected.png",
														  this,
														  handler );
    res->setPosition( ccp(size.width * px, size.height * py) );
	res->setScale(k);
	
	CCLabelTTF* pLabel = CCLabelTTF::create(text, "Thonburi", 34);
	pLabel->setColor(ccc3(0, 0, 255));
	
	pLabel->setAnchorPoint(CCPoint(1, 0.5));
	pLabel->setScale(k);
    pLabel->setPosition( ccp(res->getPositionX() - res->getContentSize().width * k * 0.5, res->getPositionY()) );
    addChild(pLabel, 100000);
	return res;
}
예제 #8
0
void GameScene::showOverView()
{
    if (m_pOverLayer == NULL)
    {
        m_pOverLayer = LGLayerColor::create(ccc4(0, 0, 0, 0));
        m_pOverLayer->retain();
        m_pOverLayer->setTouchMode(kCCTouchesOneByOne);
        m_pOverLayer->setTouchEnabled(true);
        m_pOverLayer->setZOrder(3);

        CCSprite *pTitle = CCSprite::create("title_over.png");
        pTitle->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2, m_VisibleOrigin.y + m_VisibleSize.height * 0.76f));
        m_pOverLayer->addChild(pTitle);

        CCSprite *pBgScore = CCSprite::create("bg_score.png");
        //pBgScore->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2, m_VisibleOrigin.y + m_VisibleSize.height * 0.535f));
        pBgScore->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2, m_VisibleOrigin.y - pBgScore->getContentSize().height / 2));
        pBgScore->setTag(kTagOverScoreBoard);
        m_pOverLayer->addChild(pBgScore);

        float bgW = pBgScore->getContentSize().width, bgH = pBgScore->getContentSize().height;

        int record = CCUserDefault::sharedUserDefault()->getIntegerForKey("record", 0);
        if (record < m_CurrentScore)
        {
            record = m_CurrentScore;
            CCUserDefault::sharedUserDefault()->setIntegerForKey("record", record);
            NativeBridge::submitScore(record);

            CCSprite *indicatorNew = CCSprite::create("new.png");
            indicatorNew->setPosition(ccp(bgW * (0.5 - 0.2448980f), bgH * (0.5 - 0.08035714f)));
            pBgScore->addChild(indicatorNew);
        }

        CCLabelAtlas *current = CCLabelAtlas::create(CCString::createWithFormat("%d", m_CurrentScore)->getCString(), "fonts/font2.png", 36, 48, '0');
        current->setAnchorPoint(ccp(0.5, 0.5));
        current->setPosition(bgW / 2, bgH * 0.6394f);
        pBgScore->addChild(current);
        CCLabelAtlas *best = CCLabelAtlas::create(CCString::createWithFormat("%d", record)->getCString(), "fonts/font2.png", 36, 48, '0');
        best->setAnchorPoint(ccp(0.5, 0.5));
        best->setPosition(bgW / 2, bgH * (0.5 - 0.27679f));
        pBgScore->addChild(best);

        CCMenuItemImage *pRetry = LGMenuItemImage::create("retry.png", NULL, this, menu_selector(GameScene::retryCallback));
        CCMenuItemImage *pMenu = LGMenuItemImage::create("menu.png", NULL, this, menu_selector(GameScene::menuCallback));

        pRetry->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width * 0.73333333f, m_VisibleOrigin.y + m_VisibleSize.height * 0.285f));
        pMenu->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width * 0.26666667f, pRetry->getPositionY()));

        CCMenu *pCCMenu = CCMenu::create(pRetry, pMenu, NULL);
        pCCMenu->setTag(kTagOverMenu);
        pCCMenu->setAnchorPoint(CCPointZero);
        pCCMenu->setPosition(ccp(0, m_VisibleOrigin.y - (pRetry->getPositionY() - m_VisibleOrigin.y) * 2));
        m_pOverLayer->addChild(pCCMenu);
    }

    m_pOverLayer->getChildByTag(kTagOverScoreBoard)->runAction(CCMoveTo::create(0.5f, ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2, m_VisibleOrigin.y + m_VisibleSize.height * 0.535f)));
    m_pOverLayer->getChildByTag(kTagOverMenu)->runAction(CCMoveTo::create(1.0f, CCPointZero));

    if (m_pOverLayer && m_pOverLayer->getParent() == NULL)
    {
        getParent()->addChild(m_pOverLayer);
        CC_SAFE_RELEASE_NULL(m_CurrentLayer);
        m_CurrentLayer = m_pOverLayer;
        m_CurrentLayer->retain();
        onShowOverlay(true);
    }

    m_ScoreLabel->setVisible(false);
}
예제 #9
0
void GameScene::showPauseView()
{
    m_Paused = true;

    if (m_pPauseLayer == NULL)
    {
        m_pPauseLayer = LGLayerColor::create(ccc4(0, 0, 0, 0));
        m_pPauseLayer->retain();
        m_pPauseLayer->setTouchMode(kCCTouchesOneByOne);
        m_pPauseLayer->setTouchEnabled(true);
        m_pPauseLayer->setZOrder(3);

        CCSprite *pTitle = CCSprite::create("title_pause.png");
        pTitle->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width / 2 , m_VisibleOrigin.y + m_VisibleSize.height * 0.67375f));
        m_pPauseLayer->addChild(pTitle);

        CCMenuItemImage *pContinue = LGMenuItemImage::create("play.png", NULL, this, menu_selector(GameScene::continueCallback));
        CCMenuItemImage *pMenu = LGMenuItemImage::create("menu.png", NULL, this, menu_selector(GameScene::menuCallback));

        pContinue->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width * 0.26666667f, m_VisibleOrigin.y + m_VisibleSize.height * 0.41125));
        pMenu->setPosition(ccp(m_VisibleOrigin.x + m_VisibleSize.width * 0.73333333f, pContinue->getPositionY()));

        CCMenu *pCCMenu = CCMenu::create(pContinue, pMenu, NULL);
        pCCMenu->setAnchorPoint(CCPointZero);
        pCCMenu->setPosition(CCPointZero);
        m_pPauseLayer->addChild(pCCMenu);
    }

    if (m_pPauseLayer && m_pPauseLayer->getParent() == NULL)
    {
        getParent()->addChild(m_pPauseLayer);
        CC_SAFE_RELEASE_NULL(m_CurrentLayer);
        m_CurrentLayer = m_pPauseLayer;
        m_CurrentLayer->retain();
        onShowOverlay(true);
    }
}
예제 #10
0
bool MainMenuLayer::init()
{
	if (CCLayerColor::initWithColor(ccc4(255, 255, 255, 255)))	{
    // Create a "close" menu item with close icon, it's an auto release object.
    CCMenuItemImage *pStartGameItem = CCMenuItemImage::create(
        "button-newgame.png",
        "button-newgame-sel.png",
        this,
        menu_selector(MainMenuLayer::menuStartGameCallback));

    CCMenuItemImage *pExitItem = CCMenuItemImage::create(
        "button-exit.png",
        "button-exit-sel.png",
        this,
        menu_selector(MainMenuLayer::menuExitCallback));

    // Place the menu item bottom-right conner.
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();

    int v_space = 5;
    pExitItem->setPosition(ccp(origin.x + visibleSize.width/2,
        origin.y + visibleSize.height * 1 / 3));
    pStartGameItem->setPosition(ccp(pExitItem->getPositionX(),
        pExitItem->getPositionY() +
        pExitItem->getContentSize().height / 2 +
        pStartGameItem->getContentSize().height / 2 +
        v_space));

    // Create a menu with the "close" menu item, it's an auto release object.
    CCMenu* pMenu = CCMenu::create(pStartGameItem, pExitItem, NULL);
    pMenu->setPosition(CCPointZero);

    // Add the menu to HelloWorld layer as a child layer.
    this->addChild(pMenu, 1);

    // loading best score
    HelloWorld::max_points_result =
        CCUserDefault::sharedUserDefault()->getIntegerForKey(
            "max_points_result");

    // Max points label
    v_space = 10;
    std::stringstream strs;
    strs << HelloWorld::max_points_result;
    std::string temp_str = strs.str();
    char const* pchar = temp_str.c_str();
    max_points_label = CCLabelTTF::create(pchar,
        "Artial", 20);
    max_points_label->retain();
    max_points_label->setColor(ccc3(0, 255, 0));
    max_points_label->setPosition(
        ccp(pExitItem->getPositionX(),
            pStartGameItem->getPositionY() +
            pStartGameItem->getContentSize().height / 2 +
            max_points_label->getFontSize() / 2 + v_space));
    this->addChild(max_points_label);

    // Above max points label
    v_space = 3;
    CCLabelTTF* max_points_above_label = CCLabelTTF::create("Best Score",
        "Artial", 18);
    max_points_above_label->retain();
    max_points_above_label->setColor(ccc3(0, 0, 0));
    max_points_above_label->setPosition(
        ccp(pExitItem->getPositionX(),
            max_points_label->getPositionY() +
            max_points_label->getContentSize().height / 2 +
            max_points_above_label->getFontSize() / 2 + v_space));
    this->addChild(max_points_above_label);
	}
	else	{
		return false;
	}
}
예제 #11
0
bool MainScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }

    setKeypadEnabled(true);

    CCPoint visibleOrigin = CCDirector::sharedDirector()->getVisibleOrigin();
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint visibleCenter = visibleOrigin + visibleSize / 2;

    CCSprite *sprite = CCSprite::create("bg1.jpg");
    sprite->setPosition(visibleCenter);
    addChild(sprite);

    sprite = CCSprite::create("title.png");
    sprite->setAnchorPoint(ccp(0.5, 0));
    sprite->setPosition(ccp(visibleCenter.x, visibleCenter.y + 0.24125f * visibleSize.height));
    addChild(sprite);

    m_Sound = CCUserDefault::sharedUserDefault()->getBoolForKey("sound", true);
    CCUserDefault::sharedUserDefault()->setBoolForKey("sound", m_Sound);
    m_pSound = LGMenuItemImage::create("sound_off.png", "sound_on.png", this, menu_selector(MainScene::soundCallback));
    m_pSound->setScale(0.65f);
    m_pSound->setPosition(visibleOrigin.x + visibleSize.width * 0.9f, visibleOrigin.y + visibleSize.height * 0.94375f);
    if (m_Sound)
    {
        m_pSound->selected();
    }
    else
    {
        m_pSound->unselected();
    }

    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_DIE);
    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_HIT);
    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_POINT);
    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_SWOOSHING);
    CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect(SFX_WING);

    CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
    cache->addSpriteFramesWithFile("pigs.plist");

    CCSprite *pig = CCSprite::createWithSpriteFrameName("pig1");
    pig->setPosition(ccp(visibleCenter.x, visibleCenter.y + 0.06125f * visibleSize.height));
    addChild(pig);

    CCMenuItemImage *pPlay = LGMenuItemImage::create("play.png", NULL, this, menu_selector(MainScene::playCallback));
    pPlay->setPosition(ccp(visibleOrigin.x + 0.272917f * visibleSize.width, visibleOrigin.y + 0.305625f * visibleSize.height));
    //pPlay->setPosition(ccp(visibleCenter.x, visibleCenter.y - 0.12125f * visibleSize.height));

    CCMenuItemImage *pRank = LGMenuItemImage::create("rank.png", NULL, this, menu_selector(MainScene::rankCallback));
    pRank->setPosition(ccp(visibleOrigin.x + 0.727083f * visibleSize.width, pPlay->getPositionY()));

    CCMenuItemImage *pMore = LGMenuItemImage::create("more.png", NULL, this, menu_selector(MainScene::moreCallback));
    pMore->setPosition(ccp(visibleCenter.x, visibleCenter.y - 0.05125f * visibleSize.height));
    //pMore->setPosition(ccp(visibleCenter.x, visibleOrigin.y + 0.225625f * visibleSize.height));

    CCMenu *pMenu = CCMenu::create(m_pSound, pPlay, pRank, pMore, NULL);
    pMenu->setAnchorPoint(CCPointZero);
    pMenu->setPosition(CCPointZero);
    addChild(pMenu);

    return true;
}
예제 #12
0
void HelloWorld::selectPillar(CCObject* target)
{
	bool bTopBlock = true;
	float topBlockSize;
	float selectedBlockSize;
	// set all pillar colors to default
	for (int i=0 ; i<3 ; i++)
	{
		((CCMenuItemImage*)((this->getChildByTag(i))->getChildByTag(i)))->setOpacity(255);
	}

	// set selected pillar
	CCMenuItemImage* pillar = (CCMenuItemImage*)(target);
	selectedPillar = pillar->getTag();
	//pillar->setOpacity(140);
	//CCLog("selectedPillar is %i",selectedPillar);

	if (topBlock[selectedPillar] == 20)
	{
		topBlockSize = 0;
	}
	else
	{
		topBlockSize = ((CCMenuItemImage*)(this->getChildByTag(topBlock[selectedPillar])->getChildByTag(topBlock[selectedPillar])))->getScaleX();
	}
	selectedBlockSize = ((CCMenuItemImage*)(this->getChildByTag(selectedBlock)->getChildByTag(selectedBlock)))->getScaleX();

	// if selected block size is < top block on pillar OR no block on pillar OR no block above it, run move block fxn
	CCMenuItemImage* block = ((CCMenuItemImage*)(this->getChildByTag(selectedBlock)->getChildByTag(selectedBlock)));
	float aboveBlock = block->getPositionY() + bHeight;
	for (int x=3 ; x<10 ; x++)
	{
		if (((CCMenuItemImage*)(this->getChildByTag(x)->getChildByTag(x)))->boundingBox().containsPoint(ccp(block->getPositionX(),aboveBlock)) == true)
		{
			//CCLog("block exists above selected block");
			bTopBlock = false;
			break;
		}
	}

	//CCLog("topBlockSize is %f\nselectedBlockSize is %f",topBlockSize,selectedBlockSize);
	if ((numBlock[selectedPillar] == 0) || (selectedBlockSize < topBlockSize))
	{
		if (bTopBlock == true)
			moveBlock();
	}

	// winning condition - 7 blocks,top block is tag 9
	for (int y=1 ; y<3 ; y++)
	{
		if (numBlock[y] == 7)
		{
			if (topBlock[y] == 9)
			{
				CCSprite* winMsg = CCSprite::create("/winMsg.png");
				winMsg->setPosition(ccp(240,150));
				winMsg->setScale(float(.5));
				this->addChild(winMsg);

				CCMenu* restartM = CCMenu::create();
				CCMenuItemImage* restartB = CCMenuItemImage::create("/restartB.png","/restartB.png",this,menu_selector(HelloWorld::restartGame));
				(restartB->getSelectedImage())->setScale(.75);
				(restartB->getSelectedImage())->setPosition(ccp(restartB->getPositionX()+20,restartB->getPositionY()+20));
				restartB->setScale(float(.5));
				restartB->setPositionY(-50);
				restartM->addChild(restartB);
				this->addChild(restartM);
				
				break;
			}
		}
	}
}
bool ChuanqiduanzaoItem::initItem(BaseActor* info)
{
	bool bret = false;

	//初始化背景
	if (CCSprite::initWithFile("shangdian_chuanqi_bg.png"))
	{
		bret = true;
	}

	if (bret)
	{
		m_Profession_id = info->getCurrentProperty().profession;
		//顶部文字显示
		CCLabelTTF* pTopTip = CCLabelTTF::create(LFStrings::getValue("ShenBingDuanZao_ShuoMingTiShi").c_str(), fontStr_kaiti, 18);
		pTopTip->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height-70));
		pTopTip->setColor(fonColor_FaGuang);
		this->addChild(pTopTip);

		//头像
		CCSprite* pIcon = CCSprite::create(this->getIconFileNameByType(info->getActorType()).c_str());
		this->addChild(pIcon);
		pIcon->setPosition(ccp(this->getContentSize().width/2, 400));

		//美术字(英雄类型)
		CCSprite* pHeroType = CCSprite::create(this->getHeroTypeFileNameByType(info->getActorType()).c_str());
		this->addChild(pHeroType);
		pHeroType->setPosition(ccp(this->getContentSize().width/2, 
			pIcon->getPositionY()-pIcon->getContentSize().height/2-pHeroType->getContentSize().height+2));


		//套装名字
		string zhuangBeiStr = ChuanqiPool::getPool()->getChuanQiSuitName(info->getActorType());
		CCLabelTTF* pName = CCLabelTTF::create(zhuangBeiStr.c_str(), fontStr_kaiti, 20);
		pName->setPosition(ccp(this->getContentSize().width/2, 280));
		this->addChild(pName);

		CCMenu* pMenu = CCMenu::create();
		this->addChild(pMenu);
		pMenu->setPosition(CCPointZero);
		//锻造一次
		CCMenuItemImage *yici = CCMenuItemImage::create(
			"shangdian_shenbin_anniu_duanzaoyici.png",
			"shangdian_shenbin_anniu_duanzaoyici_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
		pMenu->addChild(yici, 0, Tag_MenuItem_Yici);
		yici->setPosition(ccp(this->getContentSize().width/2-yici->getContentSize().width/2, 185));
		yici->setUserData((void*)info->getActorType());

		//锻造十次
		CCMenuItemImage *shici = CCMenuItemImage::create(
			"shangdian_shenbin_anniu_duanzaoshici.png",
			"shangdian_shenbin_anniu_duanzaoshici_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_DuanZao));
		pMenu->addChild(shici, 0, Tag_MenuItem_Shici);
		shici->setPosition(ccp(this->getContentSize().width/2+yici->getContentSize().width/2, yici->getPositionY()));
		shici->setUserData((void*)info->getActorType());

		char buf[20];
		//锻造一次需要金币
		BaseSprite *goldIcon1 = BaseSprite::create("jinbi_tubiao.png");
		this->addChild(goldIcon1);
		goldIcon1->setScale(0.5f);
		goldIcon1->setPosition(ccp(yici->getPositionX()-goldIcon1->getContentSize().width/2, yici->getPositionY()+yici->getContentSize().height/2+goldIcon1->getContentSize().height/2));
		sprintf(buf, "%d", 400);
		CCLabelTTF *yiciLabel = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
		this->addChild(yiciLabel);
		yiciLabel->setPosition(ccp(goldIcon1->getPositionX()+goldIcon1->getContentSize().width/2*goldIcon1->getScaleX()+yiciLabel->getContentSize().width/2
			, goldIcon1->getPositionY()));
		//锻造十次需要金币
		BaseSprite *goldIcon10 = BaseSprite::create("jinbi_tubiao.png");
		this->addChild(goldIcon10);
		goldIcon10->setScale(0.5f);
		goldIcon10->setPosition(ccp(shici->getPositionX()-goldIcon10->getContentSize().width/2, shici->getPositionY()+shici->getContentSize().height/2+goldIcon10->getContentSize().height/2));
		sprintf(buf, "%d", 400*10);
		CCLabelTTF *yiciLabel0 = CCLabelTTF::create(buf, fontStr_BookAntiqua, 20);
		this->addChild(yiciLabel0);
		yiciLabel0->setPosition(ccp(goldIcon10->getPositionX()+goldIcon10->getContentSize().width/2*goldIcon10->getScaleX()+yiciLabel0->getContentSize().width/2
			, goldIcon10->getPositionY()));

		CCMenuItemImage* pXiaoguo = CCMenuItemImage::create(
			"shandian_anniu_taozhuangxiaoguo.png",
			"shandian_anniu_taozhuangxiaoguo_select.png",
			this, menu_selector(ChuanqiduanzaoItem::menuItemClicked_Xiaoguo)
			);
		pMenu->addChild(pXiaoguo);
		pXiaoguo->setPosition(ccp(this->getContentSize().width/2, pXiaoguo->getContentSize().height/2));
	}

	return bret;
}