コード例 #1
0
ファイル: weather.cpp プロジェクト: lumidify/blobandconquer
void doWeather()
{
	if (mission->weather == WEATHER_NORMAL)
	{
		return;
	}
	
	switch (mission->weather)
	{
		case WEATHER_RAIN:
			doRain(player->position, 500, 7 * engine->getTimeDifference(TD_LOGIC));
			break;
			
		case WEATHER_LIGHT_RAIN:
			doRain(player->position, 700, 1 * engine->getTimeDifference(TD_LOGIC));
			break;
			
		case WEATHER_STORM:
		case WEATHER_HEAVY_RAIN:
			doRain(player->position, 500, 20 * engine->getTimeDifference(TD_LOGIC));
			break;
			
		default:
			break;
	}
}
コード例 #2
0
ファイル: GameState.cpp プロジェクト: CicadaKim/ZombieHunter
// 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;
}