Exemplo n.º 1
0
KDbool SGameLayer::init ( KDvoid )
{
	if ( !CCLayer::init ( ) )
	{
		return KD_FALSE;
	}

	CCSprite*	pSprite = CCSprite::create ( "background.png" );
	pSprite->setPosition ( ccpMid ( m_tContentSize ) );
	this->addChild ( pSprite );

	m_pMapLayer = SMapLayer::create ( );
	m_pMapLayer->setDelegate ( this );
	m_pMapLayer->loadMapWithLevel ( SLevelManager::sharedLevelManager ( )->getLevel ( ) );
	m_pMapLayer->setPosition ( ccp ( 20, -15 ) );
	this->addChild ( m_pMapLayer, 1 );

	CCSprite*	pMenuBg = CCSprite::create ( "menu.png" );
	pMenuBg->setPosition ( ccp ( m_tContentSize.cx / 2, m_tContentSize.cy - 15 ) );
	this->addChild ( pMenuBg, 5 ); 

	m_pLevelLabel = CCLabelTTF::create ( "Level:0", "Marker Felt.ttf", 32 );
	m_pLevelLabel->setPosition ( ccp  ( 70, m_tContentSize.cy - 15 ) );
	m_pLevelLabel->setScale ( 0.6f );
	m_pLevelLabel->setColor ( ccYELLOW );
	this->addChild ( m_pLevelLabel, 5, 1 );
	this->setLevelCount ( SLevelManager::sharedLevelManager ( )->getCurrentLevel ( ) );

	m_pStepLabel = CCLabelTTF::create ( "000", "Marker Felt.ttf", 32 );
	m_pStepLabel->setScale ( 0.6f );
	m_pStepLabel->setColor ( ccYELLOW );
	m_pStepLabel->setPosition ( ccp  ( 230, m_tContentSize.cy - 15 ) );
	this->addChild ( m_pStepLabel, 5, 1 );
	this->setStepCount ( 0 );	

	CCMenuItemImage*	pPrevLevel = CCMenuItemImage::create ( "previous.png", "previous.png", this, menu_selector ( SGameLayer::onPrev ) );
	( (CCSprite*) pPrevLevel->getSelectedImage ( ) )->setOpacity ( 128 );
	pPrevLevel->setPosition ( ccp ( 0, 0 ) );

	CCMenuItemImage*	pNextLevel = CCMenuItemImage::create ( "next.png", "next.png", this, menu_selector ( SGameLayer::onNext ) );
	( (CCSprite*) pNextLevel->getSelectedImage ( ) )->setOpacity ( 128 );
	pNextLevel->setPosition ( ccp ( 40, 0 ) );

	CCMenuItemImage*	pResetLevel = CCMenuItemImage::create ( "reset.png", "reset.png", this, menu_selector ( SGameLayer::onReset ) );
	( (CCSprite*) pResetLevel->getSelectedImage ( ) )->setOpacity ( 128 );
	pResetLevel->setPosition ( ccp ( 80, 0 ) );
	
	CCMenu*		pMenu = CCMenu::create ( pPrevLevel, pNextLevel, pResetLevel, KD_NULL );
	pMenu->setPosition ( ccp  ( m_tContentSize.cx - 140, m_tContentSize.cy - 15 ) );
	this->addChild ( pMenu, 5, 1 ); 

	return KD_TRUE;
}
Exemplo n.º 2
0
void TutorialManager::explainFive()
{
	back = CCSprite::create("tutorial/tuto_back.png");
	back->setPosition(ccp(target->getContentSize().width*0.5,target->getContentSize().height*0.5));

	target->addChild(back,ZORDER_TUTORIAL_BACK);

	CCSprite* messageBox = CCSprite::create("tutorial/message_popup_box06.png");
	
	messageBox->setPosition(ccp(480,194));

	back->addChild(messageBox);

	CCMenuItemImage* tutorialEnd = CCMenuItemImage::create("tutorial/tutorial_end_button.png","tutorial/tutorial_end_button.png",this,
		menu_selector(TutorialManager::tutorialEnd));

	tutorialEnd->getSelectedImage()->setScale(0.9f,0.9f);

	CCMenu* menu = CCMenu::create(tutorialEnd,NULL);

	menu->setPosition(ccp(480,85));

	back->addChild(menu);

	for(int i=0;i<5;i++)
	{
			touchIcon[i] = CCSprite::create("tutorial/touch_icon.png");
			touchIcon[i]->setPosition(ccp(338+100*i,470));
			target->addChild(touchIcon[i],ZORDER_TUTORIAL_BACK+2);
	}
}
Exemplo n.º 3
0
void TutorialManager::explainDead(UserInterface* targetInterface)
{
	this->targetInterface = targetInterface;

	back = CCSprite::create("tutorial/tuto_back.png");
	back->setPosition(ccp(target->getContentSize().width*0.5,target->getContentSize().height*0.5));

	target->addChild(back,ZORDER_TUTORIAL_BACK);

	CCSprite* messageBox = CCSprite::create("tutorial/message_popup_box07.png");
	
	messageBox->setPosition(ccp(480,330));

	back->addChild(messageBox);

	CCMenuItemImage* confirm = CCMenuItemImage::create("tutorial/confirm.png","tutorial/confirm.png",this,
		menu_selector(TutorialManager::deadExplainEnd));

	confirm->getSelectedImage()->setScale(0.9f,0.9f);

	CCMenu* menu = CCMenu::create(confirm,NULL);

	menu->setPosition(ccp(480,220));

	back->addChild(menu);
}
KDvoid SuperMarioClick::createMenu ( KDvoid )
{
	CCMenuItemImage*	pReset = CCMenuItemImage::create ( "Reset.png", "Reset.png", this, menu_selector ( SuperMarioClick::resetGame ) );    
	( (CCSprite*) pReset->getSelectedImage ( ) )->setOpacity ( 200 );

	CCMenu*				pMenu  = CCMenu::createWithItem ( pReset ); 	
	pMenu->setPosition ( m_tContentSize.cx - 36 * 3, m_tContentSize.cy - 36 );	
	this->addChild ( pMenu, -1 );
}
Exemplo n.º 5
0
// on "init" you need to initialize your instance
bool GameState::init()
{
   //////////////////////////////
	// 1. super init first
	///LayerColor->Layer로 바꿔야됨. 성능차이 많이나는듯
	
	if ( !CCLayer::init() )
	{
		return false;
	}
	Camera::sharedCameraInstance()->release();
	
	CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
	CCPoint origin = CCDirector::sharedDirector()->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

	// create menu, it's an autorelease object

	this->setTouchEnabled(true);

	for(int i=0;i<2;i++)
	{
		CCMenuItemImage* buttonLeftImg = CCMenuItemImage::create("UI/move_left_normal.png","UI/move_left_normal.png");
		CCMenuItemImage* buttonRightImg = CCMenuItemImage::create("UI/move_right_normal.png","UI/move_right_normal.png");

		CCSprite *pressImg = CCSprite::create("UI/move_left_normal.png");
		pressImg->setOpacity(100);
		buttonLeftImg->setSelectedImage(pressImg);

		CCSprite *pressRightImg = CCSprite::create("UI/move_right_normal.png");
		pressRightImg->setOpacity(100);
		buttonRightImg->setSelectedImage(pressRightImg);

		if(i == 0)	{
			buttonLeftImg->setPosition(ccp(60,60));
			buttonRightImg->setPosition(ccp(160,60));
		}
		else	{
			buttonLeftImg->setPosition(ccp(800,60));
			buttonRightImg->setPosition(ccp(900,60));
		}
		buttonLeftImg->setTag(LEFT_BUTTON);
		buttonRightImg->setTag(RIGHT_BUTTON);

		buttons[i] = Buttons::create();

		buttons[i]->setMusicSrc("music/ui/ui_click.ogg");

		buttons[i]->addChild(buttonLeftImg);
		buttons[i]->addChild(buttonRightImg);

		buttons[i]->setPosition(CCPointZero);

		this->addChild(buttons[i],ZORDER_BUTTON);
	}

	CCMenuItemFont* pMenuItem1 = CCMenuItemFont::create("Http Post",this,menu_selector(GameState::sendPostHttp));
	CCMenuItemFont* pMenuItem2 = CCMenuItemFont::create("Http Get",this,menu_selector(GameState::sendGetHttp));

	pMenuItem2->setColor(ccc3(255,255,255));
	pMenuItem1->setColor(ccc3(255,255,255));
	
	CCMenu* pMenu = CCMenu::create(pMenuItem1,pMenuItem2,NULL);
	pMenu->setPosition(240,160);
	pMenu->alignItemsVertically();
	//this->addChild(pMenu);

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

	// add a label shows "Hello World"
	// create and initialize a label

	CCLabelTTF* pLabel = CCLabelTTF::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 "GameState" splash screen"
	CCSprite* pSprite = CCSprite::create("background/background_1.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
#ifndef BODY_DEBUG
	this->addChild(pSprite, -20);
#endif
	//pChracImg = CCSprite::create("chracter/move_ani.png");

	//box2d///

	b2Vec2 gravity = b2Vec2(0.0f,-30.0f);
	_world = new b2World(gravity);
	_world->SetAllowSleeping(true);
	_world->SetContinuousPhysics(true);

	
	contactListener = new MyContactListener();
	_world->SetContactListener((b2ContactListener*)contactListener);

	b2BodyDef groundBodyDef;

	groundBodyDef.position.Set(0,0);

	b2Body *groundBody = _world->CreateBody(&groundBodyDef);

	b2EdgeShape groundEdge;
	b2FixtureDef boxShapeDef;
	boxShapeDef.shape = &groundEdge;
	
	CCSize s = this->getContentSize();
	//////////////////////////////////////// Debug
#ifdef BODY_DEBUG
	b2Draw *debugDraw = new GLESDebugDraw(PTM_RATIO); //PTM_RATIO 를 1~3 정도로 작게 두니까 맞던데?

	debugDraw->SetFlags(GLESDebugDraw::e_shapeBit);

	_world->SetDebugDraw(debugDraw);
#endif

	//doSnow();

	pressing = false;

	//doRain();

	////////////////////////pause
	pauseButton = Buttons::create();

	CCMenuItemImage* pauseImage = CCMenuItemImage::create("UI/pause.png","UI/pause.png",NULL,this,
		menu_selector(GameState::pauseGame));

	pauseImage->getSelectedImage()->setScale(0.9f,0.9f);

	CCSize pauseSize = pauseImage->getContentSize();

	pauseButton->addChild(pauseImage);

	pauseButton->setPosition(ccp(getContentSize().width-pauseSize.width*0.5,getContentSize().height-pauseSize.height*0.5));

	this->addChild(pauseButton,ZORDER_INTERFACE);

	//////////////////////////////Stage

	stageManager = new StageManager(_world,this);

	//////////////Sound
	SoundManager::getInstance()->playBackgroundMusic("music/background/game_bgm_loop.ogg",true);
	SoundManager::getInstance()->setBackgroundMusicVolume(0.3f);

	PauseState::getInstance()->setResumeTarget(this);
	EffectManager::getInstance()->setTarget(this);

	//fade
	fade = CCSprite::create("over/fade.png");
	fade->setOpacity(0);
	fade->setPosition(ccp(visibleSize.width/2,visibleSize.height/2));
	fade->retain();

#if(CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
	this->setKeypadEnabled(true);					//키패드 활성.
#endif

	userInterface = new UserInterface(this);


	doRain();

	isPressReload = false;

	tutorialManager = new TutorialManager(this);
	tutorialManager->setCurrentPage(100);

	this->schedule(schedule_selector(GameState::update));
	this->schedule(schedule_selector(Timer::update));
	this->schedule(schedule_selector(GameState::box2DTest));

	stageManager->stageUp();

	ScoreManager::sharedInstance()->moveDistance = 0;
	ScoreManager::sharedInstance()->point = 0;

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

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

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

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

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

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

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