Пример #1
0
void PlayerBoard::playBloodAnimation(const char * text, ccColor3B color) {
    CCLabelBMFont* animationFont = CCLabelBMFont::create(text , "bmfont_hp.fnt");
    animationFont->setColor(color);

    this->addChild(animationFont, 1, ANIMATION_FONT_TAG);
    animationFont->runAction(CCSequence::create(CCMoveBy::create(1,ccp(0, 100)),::CCCallFunc::create(this, callfunc_selector(PlayerBoard::bloodAnimationCallback)), NULL));
}
Пример #2
0
void CommonButton::setFontColor(const ccColor3B& color) {
	CCLabelBMFont *  bmFont = dynamic_cast<CCLabelBMFont * >(m_label);
	if (bmFont) {
		bmFont->setColor(color);
	} else {
		CCLabelTTF *  ttf = dynamic_cast<CCLabelTTF * >(m_label);
		if (ttf) {
			ttf->setColor(color);
		}
	}
}
Пример #3
0
AtlasBitmapColor::AtlasBitmapColor()
{
	CCSize s = CCDirector::sharedDirector()->getWinSize();
	
	CCLabelBMFont* label = NULL;
	label = CCLabelBMFont::labelWithString("Blue", "fonts/bitmapFontTest5.fnt");
	label->setColor( ccBLUE );
	addChild(label);
	label->setPosition( ccp(s.width/2, s.height/4) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );

	label = CCLabelBMFont::labelWithString("Red", "fonts/bitmapFontTest5.fnt");
	addChild(label);
	label->setPosition( ccp(s.width/2, 2*s.height/4) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
	label->setColor( ccRED );

	label = CCLabelBMFont::labelWithString("G", "fonts/bitmapFontTest5.fnt");
	addChild(label);
	label->setPosition( ccp(s.width/2, 3*s.height/4) );
	label->setAnchorPoint( ccp(0.5f, 0.5f) );
	label->setColor( ccGREEN );
	label->setString("Green");
}
Пример #4
0
PointsManager::PointsManager()
{
	points = 0; // players start with 0 points
	points2 = 0;
	// setup label
	pointsLabel = CCLabelBMFont::create("0","Assets/badab.fnt");
	pointsLabel->setPositionX(760.0f);
	pointsLabel->setPositionY(30.0f);
	pointsLabel->setColor(ccc3(0,0,0));
	this->addChild(pointsLabel);

	// create label that write "points" on the screen
	CCLabelBMFont* pointsLabelWord = CCLabelBMFont::create("Points:","Assets/badab.fnt");
	pointsLabelWord->setColor(ccc3(0,0,0));
	pointsLabelWord->setPositionY(30.0f);
	pointsLabelWord->setPositionX(680.0f);
	this->addChild(pointsLabelWord);
}
Пример #5
0
void PointsManager::AnihilationHappened(int numberOfBlocks, cocos2d::CCPoint spot)
{
	// number of points that will be added depends upon the number of blocks that are being anihilated
	int addpoints = 0;
	// in case it's a power up
	if (numberOfBlocks == 1) {addpoints = 2;}
	// normal anihilation
	else if (numberOfBlocks == 3){addpoints = 10;}
	// 4-block anihilation
	else if (numberOfBlocks == 4){addpoints = 30;}
	// bigger anihiltion
	else if (numberOfBlocks == 5){addpoints = 60;}
	
	points += addpoints;
	// update number of points
	pointsToDisplay.initWithFormat("%i",points);
	pointsLabel->setCString(pointsToDisplay.getCString());


	// create a flying number on the screen
	CCString flyingNumberString;
	flyingNumberString.initWithFormat("%i",addpoints);
	CCLabelBMFont* flyingNumber = CCLabelBMFont::create(flyingNumberString.getCString(),"Assets/badab.fnt");
	flyingNumber->setColor(ccc3(0,0,0));
	flyingNumber->setPosition(spot);
	//put some nice actions on the number
	CCAction* sequence = CCSequence::create(CCDelayTime::actionWithDuration(1.0),
											  CCFadeOut::actionWithDuration(1.0f),
											  CCCallFuncO::actionWithTarget(this,callfuncO_selector(PointsManager::DeleteTextCallback),flyingNumber),
											  NULL);
	// add to node
	flyingNumber->runAction(sequence);
	flyingNumber->runAction(CCMoveBy::actionWithDuration(2.0f,ccp(0.0f,120.0f)));
	this->addChild(flyingNumber);

	if (isConnected)
	{
		// send update points to other player
		RakNet::BitStream BsOut;
		BsOut.Write((RakNet::MessageID)ID_GAME_NEW_POINTS);
		BsOut.Write((const char*)&points,sizeof(int));
		player2->Send(&BsOut,HIGH_PRIORITY,RELIABLE_ORDERED,0,player2Adress,false);
	}
}
Пример #6
0
bool GameOverLayer::init()
{
    bool bRet = false;
    do
    {
        CC_BREAK_IF(!CCLayer::init());
        
		CCSize winSize=CCDirector::sharedDirector()->getWinSize();
        
        // add gameover_background
	    CCSprite* background=CCSprite::create(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("gameover.png"));
		background->setPosition(ccp(winSize.width/2,winSize.height/2));
		this->addChild(background);
        
        // add BackMenu
		CCSprite* normalBackToGame=CCSprite::create(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));
		CCSprite* pressedBackToGame=CCSprite::create(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));
		CCMenuItemImage* pBackItem=CCMenuItemImage::create();
        pBackItem->initWithNormalSprite(normalBackToGame,pressedBackToGame,NULL,this,menu_selector(GameOverLayer::menuBackCallback));
		pBackItem->setPosition(ccp(winSize.width-normalBackToGame->getContentSize().width/2-10,normalBackToGame->getContentSize().height/2+10));
		CCMenu *menuBack=CCMenu::create(pBackItem,NULL);
		menuBack->setPosition(CCPointZero);
		this->addChild(menuBack);
        
        // show score
        CCString *strScore = CCString::createWithFormat("%d", score);
        CCLabelBMFont * finalScore = CCLabelBMFont::create(strScore->m_sString.c_str(), "font.fnt");
        finalScore->setColor(ccc3(143, 146, 147));
        finalScore->setPosition(ccp(winSize.width/2, winSize.height/2));
        this->addChild(finalScore);
        
        if (CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
		{
			CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
		}
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("game_over.mp3");
        
        bRet = true;
    } while (0);
    
    return bRet;
}
Пример #7
0
bool GameLayer::init()
{
    if (!CCLayer::init()) {
        return false;
    }
    // 开启触摸
    this->setTouchEnabled(true);
    
    // 创建数组,需要retain一下
    play_bullet = CCArray::create();
    play_bullet->retain();
    
    enemy_bullet = CCArray::create();
    enemy_bullet->retain();
    
    enemy_items = CCArray::create();
    enemy_items->retain();
    
    m_state = statePlaying;//statePlaying=0
    
    Enemy::sharedEnemy();
    Effect::sharedExplosion();
    
    Config::sharedConfig()->resetConfig();
    
    winSize = CCDirector::sharedDirector()->getWinSize();
    m_levelManager = new LevelManager(this);
    
    //初始化背景
    initBackground();

    m_screenRec = CCRectMake(0, 0,  winSize.width, winSize.height + 10);
    
    // score
	CCLabelBMFont *scoreLabel = CCLabelBMFont::create("SCORE: ", s_arial14_fnt);
	scoreLabel->setAnchorPoint(ccp(0, 0));
	addChild(scoreLabel, 1000);
	scoreLabel->setColor(ccc3(255, 240, 188));
	scoreLabel->setPosition(100, winSize.height - 30);
	{
		//  1 1 000
		m_lbScore1 = CCLabelBMFont::create("", s_arial14_fnt);
		m_lbScore1->setAnchorPoint(ccp(0, 0));
		m_lbScore1->setColor(ccc3(200,0,200));
		addChild(m_lbScore1, 1000);
		m_lbScore1->setPosition(scoreLabel->getPositionX()+scoreLabel->getContentSize().width, scoreLabel->getPositionY());
		//
		m_lbScore2 = CCLabelBMFont::create("", s_arial14_fnt);
		m_lbScore2->setAnchorPoint(ccp(0, 0));
		m_lbScore2->setColor(ccYELLOW);
		addChild(m_lbScore2, 1000);
		m_lbScore2->setPosition(m_lbScore1->getPositionX()+m_lbScore1->getContentSize().width, m_lbScore1->getPositionY());
		//
		m_lbScore3 = CCLabelBMFont::create("", s_arial14_fnt);
		m_lbScore3->setAnchorPoint(ccp(0, 0));
		addChild(m_lbScore3, 1000);
		m_lbScore3->setPosition(m_lbScore2->getPositionX()+m_lbScore2->getContentSize().width, m_lbScore2->getPositionY());
	}
    
    // ship life
    CCTexture2D *shipTexture = CCTextureCache::sharedTextureCache()->addImage(s_ship01);
    CCSprite *life = CCSprite::createWithTexture(shipTexture, CCRectMake(0, 0, 60, 38));
    life->setScale(0.6);
    life->setPosition(ccp(30,winSize.height-23));
    addChild(life, 1, 5);
    
    // ship life count
    char lifecount[2];
    sprintf(lifecount, "%d",Config::sharedConfig()->getLifeCount()-1);
    m_lifeCount = CCLabelTTF::create(lifecount, "Arial", 20);
    m_lifeCount->setPosition(ccp(60, winSize.height-20));
    m_lifeCount->setColor(ccc3(255,0, 0));
    addChild(m_lifeCount, 1000);
    
    // ship
    m_ship = Ship::create();
    addChild(m_ship, m_ship->getZoder(), 1001);
    
	//pause
    CCMenuItemImage *pause = CCMenuItemImage::create("pause.png", "pause.png", this, menu_selector(GameLayer::doPause));
    pause->setAnchorPoint(ccp(1, 1));
	pause->setScale(0.8);
	pause->setPosition(ccp(winSize.width, winSize.height));
    CCMenu *menu = CCMenu::create(pause, NULL);
    menu->setAnchorPoint(ccp(0, 0));
    addChild(menu, 1, 10);
    menu->setPosition(CCPointZero);
    
    // 调 update函数
    scheduleUpdate();
    
    // 每秒调一次 scoreCounter函数
    schedule(schedule_selector(GameLayer::scoreCounter), 1);
    
    if (Config::sharedConfig()->getAudioState()) {
        SimpleAudioEngine::sharedEngine()->playBackgroundMusic(s_bgMusic, true);
    }
    
    return true;
}
Пример #8
0
bool GameOverLayer::init()
{
	bool bRet = false;
	do
	{
		CC_BREAK_IF(!CCLayer::init());
		//停止背景音乐,播放gameover的音效
		if (CocosDenshion::SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying())
		{
			CocosDenshion::SimpleAudioEngine::sharedEngine()->stopBackgroundMusic();
		}
		CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("sound/game_over.mp3");

		CCSize winSize = CCDirector::sharedDirector()->getWinSize();

		//加载gameover_background
		CCSprite* background = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("gameover.png"));
		background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(background);

		//加载BackMenu
		CCSprite* normalBackToGame = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));//正常状态下的按钮图片
		CCSprite* pressedBackToGame = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("btn_finish.png"));//按下状态下的按钮图片
		CCMenuItemImage* pBackItem = CCMenuItemImage::create();//创建menu的item
		pBackItem->initWithNormalSprite(normalBackToGame, pressedBackToGame, NULL, this, menu_selector(GameOverLayer::menuBackCallback));//设置
		pBackItem->setPosition(ccp(winSize.width - normalBackToGame->getContentSize().width / 2 - 10, normalBackToGame->getContentSize().height / 2 + 10));//位置
		CCMenu *menuBack = CCMenu::create(pBackItem, NULL);//创建menu并加入item
		menuBack->setPosition(Point::ZERO);//位置
		this->addChild(menuBack);//加入layer

		//加载score
		CCString* strScore = CCString::createWithFormat("%d", score);
		CCLabelBMFont* finalScore = CCLabelBMFont::create(strScore->_string.c_str(), "res/assets/font/font.fnt");
		finalScore->setColor(ccc3(143, 146, 147));
		finalScore->setPosition(ccp(winSize.width / 2, winSize.height / 2));
		this->addChild(finalScore);

		CCDelayTime* delay = CCDelayTime::create(1.0f);
		CCScaleTo* scalebig = CCScaleTo::create(1.0f, 3.0f);
		CCScaleTo* scalelittle = CCScaleTo::create(0.3f, 2.0f);
		CCCallFunc* showAD = CCCallFunc::create(this, callfunc_selector(GameOverLayer::showAD));
		CCFiniteTimeAction* sequence = CCSequence::create(delay, scalebig, scalelittle, showAD, NULL);
		finalScore->runAction(sequence);

		//加载历史最高分
		//CCLabelTTF* tip=CCLabelTTF::create("Congratulations! Your Score is","Monaco",20);
		//tip->setColor(ccc3(143,146,147));
		//tip->setPosition(ccp(finalScore->getPosition().x,finalScore->getPosition().y+finalScore->getContentSize().height+50));
		//this->addChild(tip);
		CCString* strHighestScore = CCString::createWithFormat("%d", highestHistoryScore);
		highestScore = CCLabelBMFont::create(strHighestScore->_string.c_str(), "res/assets/font/font.fnt");
		highestScore->setColor(ccc3(143, 146, 147));
		highestScore->setAnchorPoint(ccp(0, 0.5));//设置锚点,即为缩放等操作的发生点。
		highestScore->setPosition(ccp(140, winSize.height - 30));
		this->addChild(highestScore);
		//如果分数比最高分高,则更新最高分,并显示,播放动画
		if (score > highestHistoryScore)
		{
			CCUserDefault::sharedUserDefault()->setIntegerForKey("HighestScore", score);
			highestHistoryScore = score;
			CCDelayTime* delayChange = CCDelayTime::create(1.3f);
			CCMoveBy* moveOut = CCMoveBy::create(0.1f, ccp(0, 100));
			CCCallFuncN* beginChange = CCCallFuncN::create(this, callfuncN_selector(GameOverLayer::beginChangeHighestScore));
			CCMoveBy* moveIn = CCMoveBy::create(0.1f, ccp(0, -100));
			CCFiniteTimeAction* sequence = CCSequence::create(delayChange, moveOut, beginChange, moveIn, NULL);
			highestScore->runAction(sequence);
		}

		this->setKeypadEnabled(true);

		bRet = true;
	} while (0);
	return bRet;
}
Пример #9
0
void MainGameScene::update(float dt)
{

	// update game scene
	
	//update character
	mainCharacter->Update(dt);

	// update blocks
	//iterate through the list
	std::list<ColorBlock*>::iterator it;
	//lets just pretend that no more than 5 blocks will be deleted in the same frame

	std::list<ColorBlock*>::iterator toDelete[5];
	int amountToDelete = 0;
	for (it = blocksList.begin(); it != blocksList.end(); it++)
	{
		// only process if the block isn't dying
		if (!(*it)->GetDying())
		{
			// check if it's time to kill the block
			if ((*it)->getPositionY() > 650.0f || (*it)->getPositionY() < -85.0f ||
				(*it)->getPositionX() < -20.0f || (*it)->getPositionX() > 850.0f)
			{
				if(amountToDelete < 5)
				{
					toDelete[amountToDelete] = it;
					amountToDelete++;
				}
			}
			else
			{
				// dont process if the block is already connected with the character
				if (!(*it)->GetAttached())
				{
					// process colision detection
					b2ContactEdge* edge = (*it)->GetBody()->GetContactList();
					while (edge != NULL) // if == null, no more collisions
					{
						if (edge->contact->IsTouching())
						{
							// iterate through the list of contacts
							// if collided with character, don't delete
							if (((CCSprite*)edge->contact->GetFixtureB()->GetBody()->GetUserData())->getTag() == CHARACTER_TAG ||
								((CCSprite*)edge->contact->GetFixtureA()->GetBody()->GetUserData())->getTag() == CHARACTER_TAG)
							{
								// the block collided with character
								(*it)->AttachTo(mainCharacter->GetBody());
							}
							// check if it's a attached block, so attached to this one
							else if (((CCSprite*)edge->contact->GetFixtureB()->GetBody()->GetUserData())->getTag() == BLOCK_TAG && 
								((CCSprite*)edge->contact->GetFixtureA()->GetBody()->GetUserData())->getTag() == BLOCK_TAG)
							{
								// check which one is the IT
								// attached based on this
								if (edge->contact->GetFixtureA()->GetBody() == (*it)->GetBody())
								{
									// make sure it's already attached
									if(((ColorBlock*)edge->contact->GetFixtureB()->GetBody()->GetUserData())->GetAttached() &&
										!((ColorBlock*)edge->contact->GetFixtureB()->GetBody()->GetUserData())->GetDying())
									{
										// attach on B fixture
										(*it)->AttachTo(edge->contact->GetFixtureB()->GetBody());
									}
								}
								else
								{
									if(((ColorBlock*)edge->contact->GetFixtureA()->GetBody()->GetUserData())->GetAttached() &&
										!((ColorBlock*)edge->contact->GetFixtureA()->GetBody()->GetUserData())->GetDying())
									{
										// attach on A fixture
										(*it)->AttachTo(edge->contact->GetFixtureA()->GetBody());
									}
								}
							}
						}
						edge = edge->next; // go to the next colision
					}
				}
				// now process those which are already attached to the character body
				else
				{
					(*it)->BuildConnections(NULL, -1);

					// check if one of the attached blocks is on the death area
					if ((*it)->getPositionX() < 0.0f || (*it)->getPositionX() > 800.0f || 
						(*it)->getPositionY() > 600.0f || (*it)->getPositionY() < 0.0f)
					{
						if (isConnected)
						{
							//send gameover signal through network
							RakNet::BitStream BsOut;
							BsOut.Write((RakNet::MessageID)ID_GAME_PLAYER_LOST);
							player2->Send(&BsOut,HIGH_PRIORITY,RELIABLE_ORDERED,0,player2Adress,false);
						}
						// game over animation goes here
						// for now just call the next scene
						//CCDirector::sharedDirector()->replaceScene(CCTransitionProgressHorizontal::transitionWithDuration(1.0f,PointsScene::scene()));
						CCDirector::sharedDirector()->pushScene(CCTransitionProgressHorizontal::transitionWithDuration(1.0f,PointsScene::scene()));
						// to prevent thousands of scenes being created
						this->unscheduleUpdate();
					}

				}
			}
		}
		else
		{
			// check if it's time to be deleted
			if((*it)->getOpacity() == 0)
			{
				if(amountToDelete < 5)
				{
					toDelete[amountToDelete] = it;
					amountToDelete++;
				}
			}
		}
	}

	// delete dead ones
	for (int i = 0; i < amountToDelete; i++)
	{
		// remove from batch
		blocksBatch->removeChild((*toDelete[i]),true);
		// remove from local list
		blocksList.erase(toDelete[i]);
	}

	// update physics engine
	box2DWorld->Step(dt,20,20);
	
	// update raknet
	if (isConnected)
	{
		// receive packets
		RakNet::Packet* packet;
		for (packet = player2->Receive();packet;player2->DeallocatePacket(packet),packet=player2->Receive())
		{
			// only process a packet that came from the other player
			if (packet->systemAddress == player2Adress)
			{
				// player disconnected
				if (packet->data[0] == ID_DISCONNECTION_NOTIFICATION || 
					packet->data[0] == ID_CONNECTION_LOST)
				{
					isConnected = false;
					// put some warning on the screen
					//create a text and make it goes up
					CCLabelBMFont* discWarning = CCLabelBMFont::create("Your opponent just disconnected","Assets/badab.fnt");
					discWarning->setColor(ccc3(255,0,0));
					discWarning->setPosition(ccp(400.0f,-20.0f));
					CCSequence* warningSequence = CCSequence::create(CCMoveTo::create(4.0f,ccp(400.0f,200.0f)),
						CCCallFuncO::create(this,callfuncO_selector(MainGameScene::DeleteDisctionnectionWarning),discWarning));
					discWarning->runAction(warningSequence);
					discWarning->runAction(CCFadeOut::create(4.0f));//fade
					this->addChild(discWarning,1000);
				}
				// other player just lost
				else if (packet->data[0] == ID_GAME_PLAYER_LOST)
				{
					otherGameOver = true;
				}
				else if (packet->data[0] == ID_GAME_NEW_POINTS)
				{
					// read new points from the other player
					int rs = 0;
					RakNet::BitStream bsIn(packet->data,packet->length,false);
					bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
					bsIn.Read((char*)&rs,sizeof(int));
					pointsManager->SetP2Points(rs);
				}
				else if(packet->data[0] == ID_GAME_INIT_SWAP)
				{
					// other player will swap, prepare
					ChangeScreenSpecial* change = ChangeScreenSpecial::create();
					this->addChild(change,701);
					change->ExecuteActual();
					change->setTag(978);
				}
				else if(packet->data[0] == ID_GAME_SWAP_SCREENS)
				{
					// received information
					std::vector<BlockInformation> received;
					RakNet::BitStream bsIn(packet->data,packet->length,false);
					bsIn.IgnoreBytes(sizeof(RakNet::MessageID));
					// number of blocks within the package
					int size = 0;
					bsIn.Read((char*)&size,sizeof(int));
					BlockInformation* reci = new BlockInformation[size];
					bsIn.Read((char*)reci,sizeof(BlockInformation) * size);
					// put on the received vector
					for (int p = 0; p < size; p++)
					{
						received.push_back(reci[p]);
					}
					delete reci;
					// now change the blocks
					//delete all non-dying blocks
					std::list<ColorBlock*>::iterator it;
					std::vector<ColorBlock*> toDelete;
					for (it = blocksList.begin(); it != blocksList.end(); it++)
					{
						if (!(*it)->GetDying())
						{
							toDelete.push_back(*it);
						}
					}
					//delete them
					for (int c = 0; c < toDelete.size();c++)
					{
						blocksBatch->removeChild(toDelete[c],true);
						blocksList.remove(toDelete[c]);
					}
					//put them back

					for (int c = 0; c < received.size(); c++)
					{
						// create block on a random location
						ColorBlock* newBlock = ColorBlock::create("Assets/block.png");
						// unattached blocks have 50% opacity
						newBlock->setOpacity(127);

						newBlock->setPositionX(received[c].posX);
						newBlock->setPositionY(received[c].posY);

						// add as a child to the batch
						blocksBatch->addChild(newBlock);
						//mainScene->addChild(newBlock);

						newBlock->InitInWorld(box2DWorld);

						if (received[c].color == BLOCK_GREEN)
						{
							newBlock->setColor(ccc3(0,255,0));
						}
						else if (received[c].color == BLOCK_RED)
						{
							newBlock->setColor(ccc3(255,0,0));
						}
						else if (received[c].color == BLOCK_BLUE)
						{
							newBlock->setColor(ccc3(0,0,255));
						}
						// add to local list
						blocksList.push_back(newBlock);
					}
				}
			}
		}
	}
}
Пример #10
0
void GameOver::finishGetScores(JsonBox::Object js)
{
//	ostringstream oss;
//	oss << js << endl;
//	CCLog("**********************************************************************\n%s", oss.str().c_str());
	
	try {
		KS::KSLog("%", js);
		KS::KSLog("%", js["state"].getString().c_str());
		if(js["state"].getString() != "ok")
			throw string(gt("retrying").c_str());
		mediator->incLoadCount();
		CCLabelBMFont* allUsers = CCLabelBMFont::create(KS_Util::stringWithFormat("%d", js["alluser"].getInt()).c_str(), "main1.fnt");
//		allUsers->setColor(ccc3(0,0,0));
		allUsers->setPosition(ccp(226, 264));
		thiz->addChild(allUsers, 2);
		
		
		
		JsonBox::Array jList = js["list"].getArray();
		int st = js["timestamp"].getInt();
		int z = jList.size();

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

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

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

		


		
	} catch (const string& msg) {
		mediator->showFailedGameOver(msg);
		
	}
	
	
	
}
Пример #11
0
 bool ComicScene::init() {
     if ( !CCLayer::init() ) {
         return false;
     }
     this->setIsKeypadEnabled(true);
     CCDirector::sharedDirector()->resume();
     this->touchEnabled=true;
     this->currentPage = 0;
     this->cleanAfterExit = false;
     CCSpriteBatchNode* batch = new CCSpriteBatchNode();
     batch->initWithTexture(CCTextureCache::sharedTextureCache()->textureForKey(Config::sharedConfig()->COMIC_PNG.c_str()), 6);
     this->addChild(batch, 0, BATCH_COMIC_INTRO_TAG);
     CCSprite* gSettingBackground = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_BG.c_str());
     gSettingBackground->setPosition(Geometry::getScreenCenter());
     this->addChild(gSettingBackground, 0);
     CCLabelBMFont* labelTouch = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_CONTINUE.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str());
     labelTouch->setColor(ccc3(50,50,50));
     labelTouch->setScale(0.7);
     labelTouch->setPosition( CCPoint(Geometry::getScreenBotomCenter(24)) );
     this->addChild(labelTouch, 2, 100);
     if(!SimpleAudioEngine::sharedEngine()->isBackgroundMusicPlaying() && SimpleAudioEngine::sharedEngine()->getBackgroundMusicVolume() > 0) {
         SimpleAudioEngine::sharedEngine()->playBackgroundMusic(CCFileUtils::fullPathFromRelativePath(MUSIC_LEVEL2.c_str()), true);
     }
     CCSprite* sPage1;
     CCSprite* sPage2;
     CCSprite* sPage3;
     CCLabelBMFont* sText1;
     CCLabelBMFont* sText2;
     CCLabelBMFont* sText3;
     if (sequence == 1) {
         sPage1 = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_1.c_str());
         sPage1->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_A)) );
         sPage1->setOpacity(0);
         this->addChild(sPage1, 1, 1);
         sText1 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_1.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str());
         sText1->setColor(ccc3(45,0,0));
         sText1->setPosition( CCPoint(Geometry::getScreenUpCenter(-Config::sharedConfig()->COMIC_ADJUST_TXT_A)) );
         this->addChild(sText1, 1, 2);
         sPage2 = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_2.c_str());
         sPage2->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_B)) );
         sPage2->setOpacity(0);
         this->addChild(sPage2, 1, 3);
         sText2 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_2.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str());
         sText2->setColor(ccc3(45,0,0));
         sText2->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(-Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_C)) );
         this->addChild(sText2, 1, 4);
         sPage3 = CCSprite::spriteWithSpriteFrameName(COMIC_INTRO_3.c_str());
         sPage3->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_C)) );
         sPage3->setOpacity(0);
         this->addChild(sPage3, 1, 5);
         sText3 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_3.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str());
         sText3->setColor(ccc3(45,0,0));
         sText3->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_C)) );
         this->addChild(sText3, 1, 6);
         this->totalPages = 3;
     } else if (sequence == 2) {
         sPage1 = CCSprite::spriteWithSpriteFrameName(COMIC_END_1.c_str());
         sPage1->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_A)) );
         sPage1->setOpacity(0);
         this->addChild(sPage1, 1, 1);
         sText1 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_4.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str());
         sText1->setColor(ccc3(45,0,0));
         sText1->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(-Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_A)) );
         this->addChild(sText1, 1, 2);
         sPage2 = CCSprite::spriteWithSpriteFrameName(COMIC_END_2.c_str());
         sPage2->setPosition( CCPoint(Geometry::getScreenBotomCenter(Config::sharedConfig()->COMIC_ADJUST_PAGE_E)) );
         sPage2->setOpacity(0);
         this->addChild(sPage2, 1, 3);
         sText2 = CCLabelBMFont::labelWithString(Config::sharedConfig()->LANG_COMIC_TEXT_5.c_str(), Config::sharedConfig()->BMFONT_NAME.c_str());
         sText2->setColor(ccc3(45,0,0));
         sText2->setPosition( CCPoint(Geometry::getScreenUpCenterAdjust(Config::sharedConfig()->SCREEN_WIDTH,Config::sharedConfig()->COMIC_ADJUST_TXT_E)) );
         this->addChild(sText2, 1, 4);
         this->totalPages = 2;
     }
     showCurrentPage();
     CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
     //ipad fix
     if(CCDirector::sharedDirector()->getWinSizeInPixels().width >= 768) {
         Border* border = new Border();
         this->addChild(border, 999);
     }
     return true;
 }