Example #1
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);
}
Example #2
0
FailScene::FailScene(void)
{
	Vec2 points[] = {	Vec2(0, 0), 
						Vec2(0, 140),
						Vec2(400, 140),
						Vec2(400, 0) };
	DrawNode* draw = DrawNode::create();
	//±³¾°
	draw->drawPolygon(points, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
								0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));

	this->addChild(draw);
	draw->setAnchorPoint(Point(.5, .5));
	draw->setPositionX(ScreenUtil::getCenter().x - 200);
	draw->setPositionY(ScreenUtil::getCenter().y - 140);

	Vec2 points2[] = {	Vec2(0, 0), 
						Vec2(0, 150),
						Vec2(230, 150),
						Vec2(230, 0) };
	DrawNode* draw2 = DrawNode::create();
	//±³¾°
	draw2->drawPolygon(points2, 4, ColorUtil::getColor4F(0x00 , 0xAD , 0xFF, 0xFF),
								0, ColorUtil::getColor4F(0x00, 0xDA, 0xFF, 0xFF));

	this->addChild(draw2);
	draw2->setAnchorPoint(Point(.5, .5));
	draw2->setPositionX(ScreenUtil::getCenter().x - 115);
	draw2->setPositionY(ScreenUtil::getCenter().y + 40);

	LabelTTF* scoreTxt = LabelTTF::create("Score:", "Arial", 45);
	scoreTxt->setAnchorPoint(Point(0, .5));
	scoreTxt->setPosition(Point(draw2->getPositionX() + 10, 
								draw2->getPositionY() + 110));
	this->addChild(scoreTxt);

	LabelTTF* bestScoreTxt = LabelTTF::create("Best:", "Arial", 45);
	bestScoreTxt->setAnchorPoint(Point(0, .5));
	bestScoreTxt->setPosition(Point(scoreTxt->getPositionX(), 
									draw2->getPositionY() + 50));
	this->addChild(bestScoreTxt);

	LabelTTF* scoreValTxt = LabelTTF::create("0", "Arial", 45);
	scoreValTxt->setPositionX(scoreTxt->getPositionX() + scoreTxt->getContentSize().width + 25);
	scoreValTxt->setPositionY(scoreTxt->getPositionY());
	scoreValTxt->setTag(scoreValTxtTag);
	this->addChild(scoreValTxt);

	LabelTTF* bestScoreValTxt = LabelTTF::create("0", "Arial", 45);
	bestScoreValTxt->setPositionX(scoreValTxt->getPositionX());
	bestScoreValTxt->setPositionY(bestScoreTxt->getPositionY());
	bestScoreValTxt->setTag(bestScoreValTxtTag);
	this->addChild(bestScoreValTxt);

	LabelTTF* replayTxt = LabelTTF::create("Replay", "Arial", 45);
	MenuItemLabel* replayBtn = MenuItemLabel::create(replayTxt);
	replayBtn->setTag(replayBtnTag);

	LabelTTF* shareTxt = LabelTTF::create("Share", "Arial", 45);
	MenuItemLabel* shareBtn = MenuItemLabel::create(shareTxt);

	Menu* menu = Menu::create(replayBtn, shareBtn,  NULL);
	menu->setPositionX(ScreenUtil::getCenter().x);
	menu->setPositionY(ScreenUtil::getCenter().y - 70);
	menu->alignItemsHorizontallyWithPadding(50);
	menu->setTag(menuTag);
	this->addChild(menu);
}