Exemplo n.º 1
0
UI::UI( cocos2d::Layer *layer, int &gameState )
{
    this->gameState = &gameState;
    
    Size screenSize = Director::getInstance( )->getVisibleSize( );
    Vec2 origin = Director::getInstance( )->getVisibleOrigin( );

    MenuItemSprite *pauseItem = MenuItemSprite::create( Sprite::create( PAUSE_BUTTON ), Sprite::create( PAUSE_BUTTON_PRESSED ), Sprite::create( PAUSE_BUTTON_PRESSED ), CC_CALLBACK_1( UI::PauseGame, this ) );
    pauseItem->setPosition( Vec2( screenSize.width - ( pauseItem->getContentSize( ).width / 2 ) + origin.x, screenSize.height - ( pauseItem->getContentSize( ).height / 2 ) + origin.y ) );
    
    Menu *menuButtons = Menu::create( pauseItem, NULL );
    menuButtons->setPosition( Vec2::ZERO );
    layer->addChild( menuButtons );
    
    pausebackground = Sprite::create( PAUSE_BACKGROUND );
    pausebackground->setPosition( SonarCocosHelper::UI::GetScreenCenter( ) );
    pausebackground->setOpacity( 0 );
    layer->addChild( pausebackground );
    
    
    MenuItemImage *overlayPauseWindowItem = MenuItemImage::create( PAUSE_WINDOW, PAUSE_WINDOW, PAUSE_WINDOW, NULL );
    MenuItemSprite *resumeItem = MenuItemSprite::create( Sprite::create( RESUME_BUTTON ), Sprite::create( RESUME_BUTTON_PRESSED ), Sprite::create( RESUME_BUTTON ), CC_CALLBACK_1( UI::PauseGame, this ) );
    resumeItem->setPosition( Vec2( -overlayPauseWindowItem->getContentSize( ).width / 4, resumeItem->getPositionY( ) ) );
    MenuItemSprite *mainMenuItem = MenuItemSprite::create( Sprite::create( HOME_BUTTON ), Sprite::create( HOME_BUTTON_PRESSED ), Sprite::create( HOME_BUTTON_PRESSED ), CC_CALLBACK_1( UI::GoToMainMenu, this ) );
    mainMenuItem->setPosition( Vec2( overlayPauseWindowItem->getContentSize( ).width / 4, mainMenuItem->getPositionY( ) ) );
    
    pauseMenu = Menu::create( overlayPauseWindowItem, resumeItem, mainMenuItem, NULL );
    pauseMenu->setPosition( Vec2( SonarCocosHelper::UI::GetScreenCenter( ).x, SonarCocosHelper::UI::GetScreenCenter( ).y + screenSize.height ) );
    layer->addChild( pauseMenu );
}
Exemplo n.º 2
0
void GamePlay::gameHelp() {
	if (onSound)
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"sound/button.mp3");
	boardMenuPause->setVisible(false);

	boardMenuHelp = Sprite::create("board.png");
	boardMenuHelp->setPosition(
			Vec2(visibleSize.width / 2, visibleSize.height / 2));
	boardMenuHelp->setZOrder(30);
	this->addChild(boardMenuHelp);

	float haflHeight = boardMenuHelp->getContentSize().height / 2;
	float haflWidth = boardMenuHelp->getContentSize().width / 2;

	Sprite* text = Sprite::create("howtoplaytext.png");
	text->setPosition(Vec2(haflWidth + PADDING / 2, haflHeight));
	text->setZOrder(40);
	boardMenuHelp->addChild(text);

	MenuItemImage* closeBtn = MenuItemImage::create("menu_closeBtn.png",
			"menu_closeBtn.png", CC_CALLBACK_0(GamePlay::gameCloseMenu, this));
	auto menuClose = Menu::create(closeBtn, nullptr);
	menuClose->setZOrder(40);
	menuClose->setPosition(
			Vec2(haflWidth * 2 - closeBtn->getContentSize().width - PADDING,
					haflHeight * 2 - closeBtn->getContentSize().height
							- PADDING));
	boardMenuHelp->addChild(menuClose);
}
Exemplo n.º 3
0
void UI::ShowGameOver( cocos2d::Layer *layer )
{
    Size screenSize = Director::getInstance( )->getVisibleSize( );

    Sprite *background = Sprite::create( GAME_OVER_BACKGROUND );
    background->setPosition( SonarCocosHelper::UI::GetScreenCenter( ) );
    background->setOpacity( 0 );
    layer->addChild( background );
    background->runAction( Sequence::create( DelayTime::create( PIECE_FADE_IN_TIME * 2.5 ), FadeIn::create( GAME_OVER_BACKGROUND_FADE_IN_TIME ), NULL ) );
    
    MenuItemImage *overlayWindowItem = MenuItemImage::create( GAME_OVER_WINDOW, GAME_OVER_WINDOW, GAME_OVER_WINDOW, NULL );
    MenuItemSprite *retryItem = MenuItemSprite::create( Sprite::create( RETRY_BUTTON ), Sprite::create( RETRY_BUTTON_PRESSED ), Sprite::create( RETRY_BUTTON ), CC_CALLBACK_1( UI::Retry, this ) );
    retryItem->setPosition( Vec2( overlayWindowItem->getContentSize( ).width / 4, retryItem->getPositionY( ) ) );
    MenuItemSprite *mainMenuItem = MenuItemSprite::create( Sprite::create( HOME_BUTTON ), Sprite::create( HOME_BUTTON_PRESSED ), Sprite::create( HOME_BUTTON_PRESSED ), CC_CALLBACK_1( UI::GoToMainMenu, this ) );
    mainMenuItem->setPosition( Vec2( -overlayWindowItem->getContentSize( ).width / 4, mainMenuItem->getPositionY( ) ) );
    
    
    Menu *menu = Menu::create( overlayWindowItem, retryItem, mainMenuItem, NULL );
    menu->setPosition( Vec2( SonarCocosHelper::UI::GetScreenCenter( ).x, SonarCocosHelper::UI::GetScreenCenter( ).y + screenSize.height ) );
    layer->addChild( menu );
    

    EaseBounceOut *menuActionEasing = EaseBounceOut::create( MoveTo::create( MENU_MOVE_BOUNCE_DURATION, SonarCocosHelper::UI::GetScreenCenter( ) ) );
    Sequence *menuShowSeq = Sequence::create( DelayTime::create( PIECE_FADE_IN_TIME * 2.5 ), menuActionEasing, NULL );
    menu->runAction( menuShowSeq );
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
      
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////
	// 2. add a menu item with "X" image, which is clicked to quit the program
	//    you may modify it.

	// add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *pCloseItem = MenuItemImage::create(
		"CloseNormal.png",
		"CloseSelected.png",
        CC_CALLBACK_1(HelloWorld::menuCloseCallback,this)
                      );

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

	// create menu, it's an autorelease object
	Menu* pMenu = Menu::create(pCloseItem, NULL);
	pMenu->setPosition(Point(0,0));
	this->addChild(pMenu, 1);

    return true;
}
// on "init" you need to initialize your instance
bool ItemLayer::init() {
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() ) {
        return false;
    }

    this->setKeypadEnabled(true);

    Size size = CCDirector::getInstance()->getWinSize();

    auto title = LabelTTF::create("Item", "Arial", 24);
    title->setPosition( Point(size.width / 2, size.height - 50));
    this->addChild(title, 1);

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *pCloseItem = MenuItemImage::create(
                                        "b1.png",
                                        "b2.png",
                                        CC_CALLBACK_1(ItemLayer::menuBackCallback,this) );
    pCloseItem->setPosition( Point(pCloseItem->getContentSize().width / 2 , 50) );

    // create menu, it's an autorelease object
    auto pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition( Point::ZERO );
    this->addChild(pMenu, 1);
    
    // add next menu
    MenuItemImage *pNextItem = MenuItemImage::create(
                                                          "f1.png",
                                                          "f2.png",
                                                          CC_CALLBACK_1(ItemLayer::menuNextCallback,this) );
    pNextItem->setPosition( Point(size.width - pNextItem->getContentSize().width / 2, 50) );
    
    // create menu, it's an autorelease object
    Menu* pNextMenu = Menu::create(pNextItem, NULL);
    pNextMenu->setPosition(Point::ZERO);
    this->addChild(pNextMenu, 1);

    float step = 35;
    float yPos = 0;
    for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
        char buf[64];
		sprintf(buf, s_EventMenuItem[i].id.c_str(), itemid, counts[i]);
        
        auto label = LabelTTF::create(buf, "Arial", 30);
        MenuItemLabel* pMenuItem = MenuItemLabel::create(label,  CC_CALLBACK_1(ItemLayer::eventMenuCallback,this));
        pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);
        yPos = size.height - step*i - 100;
        pMenuItem->setPosition( Point(size.width / 2, yPos));
    }

    return true;
}
Exemplo n.º 6
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *pCloseItem = MenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        this,
                                        menu_selector(HelloWorld::menuCloseCallback));
    
	pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                origin.y + pCloseItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition(PointZero);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    LabelTTF* pLabel = LabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    Sprite* pSprite = Sprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(ccp(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);
    
    return true;
}
Exemplo n.º 7
0
bool GameOver::init()
{
    bool ret = false;
    do {
        CC_BREAK_IF(!Layer::init());
        Sprite *backGround1 = Sprite::createWithSpriteFrameName("gameover.png");
        backGround1->setAnchorPoint(Point(0, 0));
        backGround1->setPosition(Point(0, 0));
        this->addChild(backGround1, -1, 0);

        Size size = Director::getInstance()->getWinSize();

        MenuItemImage *item = MenuItemImage::create("ui/shoot_background/btn_finish.png"
            , "ui/shoot_background/btn_finish.png", menuCallback);
        Menu *menu = Menu::create(item, NULL);
        addChild(menu);
        item->setAnchorPoint(Point(0, 0));
        menu->setPosition(Point(0, 0));
        item->setPosition(Point(size.width - item->getContentSize().width, 0));

        m_scoreLabel = LabelTTF::create("0", "Arial", 28);
        m_scoreLabel->setFontSize(40);
        addChild(m_scoreLabel);

        m_scoreLabel->setPosition(Point(size.width * 0.5, size.height * 0.5));
        ret = true;
    } while (0);
    return ret;
}
Exemplo n.º 8
0
bool Skill::init(SkillType skillType)
{
	string img = IMG_PLAYER;
	ccMenuCallback callback;
	switch (skillType)
	{
	case SkillType::SKILL_THUNDER:
		{
			img += "skill2.png";
			callback = CC_CALLBACK_0(Skill::thunder, this);
			break;
		}
	case SkillType::SKILL_REINFORCE:
		{
			img += "skill1.png";
			callback = CC_CALLBACK_0(Skill::thunder, this);
			break;
		}
	default:
		return false;
	}
    MenuItemImage* skill = MenuItemImage::create(img, img, callback);
	_skillSize = skill->getContentSize();
    Menu *menu = Menu::create(skill, NULL);
    menu->setAnchorPoint(Vec2(0, 0));
    menu->setPosition(Vec2(0, 0));
    this->addChild(menu);
	return true;
}
Exemplo n.º 9
0
//TODO 屏蔽事件穿透
void BattleScene::createBottomBar()
{
	LayerColor *bottom = LayerColor::create(Color4B(0, 0, 100, 100));
	bottom->setContentSize(Size(WINSIZE.width, 120));
	bottom->setPosition(Point(0, 0));
	addChild(bottom);

	int totalCount = 11;
	int index = 0;
	Vector<MenuItem *> items;
	auto soldierInCamp = BattleData::getInstance()->getAttackSoldierInCamp();
	map<int, vector<DSoldier *>>::iterator it;
	for(it=soldierInCamp.begin(); it!=soldierInCamp.end(); it++)
	{
		MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this));
		item->setTag(it->first);
		items.pushBack(item);
		index++;

		//head
		Size size = item->getContentSize();
		char img[20];
		sprintf(img, "ui/%d.png", it->first / 100);
		auto head = Sprite::create(img);
		head->setAnchorPoint(Point(0.5, 0.5));
		head->setPosition(size.width/2, size.height/2);
		item->addChild(head);
		
		char text[20];
		sprintf(text, "X %d", it->second.size());
		TTFConfig config("fonts/tahoma.ttf",16);
		auto count = Label::createWithTTF(config, text, TextHAlignment::LEFT);
		count->setPosition(size.width/2, size.height - count->getContentSize().height);
		item->addChild(count);
		//初始化为第一个兵种
		if (m_selectedSoldierType <= 0)
		{
			m_selectedSoldierType = it->first;
		}
		
	}
	for (int i = index; i < totalCount; i++)
	{
		MenuItemImage *item = MenuItemImage::create("ui/616.0.png", "ui/617.0.png", "ui/618.0.png", CC_CALLBACK_1(BattleScene::selectArmy, this));
		item->setEnabled(false);
		items.pushBack(item);
	}

	Size bottomSize = bottom->getContentSize();
	Sprite *spItem = Sprite::create("ui/618.0.png");
	Size itemSize = spItem->getContentSize();
	float padding = (bottomSize.width - itemSize.width * totalCount) / (totalCount + 1);

	UIRadioButton *radio = UIRadioButton::createWithArray(items);
	radio->alignItemsHorizontallyWithPadding(padding);
	radio->setPosition(Point(bottomSize.width / 2, bottomSize.height / 2));
	radio->setSelectedIndex(0);
	bottom->addChild(radio);
}
Exemplo n.º 10
0
void TBaseObject::onEnter()
{
    LayerColor::onEnter();
    
    MenuItemImage* item = MenuItemImage::create("GameRes//interface//playnormal.png","GameRes//interface//playselected.png",CC_CALLBACK_1(TBaseObject::ProxyLeftDown, this));
    Menu* menu = Menu::create(item,NULL,NULL,NULL);
    menu->setPosition(Point::ZERO);
    item->setPosition(Point(TVisibleRect::center().x, TVisibleRect::center().y + item->getContentSize().height / 2));
    this->addChild(menu,9999);
}
Exemplo n.º 11
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    
    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.
    
    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *pCloseItem = MenuItemImage::create(
                                                      "CloseNormal.png",
                                                      "CloseSelected.png",
                                                      CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
    pCloseItem->setPosition(Point(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 ,
                                  origin.y + pCloseItem->getContentSize().height/2));
    
    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition(Point::ZERO);
    this->addChild(pMenu, 1);
    
    Point beginPos = Point(origin.x + visibleSize.width / 2, origin.y + visibleSize.height - 50);
    float step = 60.0f;
    int nCaseCount = sizeof(g_testCases) / sizeof(std::string);
    for (int i = 0; i < nCaseCount; ++i) {
        std::string caseName = g_testCases[i];
        MenuItemFont *pItem = MenuItemFont::create(caseName.c_str(), CC_CALLBACK_1(HelloWorld::menuCallback, this));
        pItem->setTag(i);
        pItem->setPosition(Point(beginPos.x, beginPos.y - i * step));
        pMenu->addChild(pItem);
    }
    return true;
}
Exemplo n.º 12
0
// on "init" you need to initialize your instance
bool TestIAP::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

    MyPurchase::getInstance()->loadIAPPlugin();

    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    auto pEGLView = Director::getInstance()->getOpenGLView();
    Point posBR = Point(pEGLView->getVisibleOrigin().x + pEGLView->getVisibleSize().width, pEGLView->getVisibleOrigin().y);
    Point posTL = Point(pEGLView->getVisibleOrigin().x, pEGLView->getVisibleOrigin().y + pEGLView->getVisibleSize().height);

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemFont *pBackItem = MenuItemFont::create("Back", CC_CALLBACK_1(TestIAP::menuBackCallback, this));
    Size backSize = pBackItem->getContentSize();
    pBackItem->setPosition(posBR + Point(- backSize.width / 2, backSize.height / 2));

    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(pBackItem, NULL);
    pMenu->setPosition( Point::ZERO );
    this->addChild(pMenu, 1);

    Point posStep = Point(220, -150);
    Point beginPos = posTL + (posStep * 0.5f);
    int line = 0;
    int row = 0;
    for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
    	MenuItemImage* pMenuItem = MenuItemImage::create(s_EventMenuItem[i].id.c_str(), s_EventMenuItem[i].id.c_str(),
    			CC_CALLBACK_1(TestIAP::eventMenuCallback, this));
        pMenu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);

        Point pos = beginPos + Point(posStep.x * row, posStep.y * line);
        Size itemSize = pMenuItem->getContentSize();
        if ((pos.x + itemSize.width / 2) > posBR.x)
		{
			line += 1;
			row = 0;
			pos = beginPos + Point(posStep.x * row, posStep.y * line);
		}
        row += 1;
        pMenuItem->setPosition(pos);
    }

    return true;
}
Exemplo n.º 13
0
// Layerの初期処理
// ここにゲームの一番最初の処理を記載
bool PlayScene::init(){
    //////////////////////////////
    // 1. super init first
    if (!Layer::init()) {
        return false;
    }
    
    
    // 画像描画用に画面のサイズと座標開始位置を取得
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // レイヤーの背景色を設定
    // DeprecationWarnning:
    // ccc4()は非推奨のため、Color4B()を使用(中身はinline関数で、ccc4を実行していた)
    LayerColor *color = LayerColor::create(Color4B(0.0f,200.0f,0.0f,255.0f));
    this->addChild(color);

    
    // プレイ画像の追加(スプライト生成)
    auto sprite = Sprite::create("PlayBackground.png");
    // 画面中央への配置
    sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    // レイヤーへスプライト追加
    this->addChild(sprite, 0);

    
    // メニューボタン作成(ゲーム一時停止ボタン)
    MenuItemImage* menuButton = MenuItemImage::create(
                                                      "menubutton.png",
                                                      "menubutton.png",
                                                      [this](Ref *pSender){
                                                          auto menuLayer = MenuLayer::create(this);
                                                          this->addChild(menuLayer,100,70000);
                                                      });
    
    
    menuButton->setPosition(Vec2(origin.x + ( visibleSize.width / 3) * 2 + ( menuButton->getContentSize().width / 2 ) ,
                                      origin.y + visibleSize.height / 5));
    
    // メニュー作成
    Menu* menu = Menu::create(menuButton, NULL);
    menu->setPosition(0,0);
    this->addChild(menu);
    
    // ゲーム処理(ゲームそのものの実行)
    gameLogic();
    
    
    return true;
}
Exemplo n.º 14
0
void GameScreen::CreateMenu()
{
	Size visibleSize = Director::getInstance()->getVisibleSize();
	Point origin = Director::getInstance()->getVisibleOrigin();

	MenuItemImage* pauseButton = MenuItemImage::create(Buttons::PAUSE_BUTTON,
											Buttons::PAUSE_BUTTON_CLICK,
											CC_CALLBACK_1(GameScreen::GoToPauseScene, this));

	pauseButton->setPositionX(pauseButton->getContentSize().width / 2 + origin.x);
	pauseButton->setPositionY(pauseButton->getContentSize().height + origin.y);

	Menu* menu = Menu::create(pauseButton, NULL);
	menu->setPosition(Point::ZERO);

	menu->setName("menu");
	this->addChild(menu);
}
Exemplo n.º 15
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    setKeypadEnabled(true);
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

    MenuItemImage *pCloseItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
    pCloseItem->setPosition(Vec2(origin.x + visibleSize.width - pCloseItem->getContentSize().width / 2,origin.y + visibleSize.height - pCloseItem->getContentSize().height / 2));
    Menu *pMenu = Menu::create(pCloseItem, NULL);
    pMenu->setPosition(Vec2::ZERO);
    this->addChild(pMenu, 1);
    
    //创建游戏标题界面
    MenuItemImage *pItemPlay = MenuItemImage::create("playgameNormal.png", "playgameClose.png", CC_CALLBACK_1(HelloWorld::menuPlayGameCallback, this));
    pItemPlay->setPosition(Vec2(visibleSize.width / 2, visibleSize.height * 1.0f / 4.0f));
    pItemPlay->setScaleX(visibleSize.width / 600);
    pItemPlay->setScaleY(visibleSize.height / 400);
    
    Menu *pMenuPlay = Menu::create(pItemPlay, NULL);
    pMenuPlay->setPosition(Vec2::ZERO);
    this->addChild(pMenuPlay, 1);
    
    Sprite *pSprite = Sprite::create("ScenceStart.png");
    pSprite->setPosition(Point(visibleSize.width / 2, visibleSize.height / 2));
    Size size = pSprite->getContentSize();
    
    pSprite->setScaleX(visibleSize.width / size.width);
    pSprite->setScaleY(visibleSize.height / size.height);
    this->addChild(pSprite, 0);
    
    return true;
}
Exemplo n.º 16
0
bool GameLayer::init(){
	if(!Layer::init()){
		return false;
	}
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    
    

	matrix = nullptr;
	this->scheduleUpdate();
	EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create();
	listener->onTouchBegan = CC_CALLBACK_2(GameLayer::onTouchBegan,this);
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
    
	
	Sprite* background = Sprite::create("bg_mainscene.jpg");
	background->setPosition(visibleSize.width/2,visibleSize.height/2);
	this->addChild(background,-1);
	menu = TopMenu::create();
	this->addChild(menu);
	linkNum = Label::create("","Arial",40);
	linkNum->setPosition(visibleSize.width/2,visibleSize.height-250);
	linkNum->setVisible(false);
	this->addChild(linkNum,1);

	this->floatLevelWord();
//    auto labelws=Label::createWithSystemFont("by王术", "Courier", 30);
//    labelws->setPosition(Vec2(60,800-40));
//    addChild(labelws);
//    labelws->runAction(RepeatForever::create(RotateBy::create(6, Vec3(0, 180, 0))));
    //加入暂停
    MenuItemImage* btn = MenuItemImage::create("Item_pause.png","Item_pause.png",CC_CALLBACK_0(GameLayer::MyResume, this));
    Menu* menu2 = Menu::create(btn,NULL);
    menu2->alignItemsVertically();
    menu2->setPosition(visibleSize.width-btn->getContentSize().width,visibleSize.height-btn->getContentSize().height);
    this->addChild(menu2,10);
    
	return true;
}
Exemplo n.º 17
0
bool PopupLayer::addButton(const char *normalImage, const char *selectedImage, const char *title, int tag)
{
	//Size winSize = CCDirector::getInstance()->getWinSize();
    Point pCenter = ccp(winSize.width / 2, winSize.height / 2);
    
    // 创建图片菜单按钮
    MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, this, menu_selector(PopupLayer::buttonCallback));
    menuImage->setTag(tag);
    menuImage->setPosition(pCenter);
    
    // 添加文字说明并设置位置

	Size imenu = menuImage->getContentSize();
    LabelTTF* ttf = LabelTTF::create(title, "", 20);
    ttf->setColor(ccc3(0, 0, 0));
    ttf->setPosition(ccp(imenu.width / 2, imenu.height / 2));
    menuImage->addChild(ttf);


    getMenuButton()->addChild(menuImage);
    return true;
}
void RequestAPIScene::buildScene()
{
    // Call super build scene.
    BaseScene::buildScene();
    BaseScene::addTipBoard("Do you know that you can use EziSocial to send gifts, invites and challenges to user's Facebook friends? Also you can process these requests on receiver's device");

    
    SpriteBatchNode* batchNode = SpriteBatchNode::create(PNG_FILE(kRESOURCE_REQUEST));
    this->addChild(batchNode);
    
    SpriteFrameCache::getInstance()->addSpriteFramesWithFile(PLIST_FILE(kRESOURCE_REQUEST));
    
    buildHeader(-1, "Request APIs", "Send gifts, invites and much more with Facebook");
    
    // Build the tiles.
    MenuItemImage* menuItem = NULL;
    
    menuItem = this->buildAndPlaceTile("btn_send_gifts_nrl",      "btn_send_gifts_prd",         0, 0);
    menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::sendGifts, this));
    
    menuItem = this->buildAndPlaceTile("btn_challenge_nrl",      "btn_challenge_prd",           2, 0);
    menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::challengeFriends, this));
    
    menuItem = this->buildAndPlaceTile("btn_invite_friends_nrl",      "btn_invite_friends_prd", 1, 1);
    menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::inviteFriends, this));
    
    menuItem = this->buildAndPlaceTile("btn_new_requests_nrl",      "btn_new_requests_prd",     0, 2);
    menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::refreshIncomingRequests, this));
    
    Size menuSize = menuItem->getContentSize();
    _pendingRequestLabel = LabelTTF::create("0", "Arial", AppDelegate::SCREEN_SCALE_FACTOR * 20);
    menuItem->addChild(_pendingRequestLabel, 5);
    _pendingRequestLabel->cocos2d::CCNode::setPosition(menuSize.width * 0.2, menuSize.height * 0.2);
    
    menuItem = this->buildAndPlaceTile("btn_view_open_nrl",      "btn_view_open_prd",           2, 2);
    menuItem->setCallback(CC_CALLBACK_1(RequestAPIScene::viewOpenRequestItems, this));
}
Exemplo n.º 19
0
bool PopLayer::addButton(const char* normalImage, const char* selectedImage, const char* title, int tag /*= 0*/)
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 pCenter(visibleSize.width / 2, visibleSize.height / 2);
    
    // 创建图片菜单按钮
    MenuItemImage* menuImage = MenuItemImage::create(normalImage, selectedImage, CC_CALLBACK_1(PopLayer::buttonCallback, this));
    menuImage->setTag(tag);
    //menuImage->setPosition(pCenter);
    
    // 添加文字说明并设置位置
    if(title != NULL)
    {
        Size imenu = menuImage->getContentSize();
        LabelTTF* ttf = LabelTTF::create(title, "", 20);
        ttf->setColor(Color3B(0, 0, 0));
        ttf->setPosition(Vec2(imenu.width / 2, imenu.height / 2));
        menuImage->addChild(ttf);
    }
    
    
    getMenuButton()->addChild(menuImage);
    return true;
}
Exemplo n.º 20
0
void GamePlay::gameOver(float dt) {
//	Director::getInstance()->pause();
	gameState = End;
//invisible frame ready
	if (frameReady != NULL) {
		for (int i = 0; i < SUM_NUM; i++)
			frameReady[i]->setVisible(false);
	}

	boardWin = Sprite::create("board.png");
	boardWin->setPosition(Vec2(-visibleSize.width / 4, visibleSize.height / 2));
	boardWin->setZOrder(30);
	this->addChild(boardWin);
	float haflHeight = boardWin->getContentSize().height / 2;
	float haflWidth = boardWin->getContentSize().width / 2;

	auto jumpto = JumpTo::create(0.5,
			Vec2(visibleSize.width / 2, visibleSize.height / 2 - 3 * PADDING),
			PADDING * 3, 4);
	boardWin->runAction(jumpto);

	updatehightestRecord();

	if (onSound)
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"sound/music_win.ogg");
//congratulation
	Sprite* congratulation = Sprite::create("congratulation.png");
	congratulation->setPosition(
			Vec2(haflWidth,
					haflHeight * 2 - 3 * PADDING
							- congratulation->getContentSize().height));
	congratulation->setZOrder(40);
	boardWin->addChild(congratulation);

//highscore
	Sprite* newhighscore = Sprite::create("newhighscore.png");
	newhighscore->setPosition(
			Vec2(haflWidth,
					congratulation->getPositionY()
							- congratulation->getContentSize().height / 2
							- newhighscore->getContentSize().height / 2
							- 2 * PADDING));
	newhighscore->setZOrder(40);
	boardWin->addChild(newhighscore);

	//TODO
	if (timeplay > 0)
		NativeUtils::submitScore(
				getLeaderBoard(GamePlay::instance()->getLevel()),
				timeplay * 1000);
	if (timeplay > highScore) {
		newhighscore->setVisible(false);
	} else {
		newhighscore->setVisible(true);
	}

//gameover text
	Sprite* gameovertext = Sprite::create("gameovertext.png");
	gameovertext->setPosition(
			Vec2(4 * PADDING + gameovertext->getContentSize().width / 2,
					newhighscore->getPositionY()
							- newhighscore->getContentSize().height / 2
							- gameovertext->getContentSize().height / 2
							- 2 * PADDING));
	gameovertext->setZOrder(40);
	boardWin->addChild(gameovertext);

	float sizewidth = gameovertext->getContentSize().width;
	float sizeheight = gameovertext->getContentSize().height;
//show score
	LabelTTF *currentscore = LabelTTF::create("00:00", "fonts/hlvgchac.ttf",
			40);
	currentscore->setZOrder(50);
	currentscore->setColor(Color3B(Color3B::BLUE));
	showTextTime(currentscore, timeplay);
	currentscore->setPositionX(
			sizewidth + PADDING + currentscore->getContentSize().width / 2);
	currentscore->setPositionY(sizeheight / 2);
	gameovertext->addChild(currentscore);

	LabelTTF *highscore = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 40);
	highscore->setZOrder(50);
	highscore->setColor(Color3B(Color3B::BLUE));
	showTextTime(highscore, highScore);
	highscore->setPositionX(
			sizewidth + PADDING + currentscore->getContentSize().width / 2);
	highscore->setPositionY(highscore->getContentSize().height / 2);
	gameovertext->addChild(highscore);

	std::string miniModeSprite = getLevelString(
			GamePlay::instance()->getLevel());
	Sprite* miniMode = Sprite::create("mini" + miniModeSprite + ".png");
	miniMode->setPosition(
			Vec2(
					haflWidth * 2 - miniMode->getContentSize().width / 2
							- 3 * PADDING,
					gameovertext->getPositionY()
							+ miniMode->getContentSize().height / 2
							+ 2 * PADDING));
	boardWin->addChild(miniMode);
//button ok
	MenuItemImage* okBtn = MenuItemImage::create("okBtn.png", "okBtn.png",
			CC_CALLBACK_0(GamePlay::gameCloseWinBoard, this));
	auto okMenu = Menu::create(okBtn, nullptr);
	okMenu->setZOrder(40);
	okMenu->setPosition(
			Vec2(haflWidth / 2 + PADDING,
					gameovertext->getPositionY()
							- gameovertext->getContentSize().height / 2
							- okBtn->getContentSize().height / 2
							- 2 * PADDING));
	boardWin->addChild(okMenu);
//button share
	MenuItemImage* shareBtn = MenuItemImage::create("shareBtn.png",
			"shareBtn.png", CC_CALLBACK_0(GamePlay::gameShareWin, this));
	auto shareMenu = Menu::create(shareBtn, nullptr);
	shareMenu->setZOrder(40);
	shareMenu->setPosition(
			Vec2(haflWidth * 3 / 2 - PADDING, okMenu->getPositionY()));
	boardWin->addChild(shareMenu);
}
Exemplo n.º 21
0
void GamePlay::gameSetting() {
	if (onSound)
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(
				"sound/button.mp3");
	boardMenuPause->setVisible(false);

	boardMenuSetting = Sprite::create("board.png");
	boardMenuSetting->setPosition(
			Vec2(visibleSize.width / 2, visibleSize.height / 2));
	boardMenuSetting->setZOrder(30);
	this->addChild(boardMenuSetting);
	float haflHeight = boardMenuSetting->getContentSize().height / 2;
	float haflWidth = boardMenuSetting->getContentSize().width / 2;
	MenuItemImage* closeBtn = MenuItemImage::create("menu_closeBtn.png",
			"menu_closeBtn.png",
			CC_CALLBACK_0(GamePlay::gameCloseMenuSetting, this));
	auto menuClose = Menu::create(closeBtn, nullptr);
	menuClose->setZOrder(40);
	menuClose->setPosition(
			Vec2(haflWidth * 2 - closeBtn->getContentSize().width - PADDING,
					haflHeight * 2 - closeBtn->getContentSize().height
							- PADDING));
	boardMenuSetting->addChild(menuClose);

	Sprite* sound = Sprite::create("sound.png");
	sound->setPosition(
			Vec2(4 * PADDING + sound->getContentSize().width / 2,
					menuClose->getPositionY()
							- closeBtn->getContentSize().height - 2 * PADDING));
	sound->setZOrder(40);
	boardMenuSetting->addChild(sound);
	//button on/of sound
	MenuItemImage* onSoundBtn = MenuItemImage::create("onbutton.png",
			"onbutton.png", CC_CALLBACK_0(GamePlay::gameOnSound, this));
	auto menuOnSound = Menu::create(onSoundBtn, nullptr);
	menuOnSound->setZOrder(40);
	menuOnSound->setPosition(
			Vec2(haflWidth / 2 + PADDING,
					sound->getPositionY() - 2 * PADDING
							- onSoundBtn->getContentSize().height));
	boardMenuSetting->addChild(menuOnSound);

	MenuItemImage* offSoundBtn = MenuItemImage::create("offbutton.png",
			"offbutton.png", CC_CALLBACK_0(GamePlay::gameOffSound, this));
	auto menuOffSound = Menu::create(offSoundBtn, nullptr);
	menuOffSound->setZOrder(40);
	menuOffSound->setPosition(
			Vec2(haflWidth * 3 / 2 - PADDING, menuOnSound->getPositionY()));
	boardMenuSetting->addChild(menuOffSound);
	//stick sound
	stickSound = Sprite::create("stick.png");
	stickSound->setZOrder(50);
	stickSound->setTag(TAG_STICK_SOUND);
	stickSound->setPositionY(menuOnSound->getPositionY());
	boardMenuSetting->addChild(stickSound);
	this->posOnX = menuOnSound->getPositionX()
			- onSoundBtn->getContentSize().width / 4 - PADDING / 2;
	this->posOffX = menuOffSound->getPositionX()
			- offSoundBtn->getContentSize().width / 4 - PADDING / 2;
	if (onSound == true) {
		stickSound->setPositionX(this->posOnX);
	} else {
		stickSound->setPositionX(this->posOffX);
	}

	Sprite* music = Sprite::create("music.png");
	music->setZOrder(40);
	music->setPosition(
			Vec2(sound->getPositionX(),
					sound->getPositionY()
							- 3 * music->getContentSize().height));
	boardMenuSetting->addChild(music);

	//button on/of music
	MenuItemImage* onMusicBtn = MenuItemImage::create("onbutton.png",
			"onbutton.png", CC_CALLBACK_0(GamePlay::gameOnMusic, this));
	auto menuOnMusic = Menu::create(onMusicBtn, nullptr);
	menuOnMusic->setZOrder(40);
	menuOnMusic->setPosition(
			Vec2(menuOnSound->getPositionX(),
					music->getPositionY() - 2 * PADDING
							- onMusicBtn->getContentSize().height));
	boardMenuSetting->addChild(menuOnMusic);

	MenuItemImage* offMusicBtn = MenuItemImage::create("offbutton.png",
			"offbutton.png", CC_CALLBACK_0(GamePlay::gameOffMusic, this));
	auto menuOffMusic = Menu::create(offMusicBtn, nullptr);
	menuOffMusic->setZOrder(40);
	menuOffMusic->setPosition(
			Vec2(haflWidth * 3 / 2 - PADDING, menuOnMusic->getPositionY()));
	boardMenuSetting->addChild(menuOffMusic);

	//stick sound
	stickMusic = Sprite::create("stick.png");
	stickMusic->setZOrder(50);
	stickMusic->setTag(TAG_STICK_MUSIC);
	stickMusic->setPositionY(menuOnMusic->getPositionY());
	boardMenuSetting->addChild(stickMusic);
	if (onMusic == true) {
		stickMusic->setPositionX(this->posOnX);
	} else {
		stickMusic->setPositionX(this->posOffX);
	}
	//volumn setting
	/*cocos2d::extension::ControlSlider* slider =
	 cocos2d::extension::ControlSlider::create("sliderTrack2.png",
	 "sliderProgress2.png", "sliderThumb.png");
	 slider->setPosition(200, 200);
	 slider->setMinimumValue(0);
	 slider->setMaximumValue(100);
	 slider->setValue(50);
	 slider->addTargetWithActionForControlEvents(this, cccontrol_selector(IntroView::valueChangedCallback), cocos2d::extension::Control::EventType::VALUE_CHANGED);
	 addChild(slider);
	 void IntroView::valueChangedCallback(Ref* sender, cocos2d::extension::Control::EventType evnt)
	 {
	 float value = static_cast<cocos2d::extension::ControlSlider*>(sender)->getValue();
	 CCLOG(std::to_string(value).c_str());
	 }*/
}
Exemplo n.º 22
0
bool GamePlay::init() {
	if (!Layer::init()) {
		return false;
	}

	gameState = Ready;
	visibleSize = Director::getInstance()->getVisibleSize();
	getSoundMusic();

	//load game AI
	//init array number and computation
	int ARRAY_NUMBER[9] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	arrNum = gameAI->randomNumber(ARRAY_NUMBER, SUM_NUM);
	for (int i = 0; i < SUM_NUM; i++) {
		arrNUM[i] = arrNum[i];
	}
	char s[SUM_COM] = "";
	//TODO change level
//	arrCOM = gameAI->randomComputation(s, SUM_COM,
//			GamePlay::instance()->getLevel() >= 2 ? 2 : 3);
	arrCOM = gameAI->randomComputation(s, SUM_COM, 2);
	for (int i = 0; i < SUM_COM; i++) {
		arrCOMPUTATE[i] = arrCOM[i];
	}
	for (int i = 0; i < SUM_COM / 2; i++) {
		tempResult[i] = INIT_FRAME;
	}

	int arr[GamePlay::instance()->getLevel()];
	int* arrayLevel = gameAI->randomLessNumber(arr,
			GamePlay::instance()->getLevel());

	//load background
	auto bg = Sprite::create("background.png");
	bg->setAnchorPoint(Vec2(0, 0));
	bg->setPosition(Vec2(0, 0));
	this->addChild(bg, -1);
	float rX = visibleSize.width / bg->getContentSize().width;
	float rY = visibleSize.height / bg->getContentSize().height;
	bg->setScaleX(rX);
	bg->setScaleY(rY);

	//show logo game
	Sprite *logoGame = Sprite::create("smalllogo.png");
	logoGame->setAnchorPoint(Vec2(0.0, 1.0));
	logoGame->setPosition(Vec2(PADDING, visibleSize.height - PADDING));
	logoGame->setTag(TAG_LOGO);
	logoGame->setScale(0.6f);
	this->addChild(logoGame);

	//load frame ready
	float baseY = logoGame->getPositionY()
			- logoGame->getBoundingBox().size.height - PADDING;
	float baseX = PADDING / 2;
	for (int i = 0; i < SUM_NUM; i++) {
		frameReady[i] = Sprite::create("frame.png");
		float width = frameReady[i]->getContentSize().width;
		float height = frameReady[i]->getContentSize().height;
		frameReady[i]->setTag(TAG_START_READY_POINT + i);
		frameReady[i]->setPositionX(baseX + 5.0 / 8.0 * i * width + width / 2);
		if (i % 2 == 0) {
			frameReady[i]->setPositionY(baseY - height / 2);
		} else {
			frameReady[i]->setPositionY(baseY - height);
		}
		this->addChild(frameReady[i]);
	}

	//create frame play
	float paddingY = 0;
	float paddingX = 0;
	for (int i = 0; i < SUM_NUM; i++) {
		float baseX = PADDING;
		framePlay[i] = TouchSprite::create("frame.png");
		framePlay[i]->setTag(TAG_FRAME_PLAY + i);
		paddingX = (visibleSize.width - PADDING * 4
				- framePlay[i]->getContentSize().width) / 3.0;
		framePlay[i]->setPositionX(
				PADDING + framePlay[i]->getContentSize().width / 2
						+ paddingX * (i % 3));

		float baseY = frameReady[0]->getPositionY();
		if (i % 3 == 0)
			paddingY = paddingX * ((int) i / 3 + 1);
		framePlay[i]->setPositionY(baseY - paddingY);
		framePlay[i]->score = 0;
		framePlay[i]->isFixed = false;
		for (int j = 0; j < GamePlay::instance()->getLevel(); j++) {
			if (arrNum[i] == arrayLevel[j]) {
				framePlay[i]->score = arrNum[i];
				//TODO
				framePlay[i]->isFixed = true;
				framePlay[i]->setDisplayFrame(
						SpriteFrame::create(
								"frame" + std::to_string(arrNum[i]) + ".png",
								framePlay[i]->getTextureRect()));
			}
		}
//		CCLog("frameplay[%d] = %d", i, framePlay[i]->score);
		this->addChild(framePlay[i]);
	}

	//load number button
	//TODO
	std::string name = "number";
	MoveTo* actionBy;
	int k = 0;
	for (int i = 0; i < SUM_NUM; i++) {
		numberBtn[i] = TouchSprite::create(
				name + std::to_string(i + 1) + ".png");
		numberBtn[i]->setTag(TAG_NUMBER + i);
		numberBtn[i]->setPositionY(visibleSize.height + 3 * PADDING);
		numberBtn[i]->setPositionX(frameReady[i]->getPositionX());
		numberBtn[i]->setZOrder(10);
		numberBtn[i]->isHidden = false;
		this->addChild(numberBtn[i]);
		actionBy = MoveTo::create(0.4, frameReady[i]->getPosition());
		auto easeAction = EaseBounceInOut::create(actionBy);

		for (int j = 0; j < GamePlay::instance()->getLevel(); j++) {
			if ((i + 1) == arrayLevel[j]) {
				numberBtn[i]->isHidden = true;
				numberBtn[i]->setVisible(false);
			}
		}

		if (numberBtn[i]->isHidden == false) {
			auto delay = DelayTime::create(0.2 * (k + 1));
			auto sequence = Sequence::create(delay, easeAction, nullptr);
			numberBtn[i]->runAction(sequence);
			k++;
		}
	}

	if (frameReady != NULL) {
		for (int i = 0; i < SUM_NUM; i++)
			frameReady[i]->setVisible(false);
	}

	//create result frame and equal character
	Sprite* frameEqual[SUM_COM / 2];
	Sprite* characterEqual[SUM_COM / 2];
	for (int i = 0; i < SUM_COM / 2; i++) {
		characterEqual[i] = Sprite::create("icon_equal.png");
		frameEqual[i] = Sprite::createWithTexture(frameReady[i]->getTexture());
		frameEqual[i]->setTag(TAG_FRAME_EQUAL + i);
		if (i % 2 == 0) {
			//frame equal
			frameEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY()
							+ paddingX * (2 - (int) i / 2));
			frameEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX() + paddingX);
			//character equal
			characterEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY()
							+ paddingX * ((int) i / 2));
			characterEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX() + paddingX / 2);
		} else {
			//frame equal
			frameEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY() - paddingX);
			frameEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX()
							- paddingX * (2 - (int) i / 2));
			//character equal
			characterEqual[i]->setPositionY(
					framePlay[SUM_NUM - 1]->getPositionY() - paddingX / 2);
			characterEqual[i]->setPositionX(
					framePlay[SUM_NUM - 1]->getPositionX()
							- paddingX * (2 - (int) i / 2));
		}
		this->addChild(frameEqual[i]);
		this->addChild(characterEqual[i]);
	}

	//position of character computation
	Sprite* plusSprite = Sprite::create("icon_plus.png");
	Sprite* minusSrite = Sprite::create("icon_minus.png");
	Sprite* mutiplySprite = Sprite::create("icon_multiply.png");
	Sprite* divideSprite = Sprite::create("icon_divide.png");

	for (int i = 0; i < SUM_COM; i++) {
		if (arrCOM[i] == '+')
			comBtn[i] = Sprite::createWithTexture(plusSprite->getTexture());
		else if (arrCOM[i] == '-')
			comBtn[i] = Sprite::createWithTexture(minusSrite->getTexture());
		else if (arrCOM[i] == '*')
			comBtn[i] = Sprite::createWithTexture(mutiplySprite->getTexture());
		else if (arrCOM[i] == '/')
			comBtn[i] = Sprite::createWithTexture(divideSprite->getTexture());
		this->addChild(comBtn[i]);
	}
	setPosCharacterBtn(comBtn, framePlay, paddingX);

	//calculate result
	result[0] = gameAI->calculate(arrNum[0], arrNum[1], arrNum[2], arrCOM[0],
			arrCOM[1]);
	result[1] = gameAI->calculate(arrNum[0], arrNum[3], arrNum[6], arrCOM[2],
			arrCOM[7]);
	result[2] = gameAI->calculate(arrNum[3], arrNum[4], arrNum[5], arrCOM[5],
			arrCOM[6]);
	result[3] = gameAI->calculate(arrNum[1], arrNum[4], arrNum[7], arrCOM[3],
			arrCOM[8]);
	result[4] = gameAI->calculate(arrNum[6], arrNum[7], arrNum[8], arrCOM[10],
			arrCOM[11]);
	result[5] = gameAI->calculate(arrNum[2], arrNum[5], arrNum[8], arrCOM[4],
			arrCOM[9]);
	gameAI->printArray(result, SUM_COM / 2);

	//set result to frameEqual
	for (int i = 0; i < SUM_COM / 2; i++) {
		resultLabel[i] = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 48);
		resultLabel[i]->setColor(Color3B(Color3B::RED));
		resultLabel[i]->setString(std::to_string(result[i]));
		resultLabel[i]->setPosition(frameEqual[i]->getPosition());
		this->addChild(resultLabel[i]);
	}

	//button pause
	Sprite* pauseGame = Sprite::create("pauseBtn.png");
	Sprite* pauseGame_press = Sprite::create("pauseBtn_press.png");
	MenuItemSprite* pauseBtn = MenuItemSprite::create(pauseGame,
			pauseGame_press, NULL, CC_CALLBACK_0(GamePlay::gamePause, this));
	Menu *menuPause = Menu::create(pauseBtn, nullptr);
	menuPause->setPosition(
			Vec2(
					visibleSize.width - PADDING
							- pauseBtn->getContentSize().width / 2,
					visibleSize.height - PADDING
							- pauseBtn->getContentSize().height / 2));
	menuPause->setTag(TAG_PAUSE_BTN);
	this->addChild(menuPause);

	//time in pause button
	LabelTTF *currenttime = LabelTTF::create("00:00", "fonts/hlvgchac.ttf", 40);
	Point timePoint = menuPause->getPosition();
	currenttime->setPosition(
			Vec2(timePoint.x - PADDING * 2, timePoint.y + 7.0 / 4.0 * PADDING));
	currenttime->setZOrder(10);
	currenttime->setColor(Color3B(Color3B::RED));
	currenttime->setTag(TAG_LABEL_COUNT_TIME);
	this->addChild(currenttime);

	std::string miniModeSprite = getLevelString(
			GamePlay::instance()->getLevel());
	Sprite* miniMode = Sprite::create("mini" + miniModeSprite + ".png");
	miniMode->setScale(0.5);
	miniMode->setPosition(
			Vec2(currenttime->getPositionX(),
					currenttime->getPositionY()
							- currenttime->getContentSize().height
							- PADDING / 2));
	this->addChild(miniMode);

	//board menu pause
	boardMenuPause = Sprite::create("board.png");
	boardMenuPause->setPosition(
			Vec2(visibleSize.width / 2,
					visibleSize.height
							+ boardMenuPause->getContentSize().height / 2
							+ PADDING));
	boardMenuPause->setZOrder(30);
	this->addChild(boardMenuPause);

	//button help of menu
	Sprite* helpbtn = Sprite::create("help1.png");
	Sprite* helpbtn_press = Sprite::create("help2.png");
	MenuItemSprite* helpBtn = MenuItemSprite::create(helpbtn, helpbtn_press,
	NULL, CC_CALLBACK_0(GamePlay::gameHelp, this));
	Menu *menuHelp = Menu::create(helpBtn, nullptr);
	menuHelp->setPosition(
			Vec2(boardMenuPause->getContentSize().width / 2,
					boardMenuPause->getContentSize().height
							- helpbtn->getContentSize().height));
	boardMenuPause->addChild(menuHelp);

	//button setting of menu
	Sprite* setbtn = Sprite::create("settings1.png");
	Sprite* setbtn_press = Sprite::create("settings2.png");
	MenuItemSprite* setBtn = MenuItemSprite::create(setbtn, setbtn_press, NULL,
			CC_CALLBACK_0(GamePlay::gameSetting, this));
	Menu *menuSetting = Menu::create(setBtn, nullptr);
	menuSetting->setPosition(
			Vec2(boardMenuPause->getContentSize().width / 2,
					menuHelp->getPositionY() - setbtn->getContentSize().height
							- PADDING));
	menuSetting->setTag(TAG_SETTING);
	boardMenuPause->addChild(menuSetting);

	//button quit of menu
	Sprite* quitbtn = Sprite::create("quit1.png");
	Sprite* quitbtn_press = Sprite::create("quit2.png");
	MenuItemSprite* quitBtn = MenuItemSprite::create(quitbtn, quitbtn_press,
	NULL, CC_CALLBACK_0(GamePlay::gameQuit, this));
	Menu *menuQuit = Menu::create(quitBtn, nullptr);
	menuQuit->setPosition(
			Vec2(menuSetting->getPositionX(),
					menuSetting->getPositionY()
							- quitbtn->getContentSize().height - PADDING));
	menuQuit->setTag(TAG_QUIT);
	boardMenuPause->addChild(menuQuit);

	//button replay, resume, share
	MenuItemImage* resumeBtn = MenuItemImage::create("menu_resume.png",
			"menu_resume.png", CC_CALLBACK_0(GamePlay::gameResume, this));
	auto menuResume = Menu::create(resumeBtn, nullptr);
	menuResume->setPosition(
			Vec2(menuSetting->getPositionX(),
					menuQuit->getPositionY()
							- resumeBtn->getContentSize().height - PADDING));
	boardMenuPause->addChild(menuResume);

	MenuItemImage* replayBtn = MenuItemImage::create("menu_replay.png",
			"menu_replay.png", CC_CALLBACK_0(GamePlay::gameReplay, this));
	auto menuReplay = Menu::create(replayBtn, nullptr);
	menuReplay->setPosition(
			Vec2(
					menuResume->getPositionX()
							- resumeBtn->getContentSize().width - PADDING,
					menuResume->getPositionY()));
	boardMenuPause->addChild(menuReplay);

	MenuItemImage* shareBtn = MenuItemImage::create("menu_share.png",
			"menu_share.png",
			CC_CALLBACK_0(GamePlay::gameShareCloseMenuPause, this));
	auto menuShare = Menu::create(shareBtn, nullptr);
	menuShare->setPosition(
			Vec2(
					menuResume->getPositionX()
							+ resumeBtn->getContentSize().width + PADDING,
					menuResume->getPositionY()));
	boardMenuPause->addChild(menuShare);

	auto event_listener = EventListenerTouchOneByOne::create();
	auto dispatcher = Director::getInstance()->getEventDispatcher();
	event_listener->setSwallowTouches(true);
	event_listener->onTouchBegan = CC_CALLBACK_2(GamePlay::onTouchBegan, this);
	event_listener->onTouchMoved = CC_CALLBACK_2(GamePlay::onTouchMoved, this);
	event_listener->onTouchEnded = CC_CALLBACK_2(GamePlay::onTouchEnded, this);
	dispatcher->addEventListenerWithSceneGraphPriority(event_listener, this);
	this->setKeypadEnabled(true);
	this->scheduleUpdate();
//	this->schedule(schedule_selector(GamePlay::update), 1.0f);
	gameState = Playing;
	return true;
}
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();
    
    /////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.
    
    // add a "close" icon to exit the progress. it's an autorelease object
    auto closeItem = MenuItemImage::create(
                                           "CloseNormal.png",
                                           "CloseSelected.png",
                                           CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
    
    closeItem->setPosition( Point(closeItem->getContentSize().width / 2 , 50) );

    
    // create menu, it's an autorelease object
    auto menu = Menu::create(closeItem, NULL);
    menu->setPosition(Point::ZERO);
    this->addChild(menu, 1);
    
    /////////////////////////////
    // 3. add your codes below...
    
    // add a label shows "Hello World"
    // create and initialize a label
    
    auto label = LabelTTF::create("Hello World", "Arial", 24);
    
    // position the label on the center of the screen
    label->setPosition(Point(origin.x + visibleSize.width/2,
                             origin.y + visibleSize.height - label->getContentSize().height));
    
    // add the label as a child to this layer
    this->addChild(label, 1);
    
    // add "HelloWorld" splash screen"
    auto sprite = Sprite::create("HelloWorld.png");
    
    // position the sprite on the center of the screen
    sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));
    
    // add the sprite as a child to this layer
    this->addChild(sprite, 0);
    
    float step = 35;
    float yPos = 0;
    for (int i = 0; i < sizeof(s_EventMenuItem)/sizeof(s_EventMenuItem[0]); i++) {
        char buf[64];
        sprintf(buf, s_EventMenuItem[i].id.c_str(), ++_indexes[i]);
        
        auto label = LabelTTF::create(buf, "Arial", 24);
        MenuItemLabel* pMenuItem = MenuItemLabel::create(label, CC_CALLBACK_1(HelloWorld::menuEventCallback, this));
        menu->addChild(pMenuItem, 0, s_EventMenuItem[i].tag);
        yPos = visibleSize.height - step*i - 100;
        pMenuItem->setPosition( Point(visibleSize.width / 2, yPos));
    }
    
    // add next menu
    MenuItemImage *pNextItem = MenuItemImage::create("f1.png","f1.png",CC_CALLBACK_1(HelloWorld::menuNextCallback,this));
    pNextItem->setPosition( Point(visibleSize.width - pNextItem->getContentSize().width / 2, 50) );
    
    // create menu, it's an autorelease object
    Menu* pNextMenu = Menu::create(pNextItem, NULL);
    pNextMenu->setPosition( Point::ZERO );
    this->addChild(pNextMenu, 1);

    
    return true;

}
Exemplo n.º 24
0
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

	/////////////////////////////
    // 2. add a menu item with "X" image, which is clicked to quit the program
    //    you may modify it.

    // add a "close" icon to exit the progress. it's an autorelease object
    MenuItemImage *closeItem = MenuItemImage::create(
                                        "CloseNormal.png",
                                        "CloseSelected.png",
                                        CC_CALLBACK_1(HelloWorld::menuCloseCallback,this));
    
	closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
                                origin.y + closeItem->getContentSize().height/2));

    // create menu, it's an autorelease object
    Menu* pMenu = Menu::create(closeItem, NULL);
    pMenu->setPosition(Point::ZERO);
    this->addChild(pMenu, 1);

    /////////////////////////////
    // 3. add your codes below...

    // add a label shows "Hello World"
    // create and initialize a label
    
    LabelTTF* pLabel = LabelTTF::create("Hello World", "Arial", TITLE_FONT_SIZE);
    
    // position the label on the center of the screen
    pLabel->setPosition(Point(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));

    // add the label as a child to this layer
    this->addChild(pLabel, 1);

    // add "HelloWorld" splash screen"
    Sprite* pSprite = Sprite::create("HelloWorld.png");

    // position the sprite on the center of the screen
    pSprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

    // add the sprite as a child to this layer
    this->addChild(pSprite, 0);

	// initialize flash
    tinyswf::SWF::initialize(CCFlashLoadAsset, 256*1024); // 256kB buffer for libtess2
	tinyswf::Renderer::setInstance(new CCFlashRenderer);
	tinyswf::FontHandler::setInstance(new CCFlashFontHandler);
    CCFlash* pFlash = CCFlash::create("test.swf");
	pFlash->scheduleUpdate();
	this->addChild(pFlash,1);

	pFlash->getSWF()->get<tinyswf::Text>("_text")->setString(
		"<p>test<font color='#ff0000'>1234</font>hello world</p><p>font <font color='#00ffff'>color</font> test</p>");

#ifdef USE_HTTP
	CCHttpRequest* request = new CCHttpRequest();
	request->setUrl("https://localhost/codeigniter/user/login");
	request->setRequestType(CCHttpRequest::kHttpPost);
	request->setResponseCallback(this, httpresponse_selector(HelloWorld::onHttpRequestCompleted));
	request->setTag("POST login");

	std::string uuid;
	getUUID(uuid);
	std::string post = "uuid="+uuid;
	request->setRequestData(post.c_str(), post.length()); 

	CCHttpClient::getInstance()->send(request);
	request->release();
#endif
    return true;
}
bool ManagerToUserSettingsLayer::init(IOnGoalChangedForUser *delegate, const std::string &userId, int goal) {
    if(!Layer::init()) {
        return false;
    }

    _goalChangedDelegate = delegate;
    _userId = userId;
    _userGoal = goal;

    Size visibleSize = Director::getInstance()->getVisibleSize();

    // back
    {
        _back = Sprite::create("back.png");
        _back->setPosition({static_cast<float>(visibleSize.width / 2.0), static_cast<float>(visibleSize.height / 2.0)});

        Size backSize = _back->getContentSize();

        _back->setScale(visibleSize.width / backSize.width, visibleSize.height / backSize.height);

        this->addChild(_back, zBack);
    }

    {
        // parent blocker
        MenuItemImage *btn = MenuItemImage::create("blank.png", "blank.png", [](Ref *) {});
        btn->setScale(visibleSize.width / btn->getContentSize().width, visibleSize.height / btn->getContentSize().height);
        btn->setOpacity(0);

        Menu *blockMenu = Menu::create(btn, nullptr);
        blockMenu->setPosition({visibleSize.width * 0.5f, visibleSize.height * 0.5f});

        this->addChild(blockMenu);
    }

    {
        // heading
        _mntHeading = Sprite::create("mnt_settings_heading.png");
        _mntHeading->setAnchorPoint({0.5f, 1.0f});
        _mntHeading->setPosition({visibleSize.width * 0.5f, visibleSize.height});

        this->addChild(_mntHeading);

        // back button
        _btnBack = MenuItemImage::create("btn_back.png", "btn_back_on.png", CC_CALLBACK_0(ManagerToUserSettingsLayer::onBtnBackPressed, this));
        _btnBack->setAnchorPoint({0, 1});
        _btnBack->setPosition({0, visibleSize.height});

        Menu *backMenu = Menu::create(_btnBack, nullptr);
        backMenu->setPosition({0, 0});

        this->addChild(backMenu);
    }

    {
        // save button
        _btnSave = MenuItemImage::create("btn_settings_save.png", "btn_settings_save_on.png", CC_CALLBACK_0(ManagerToUserSettingsLayer::onBtnSavePressed, this));
        _btnSave->setAnchorPoint({0.5f, 0});
        _btnSave->setPosition({visibleSize.width * 0.5f, 0});

        Menu *saveMenu = Menu::create(_btnSave, nullptr);
        saveMenu->setPosition({0, 0});

        this->addChild(saveMenu);
    }

    {
        // a slider
        _sliderGroupNode = Node::create();
        _sliderGroupNode->setPosition({visibleSize.width * 0.5f, visibleSize.height * 0.5f + _btnSave->getContentSize().height * 0.5f});

        this->addChild(_sliderGroupNode);

        _sliderCalories = ControlSlider::create("mnt_settings_calories_slider.png", "settings_calories_slider.png", "settings_calories_slider_thumb.png");
        _sliderCalories->addTargetWithActionForControlEvents(this, cccontrol_selector(ManagerToUserSettingsLayer::onSliderCaloriesChanged),
                Control::EventType::VALUE_CHANGED);
        _sliderCalories->setMaximumAllowedValue(1);
        _sliderCalories->setMinimumAllowedValue(0.1);

        _sliderGroupNode->addChild(_sliderCalories);
    }

    {
        // captions
        _labelSliderCaption = Label::createWithTTF("Daily goal", "helvetica.ttf", 26);
        _labelSliderCaption->setColor({53, 172, 225});
        _labelSliderCaption->setAnchorPoint({0, 0.0});
        _labelSliderCaption->setPosition({-_sliderCalories->getContentSize().width * 0.5f, _labelSliderCaption->getContentSize().height});

        _sliderGroupNode->addChild(_labelSliderCaption);
    }

    {
        _labelCaloriesToConsumeCaption = Label::createWithTTF("10000", "helvetica.ttf", 25);
        _labelCaloriesToConsumeCaption->setColor({93, 93, 93});
        _labelCaloriesToConsumeCaption->setOpacity(0.7f * 255);
        _labelCaloriesToConsumeCaption->setAnchorPoint({0.5, 1});
        _labelCaloriesToConsumeCaption->setPosition({0, -_labelCaloriesToConsumeCaption->getContentSize().height});

        _sliderGroupNode->addChild(_labelCaloriesToConsumeCaption);

        _sliderCalories->setValue(1.0f * _userGoal / kMaxKCaloriesPerDay);
    }

    return true;
}