Example #1
0
int StageManager::allCheck(int id) {
	//id = 0 BRUE, id = 1 RED
	int brue, red;
	UserDefault* userdef = UserDefault::getInstance();
	brue = 0, red = 0;
	//BRUE
	if (id == 0) {
		for (int i = 0; i < m_Container.size(); ++i) {
			if (m_Container.at(i)->getColor() == Color3B::BLUE) {
				 ++brue;
				 userdef->setIntegerForKey("blue", brue);
			}
		}
		return brue;
	}
	//RED
	if (id == 1) {
		for (int i = 0; i < m_Container.size(); ++i) {
			if (m_Container.at(i)->getColor() == Color3B::RED) {
				++red;
				userdef->setIntegerForKey("red", red);
			}
		}
		return red;
	}
}
Example #2
0
void InGameLayer::MenuBombCallback()
{
	SimpleAudioEngine::getInstance()->playEffect("sound/use_bomb.mp3");
	cleanAllEnemys();
	if(bombNum>0)
		bombNum--;

	auto label = static_cast<Label*>(this->getChildByTag(GameSceneNodeTagNumLabel));
	auto menu = static_cast<Menu*>(this->getChildByTag(GameSceneNodeTagMenuBomb));

	if (bombNum == 0)
	{
		label->setVisible(false);
		menu->setVisible(false);
	}
	else
	{
		label->setString(__String::createWithFormat("x%d",bombNum)->getCString());
	}
	score += 100;
	scoreLabel->setString(__String::createWithFormat("%d",score)->getCString());
	UserDefault *defaults = UserDefault::getInstance();
	int highScore = defaults->getIntegerForKey("highscore_key");    
	if (highScore < score) {
		highScore = score;
		defaults->setIntegerForKey("highscore_key", highScore);
	}
	__String *text = __String::createWithFormat("%i", highScore);

	auto lblScoreOfHigh = static_cast<Label*>(this->getChildByTag(GameSceneNodelblHighScore));
	lblScoreOfHigh->setString(text->getCString());
}
// on "init" you need to initialize your instance
bool GameOverScene::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();

	auto backgroundSprite = Sprite::create("Background.png");
	backgroundSprite->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y));

	this->addChild(backgroundSprite);

	auto retryItem = MenuItemImage::create("Retry Button.png", "Retry Button Clicked.png", CC_CALLBACK_1(GameOverScene::GoToGameScene, this));
	retryItem->setPosition(Point(visibleSize.width /2 + origin.x, visibleSize.height / 4 * 3));

	auto mainMenuItem = MenuItemImage::create("Menu Button.png", "Menu Button Clicked.png", CC_CALLBACK_1(GameOverScene::GoToMainMenuScene, this));
	mainMenuItem->setPosition(Point(visibleSize.width /2 + origin.x, visibleSize.height / 4 ));

	auto menu = Menu::create(retryItem, mainMenuItem, NULL);
	menu->setPosition(Point::ZERO);

	this->addChild(menu);

	UserDefault *def = UserDefault::getInstance();

	auto highScore = def->getIntegerForKey("HIGHSCORE", 0);

	if (score > highScore)
	{
		highScore = score;

		def->setIntegerForKey("HIGHSCORE", highScore);
	}

	def->flush();

	__String *tempScore = __String::createWithFormat("Current : %i", score);

	auto currentScore = LabelTTF::create(tempScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);
	currentScore->setPosition(Point(visibleSize.width * 0.25 + origin.x, visibleSize.height /2 + origin.y ));

	this->addChild(currentScore);
	
	__String *temHighpScore = __String::createWithFormat("High : %i", highScore);

	auto highScoreLabel = LabelTTF::create(temHighpScore->getCString(), "fonts/Marker Felt.ttf", visibleSize.height * SCORE_FONT_SIZE);

	highScoreLabel->setColor(Color3B::YELLOW);
	highScoreLabel->setPosition(Point(visibleSize.width * 0.75 + origin.x, visibleSize.height / 2 + origin.y));

	this->addChild(highScoreLabel);

	return true;
}
void HighScoreManager::registerCurrentScore(int score)
{
    UserDefault* userDef = UserDefault::getInstance();
    if (score > userDef->getIntegerForKey(KEY_HIGHSCORE.c_str(), 0))
    {
        userDef->setIntegerForKey(KEY_HIGHSCORE.c_str(), score);
    }
}
Example #5
0
void TutorialScene::resetSaveData()
{
	const int maxNumMonsters = 3;
	const int maxNumKnown = 31;

	//データをリセット
	//Set every SaveDataKey for Monsters and Equipment to 0 (eEmpty)
	UserDefault* def = UserDefault::getInstance();

	for (int i = 0; i < maxNumMonsters; i++)
	{
		def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonsterData01 + i].c_str(), n_MonsterData::eEmpty);

	}
	for (int i = 0; i < maxNumKnown; i++)
	{
		def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01 + i].c_str(), false);
	}
	def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01].c_str(), true);

	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster1Exp].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster2Exp].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster3Exp].c_str(), 0);

	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum01].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum02].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum03].c_str(), 0);

	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum01].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum02].c_str(), 0);
	def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum03].c_str(), 0);


	def->flush();
}
void ThirdPartyHelper::showReviewAlertWhenOpenTime(int opentime){
    UserDefault *ud = UserDefault::getInstance();
    int cu = ud->getIntegerForKey(LHOPENTIME, 0);
    cu ++;
    ud->setIntegerForKey(LHOPENTIME, cu);
    if (cu == opentime) {
        ThirdPartyHelper::showReviewAlert();
    }
}
Example #7
0
void BBGameDataManager::setGameOverData(int star, int leftTime)
{
    int themeId = m_themeId;
    int levelId = m_levelId + 1;
    
    UserDefault* ud = UserDefault::getInstance();
    // 更新星级
    __String *starkey = __String::createWithFormat("star_%d_%d", m_themeId, m_levelId);
    int curStar = ud->getIntegerForKey(starkey->getCString(), 0);
    if (curStar < star) {
        ud->setIntegerForKey(starkey->getCString(), star);
    }
    
    __String *bestkey = __String::createWithFormat("best_%d_%d", m_themeId, m_levelId);
    int bestTime = ud->getIntegerForKey(bestkey->getCString(), 0);
    if (bestTime == 0 || bestTime > leftTime) {
        ud->setIntegerForKey(bestkey->getCString(), leftTime);
    }
    
    // 更新关卡进度
    int themeIdFramCache = ud->getIntegerForKey("themeId", 1);
    int levelIdFramCache = ud->getIntegerForKey("levelId", 1);
    
    if (themeIdFramCache > themeId) {
        return;
    } else if (themeIdFramCache == themeId) {
        if (levelIdFramCache >= levelId) {
            return;
        }
    }
    
    if (levelId > 9) {
        // 进入下一个主题
        themeId++;
        levelId = 1;
    }
    
    ud->setIntegerForKey("themeId", themeId);
    ud->setIntegerForKey("levelId", levelId);
    
    ud->flush();

}
Example #8
0
void TitleScene::menuSceneTransition(cocos2d::Ref *pSender, bool newGame)
{
	const int maxNumMonsters = 3;
	const int maxNumEquip = 10;

	if (newGame)
	{
		if (Generic::checkSaveData())
		{
			auto nextScene = TutorialScene::createScene();
			auto pScene = TransitionFade::create(1.0f, nextScene);
			Director::getInstance()->replaceScene(pScene);
		}
		else
		{
			const int maxNumMonsters = 3;
			const int maxNumKnown = 31;

			//データをリセット
			//Set every SaveDataKey for Monsters and Equipment to 0 (eEmpty)
			UserDefault* def = UserDefault::getInstance();

			for (int i = 0; i < maxNumMonsters; i++)
			{
				def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonsterData01 + i].c_str(), n_MonsterData::eEmpty);

			}
			for (int i = 0; i < maxNumKnown; i++)
			{
				def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01 + i].c_str(), false);
			}
			def->setBoolForKey(SaveDataKey[n_DataKeyNum::eKnownData01].c_str(), true);

			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster1Exp].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster2Exp].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eMonster3Exp].c_str(), 0);

			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum01].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum02].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eWinNum03].c_str(), 0);

			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum01].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum02].c_str(), 0);
			def->setIntegerForKey(SaveDataKey[n_DataKeyNum::eLossNum03].c_str(), 0);

			def->flush();

			auto nextScene = MenuScene::createScene();
			auto pScene = TransitionFade::create(1.0f, nextScene);
			Director::getInstance()->replaceScene(pScene);
		}
		return;
	}
    
    auto nextScene = MenuScene::createScene();
    auto pScene = TransitionFade::create(0.5f, nextScene);
    Director::getInstance()->replaceScene(pScene);
}
/*--------------------------/
 Yesボタン生成
 /--------------------------*/
void StageSelectActionLayer::buttonYes(cocos2d::Layer* layer,Menu* menu,int tag){
    
    auto buttonYes = MenuItemImage::create("Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
                                           "Texture/GamePlay/GameScene/StageSelect/StageSelect_Yes.png",
                                           [ = ](Ref* sender)
                                           {
											   UserDefault* useDef = UserDefault::getInstance();
                                               useDef->setIntegerForKey("selectStage",tag);
											   useDef->setIntegerForKey("selectGimmick", tag);
                                               useDef->flush();
                                               
                                               auto nextScene = SceneCreator::createPhysicsScene(GameMainScene::create(), Vect(0, -9.8f), 5.0f);
                                               auto scene	= TransitionFade::create( 1.5f, nextScene, Color3B::BLACK );
                                               auto dir = Director::getInstance();
                                               dir->replaceScene(scene);
                                           });
    buttonYes->setPosition(400,300);
    buttonYes->setScale(1.2f);
    menu->addChild(buttonYes);
    
}
bool GameOverScene::init()	{
    if(!Layer::init())	{
        return false;
    }

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

    UserDefault* userScore = UserDefault::getInstance();
    if(score >= userScore->getIntegerForKey( "highscore" ))	{
        userScore->setIntegerForKey( "highscore", score );
    }
    userScore->flush();

    //create background for game over scene
    auto background = Sprite::create("FlappyResources/Background.png");
    background->setPosition(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2);
    this->addChild(background);

    //create retry item
    auto retry = MenuItemImage::create( "FlappyResources/Retry_Button.png", "FlappyResources/Retry_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToGameScene, this) );
    retry->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 );

    //create quit item
    auto quit = MenuItemImage::create( "FlappyResources/Menu_Button.png", "FlappyResources/Menu_Button_Clicked.png", CC_CALLBACK_1(GameOverScene::goToMainMenuScene, this) );
    quit->setPosition( origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2 - quit->getContentSize().height * 2);

    //create menu
    auto menu = Menu::create( retry, quit, NULL );
    menu->setPosition( Vec2(0, 0) );

    //create label score
    auto stringScore = __String::createWithFormat( "Your score: %d", score );
    auto labelScore = LabelTTF::create( stringScore->getCString(), "fonts/Marker Belt.ttf", 50 );
    labelScore->setPosition( origin.x + labelScore->getContentSize().width, origin.y + visibleSize.height / 2 + labelScore->getContentSize().height * 4 );
    labelScore->setFontFillColor( Color3B::YELLOW );

    //create label display best score
    auto stringBestScore = __String::createWithFormat( "High score: %d", userScore->getIntegerForKey( "highscore" ) );
    auto labelHighScore = LabelTTF::create( stringBestScore->getCString(), "fonts/Marker Belt.ttf", 50 );
    labelHighScore->setPosition( origin.x + labelScore->getContentSize().width + visibleSize.width / 2, origin.y + visibleSize.height / 2 + labelHighScore->getContentSize().height * 4);
    labelHighScore->setFontFillColor( Color3B::RED );

    this->addChild( menu );
    this->addChild( labelScore );
    this->addChild( labelHighScore );

    return true;
}
Example #11
0
void Flame::updateFlameCollectedCount()
{
    StatisticsData* totaldata = StatisticsData::getRunningLayer();
    UserDefault* userDefault = UserDefault::getInstance();
    int FlameWhiteCount = userDefault->getIntegerForKey("collectedWhite",0);
    int FlameBlueCount = userDefault->getIntegerForKey("collectedBlue", 0);
    int FlameVioltCount = userDefault->getIntegerForKey("collectedViolet",0);
    int FlameOrangeCount = userDefault->getIntegerForKey("collectedOrange",0);

    switch(_type){
        case Flame_White:
            FlameWhiteCount++;
            totaldata->totalFlame_White++;
            userDefault->setIntegerForKey("collectedWhite", FlameWhiteCount);
            break;
        case Flame_Blue:
            FlameBlueCount++;
            totaldata->totalFlame_Blue++;
            userDefault->setIntegerForKey("collectedBlue", FlameBlueCount);
            break;
        case Flame_Violet:
            FlameVioltCount++;
            totaldata->totalFlame_Violet++;
            userDefault->setIntegerForKey("collectedViolet", FlameVioltCount);
            break;
        case Flame_Orange:
            FlameOrangeCount++;
            totaldata->totalFlame_Orange++;
            userDefault->setIntegerForKey("collectedOrange", FlameOrangeCount);
            break;
            
        default:
            break;
    }

}
Example #12
0
//ハイスコア記録・表示
void GameScene::saveHighScore()
{
    UserDefault* userDefault = UserDefault::getInstance();
    
    //ハイスコアを取得する
    int oldHighScore = userDefault->getIntegerForKey(KEY_HIGHSCORE,0);
    if(oldHighScore < m_score)
    {
        //ハイスコアを保存する
        userDefault->setIntegerForKey(KEY_HIGHSCORE, m_score);
        userDefault->flush();
        
        //ハイスコアを表示する
        showHighScoreLabel();
    }
}
Example #13
0
void GeneralUtils::setControllerType(ControllerType controllerType)
{
    int controllerTypeInt = 0;
    
    if (controllerType == E_CONTROLLER_TOUCH)
    {
        controllerTypeInt = 1;
    }
    else if (controllerType == E_CONTROLLER_TILT)
    {
        controllerTypeInt = 2;
    }
    else
    {
        return;
    }
    
    UserDefault *ud = UserDefault::getInstance();
    
    ud->setIntegerForKey("control_type", controllerTypeInt);
    ud->flush();
}
Example #14
0
bool TitleScene::init() 
{
    if ( !Layer::init() ) 
	{
		return false; 
	}

	//glClearColor(255, 255, 255, 255);
    
    visibleSize = Director::getInstance()->getVisibleSize();
    m_Mag = Generic::getScreenMagnification(visibleSize);

	UserDefault* def = UserDefault::getInstance();
	def->setIntegerForKey("Battle", 0);

	displayBG();
	setSound();
    displayMenu(Generic::checkSaveData());

	this->scheduleUpdate();
    
    return true;
}
Example #15
0
// on "init" you need to initialize your instance
bool Result::init()
{
    //////////////////////////////
    //  super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();
    
    // add a label shows "Hello World"
    // create and initialize a label
    
    
    
    
    
    
    //タッチイベントの監視を開始
    auto listener = EventListenerTouchOneByOne::create();
    listener->onTouchBegan = CC_CALLBACK_2(Result::onTouchBegan, this);
    listener->onTouchCancelled= CC_CALLBACK_2(Result::onTouchCancelled,this);
    listener->onTouchMoved= CC_CALLBACK_2(Result::onTouchMoved,this);
    listener->onTouchEnded = CC_CALLBACK_2(Result::onTouchEnded, this);
    this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this);
    int dby=100;
    
    //スタートボタンを設置
    auto startButton = MenuItemImage::create(
                                             "BACKbutton.png",  // 通常状態の画像
                                             "BACKbutton.png",  // 押下状態の画像
                                             CC_CALLBACK_1(Result::pushStart, this)); // 押下時のアクション
    
    startButton->setPosition(Point(visibleSize.width/4,
                                 visibleSize.height/2-dby));
    
    //create menu, it's an autorelease object
    auto s_menu = Menu::create(startButton, NULL);
    s_menu->setPosition(Point::ZERO);
    this->addChild(s_menu, 2);
    
    //リトライボタンを設置
    auto retryButton = MenuItemImage::create(
                                             "RETRYbutton.png",  // 通常状態の画像
                                             "RETRYbutton.png",  // 押下状態の画像
                                             CC_CALLBACK_1(Result::pushRetry, this)); // 押下時のアクション
    
    retryButton->setPosition(Point(visibleSize.width*3/4 ,visibleSize.height/2-dby));
    //create menu, it's an autorelease object
    auto r_menu = Menu::create(retryButton, NULL);
    r_menu->setPosition(Point::ZERO);
    this->addChild(r_menu, 3);
    
    //this->particle = particle;
    
    
//    auto scoreLabel = Label::createWithSystemFont(cocos2d::StringUtils::toString(Stage:jugScore), "HiraKakuProN-W6", 48);
//    scoreLabel->setPosition(Point(visibleSize.width/2, visibleSize.height/2));
//    scoreLabel->setTag(20);
//    this->addChild(scoreLabel)
    

    UserDefault *userDef = UserDefault::getInstance();
    
    
    int highScore = userDef->getIntegerForKey("highScore", 0);
    //int型をセット
    int tempScore = userDef->getIntegerForKey("temp");
    
    //点数評価
    std::string honor;
    if(tempScore<=10)
        honor="GO How to Play";
    else if(10<tempScore&&tempScore<=30)
        honor="Do you play with a blindfold?";
    else if(30<tempScore&&tempScore<=50)
        honor="My grandma level";
    else if(50<tempScore&&tempScore<=80)
        honor="Otedamer";
    else if(80<tempScore&&tempScore<=100)
        honor="Pro otedamer";
    else if(100<tempScore&&tempScore<=130)
        honor="Cool Juggler";
    else if(130<tempScore&&tempScore<=150)
        honor="God juggler!!";
    else
        honor="God";
    std::string honor2="Your Rank : ";
    honor2.append(honor);
    auto honorLabel = Label::createWithSystemFont(honor2, "HiraKakuProN-W6", 40);
    honorLabel->setPosition(Point(visibleSize.width/2, visibleSize.height-70));
    this->addChild(honorLabel);

    
    CCLOG("highscore=%dtempScore=%d",highScore,tempScore);
    if(tempScore>highScore){
        userDef->setIntegerForKey("highScore", tempScore);
        auto scoreLabel = Label::createWithSystemFont(cocos2d::StringUtils::toString(tempScore), "HiraKakuProN-W6", 60);
        scoreLabel->setPosition(Point(visibleSize.width/2, visibleSize.height/2));
        auto high = Label::createWithSystemFont("HIGHSCORE!!!!!", "HiraKakuProN-W6", 48);
        high->setPosition(Point(visibleSize.width/2, visibleSize.height/2+250));
        this->addChild(high);
        this->addChild(scoreLabel);
        this->schedule( schedule_selector(Result::StageEffect), 1.8 );
    }else{
        auto scoreLabel = Label::createWithSystemFont(cocos2d::StringUtils::toString(tempScore), "HiraKakuProN-W6", 48);
        scoreLabel->setPosition(Point(visibleSize.width/2, visibleSize.height/2));
        this->addChild(scoreLabel);
        std::string hi="highScore : ";
        auto highScoreLabel = Label::createWithSystemFont(hi.append(cocos2d::StringUtils::toString(highScore)), "HiraKakuProN-W6", 24);
        highScoreLabel->setPosition(Point(visibleSize.width-140, visibleSize.height-100));
        this->addChild(highScoreLabel);
    }
    
    auto scoreButton = MenuItemImage::create(
                                             "sendScore.png",  // 通常状態の画像
                                             "sendScore.png",  // 押下状態の画像
                                             CC_CALLBACK_1(Result::pushScore, this)); // 押下時のアクション
    
    scoreButton->setPosition(Point(visibleSize.width*3/4+130 ,visibleSize.height/2+dby+80));
    //create menu, it's an autorelease object
    auto sc_menu = Menu::create(scoreButton, NULL);
    sc_menu->setPosition(Point::ZERO);
    this->addChild(sc_menu, 4);


    return true;
}
Example #16
0
bool GameOverLayer::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    //bg
    auto bg = TMXTiledMap::create("map/blue_bg.tmx");
    this->addChild(bg);
    
    //eff
    ParticleSystem *ps = ParticleSystemQuad::create("particle/light.plist");
    ps->setPosition(Vec2(visibleSize.width, visibleSize.height - 200) / 2);
    this->addChild(ps);
    
    auto top = Sprite::createWithSpriteFrameName("gameover.top.png");
    //top
    top->setAnchorPoint(Vec2(0,0));
    top->setPosition(Vec2(0, visibleSize.height - top->getContentSize().height));
    this->addChild(top);
    
    UserDefault *defaults = UserDefault::getInstance();
    int highScore = defaults->getIntegerForKey(HIGHSCORE_KEY);
    if (highScore < score) {
        highScore = score;
        defaults->setIntegerForKey(HIGHSCORE_KEY,highScore);
    }
    __String *text = __String::createWithFormat("%i points", highScore);
    auto lblHighScore = Label::createWithTTF(HellcUtils::getUTF8Char("lblHighScore"), "fonts/hanyi.ttf", 25);
    lblHighScore->setAnchorPoint(Vec2(0,0));
    lblHighScore->setPosition(Vec2(60, top->getPosition().y - 30));
    addChild(lblHighScore);
    
    auto lblScore = Label::createWithTTF(text->getCString(), "fonts/hanyi.ttf", 24);
    lblScore->setColor(Color3B(75,255,255));
    lblScore->setAnchorPoint(Vec2(0,0));
    lblScore->setPosition(lblHighScore->getPosition() - Vec2(0, 40));
    addChild(lblScore);
    
    auto text2 = Label::createWithTTF("Tap the Screen to Play", "fonts/hanyi.ttf", 24);
    text2->setAnchorPoint(Vec2(0,0));
    text2->setPosition(lblScore->getPosition() - Vec2(10, 45));
    addChild(text2);
    
    //touch
    auto listener = EventListenerTouchOneByOne::create();
    listener->setSwallowTouches(true);
    
    listener->onTouchBegan = [](Touch* touch, Event* event){
        Director::getInstance()->popScene();
        if (UserDefault::getInstance()->getBoolForKey(SOUND_KEY)) {
            SimpleAudioEngine::getInstance()->playEffect(sound_1);
        }
        return false;
    };
    
    //touch
    EventDispatcher* eventDispatcher = Director::getInstance()->getEventDispatcher();
    eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);
    
    return true;
}
Example #17
0
void Ajustes::guardarIdioma(int nIdioma){
    Configuracion::idioma = nIdioma;
    UserDefault *preferencias = UserDefault::getInstance();
    preferencias->setIntegerForKey("idioma", nIdioma);
    LanguageManager::getInstance()->recompilar();
}
Example #18
0
void Tutorial::onTouchEnded(Touch* touch, Event* event)
{

	UserDefault* userDefault = UserDefault::sharedUserDefault();
	int wk_flag = userDefault->getIntegerForKey(key_tutorialFlag, 1);

	if (wk_flag < 3) {


		Node* pArrow = this->getChildByTag(tagArrow);
		Node* pYubi;
		Node* pMsg;
		LabelTTF* arrowLabel;
		switch (scene_flag){
		case 0:
			//アニメーション停止
			pArrow->stopAllActions();
			pArrow->runAction(Show::create());
			pArrow->runAction(MoveTo::create(2, ccp(120.0, visibleSize.height * 0.80)));

			// 	メッセージ削除
			pMsg = this->getChildByTag(tagMsg);
			pMsg->removeFromParentAndCleanup(true);
			pMsg = this->getChildByTag(tagTap);
			pMsg->removeFromParentAndCleanup(true);
			pMsg = this->getChildByTag(tagTap2);
			pMsg->removeFromParentAndCleanup(true);

			//スワイプアニメーション追加
			pYubi = Sprite::create("yubi.png");
			pYubi->setPosition(Point(visibleSize.width-120, visibleSize.height * 0.80-200));
			pYubi->setRotation(120);
			pYubi->setTag(tagYubi);
			this->addChild(pYubi,2);
			pYubi->runAction(Sequence::create(MoveTo::create(1, ccp(120.0, visibleSize.height * 0.80-200)),MoveTo::create(0.7, ccp(120.0, visibleSize.height * 0.4)),NULL));

			scene_flag++;

			this->scheduleOnce(schedule_selector(Tutorial::msg2), 2);

			break;
		case 1:
			//アニメーションキャンセル
			this->unschedule(schedule_selector(Tutorial::msg2));

			//矢印を所定の位置へ移動
			pArrow->stopAllActions();
			pArrow->setPosition(Point(120.0, visibleSize.height * 0.80));

			//yubiを所定の位置へ移動
			pYubi  = this->getChildByTag(tagYubi);
			pYubi->stopAllActions();
			pYubi->setPosition(Point(120.0, visibleSize.height * 0.4));
			pYubi->runAction(RotateBy::create(0.5f, -90.0f));

			//メッセージ表示
			pMsg = Sprite::create("help_msg2.png");
			pMsg->setPosition(Point(280, visibleSize.height * 0.80-150));
			pMsg->setTag(tagMsg);
			this->addChild(pMsg,2);

			pMsg = Sprite::create("help_msg3.png");
			pMsg->setPosition(Point(visibleSize.width/2 , origin.y + 200));
			pMsg->setTag(tagTap2);
			this->addChild(pMsg,2);

			arrowLabel = LabelTTF::create("タップしてね", "Arial", 40);
			arrowLabel->setColor(ccc3(0, 0, 0));
			arrowLabel->setPosition(Point(visibleSize.width/2 , origin.y + 200));
			arrowLabel->setTag(tagTap);
			this->addChild(arrowLabel,3);
			arrowLabel->runAction(CCRepeatForever::create(Blink::create(5,7)));

			scene_flag++;

			break;
		case 2:
			if (wk_flag == 1) {
				Scene* gameScene = (Scene*)TitleScene::create();
				Director::getInstance()->replaceScene(gameScene);
			} else if (wk_flag == 2) {
				//相手レベル記録
				UserDefault* userDefault = UserDefault::sharedUserDefault();
				userDefault->setIntegerForKey(key_playEnemyLv, 1);

				// ゲーム画面の表示
				Scene* scene = HelloWorld::createScene();
				TransitionFlipX* tran = TransitionFlipX::create(0.2, scene);
				Director::sharedDirector()->replaceScene(tran);
			}
		}

	} else {
		if (wk_count > 3) {
		    Scene* scene = PowerUp::createScene();
		    TransitionFlipX* tran = TransitionFlipX::create(1, scene);
		    Director::sharedDirector()->replaceScene(tran);
		} else {
			wk_count = wk_count + 1;
			Sprite* pBG = Sprite::create(String::createWithFormat("help_%d.png", wk_count)->getCString());
		    pBG->setPosition(Point(visibleSize.width * 0.5, visibleSize.height * 0.5));
		    this->addChild(pBG);
		}
	}

}
Example #19
0
// on "init" you need to initialize your instance
bool GameOverScene::init()
{
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Vec2 origin = Director::getInstance()->getVisibleOrigin();


    auto backgroundSprite = Sprite::create( "BackGroundFlappy.png");
    auto backgroundSprite2 = Sprite::create("BackGroundFlappy.png");
    auto backgroundSprite3 = Sprite::create("BackGroundFlappy.png");
    auto groundSprite = Sprite::create("Ground.png");
    auto groundSprite2 = Sprite::create("Ground.png");
    auto groundSprite3 = Sprite::create("Ground.png");
    
    backgroundSprite->setScale(1.4);
    backgroundSprite2->setScale(1.4);
    backgroundSprite3->setScale(1.4);
    
    backgroundSprite->setPosition(visibleSize.width/2.2 + origin.x/2, visibleSize.height/2 - origin.y/2);
    groundSprite->setPosition(visibleSize.width/2.2, 0);
    
    backgroundSprite->setAnchorPoint(Vec2(0.5,0.4));
    backgroundSprite2->setAnchorPoint(Vec2(0.5,0.4));
    backgroundSprite3->setAnchorPoint(Vec2(0.5,0.4));
    
    auto sizeBack = backgroundSprite->getContentSize();

    backgroundSprite2->setPosition(backgroundSprite->getPositionX() + sizeBack.width/2, backgroundSprite->getPositionY());
    backgroundSprite3->setPosition(backgroundSprite2->getPositionX() + sizeBack.width/2, backgroundSprite->getPositionY());
    
    groundSprite->setScale(1.95);
    groundSprite2->setScale(1.95);
    groundSprite3->setScale(1.95);
    
    auto sizeGround = groundSprite->getContentSize();
    groundSprite->setAnchorPoint(Vec2(0.5, 0.4));
    groundSprite2->setAnchorPoint(Vec2(0.5, 0.4));
    groundSprite3->setAnchorPoint(Vec2(0.5, 0.4));
    
    groundSprite2->setPosition(groundSprite->getPositionX() + sizeGround.width/2, groundSprite->getPositionY());
    groundSprite3->setPosition(groundSprite2->getPositionX() + sizeGround.width/2, groundSprite->getPositionY());
    
    this->addChild( backgroundSprite);
    this->addChild( backgroundSprite2);
    this->addChild( backgroundSprite3);
    this->addChild(groundSprite);
    this->addChild(groundSprite2);
    this->addChild(groundSprite3);
    
    auto retryItem = MenuItemImage::create( "Restart.png", "Restart.png", CC_CALLBACK_1( GameOverScene::GoToGameScene, this ) );
    retryItem->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height / 4 * 3 ) );
    
    auto menu = Menu::create( retryItem, NULL );
    menu->setPosition( Point::ZERO );
    
    
    this->addChild( menu);
    
    UserDefault *def = UserDefault::getInstance( );
    
    auto highScore = def->getIntegerForKey( "HIGHSCORE FLAPPY", 0 );
    
    if ( score > highScore )
    {
        highScore = score;
        
        def->setIntegerForKey( "HIGHSCORE FLAPPY", highScore );
    }
    
    def->flush( );
    
    __String *tempScore = __String::createWithFormat( "%i", score );
    
    auto currentScore = Label::createWithTTF (tempScore->getCString( ), "fonts/FlappyFont.TTF", visibleSize.height * SCORE_FONT_SIZE );
    currentScore->setPosition( Point( visibleSize.width * 0.25 + origin.x, visibleSize.height / 2 + origin.y ) );
   currentScore->setColor( Color3B::BLACK );
    
    auto currentLabel = Label::createWithTTF("SCORE", "fonts/FlappyFont.TTF", visibleSize.height * SCORE_FONT_SIZE );
    currentLabel->setPosition( Point( visibleSize.width * 0.25 + origin.x, visibleSize.height / 1.7 + origin.y ) );
    currentLabel->setColor( Color3B::BLACK );
    currentLabel->setScale(0.9);
    
    this->addChild( currentScore );
    this->addChild( currentLabel );
    
    __String *tempHighScore = __String::createWithFormat( "%i", highScore );
    
    auto highScoreLabel = Label::createWithTTF( tempHighScore->getCString( ), "fonts/FlappyFont.TTF", visibleSize.height * SCORE_FONT_SIZE );
    
    highScoreLabel->setColor( Color3B::BLACK );
    highScoreLabel->setPosition( Point( visibleSize.width * 0.75 + origin.x, visibleSize.height / 2 + origin.y ) );

    auto bestLabel = Label::createWithTTF("BEST", "fonts/FlappyFont.TTF", visibleSize.height * SCORE_FONT_SIZE );
    bestLabel->setColor( Color3B::BLACK );
    bestLabel->setPosition( Point( visibleSize.width * 0.75 + origin.x, visibleSize.height / 1.7 + origin.y ) );
    bestLabel->setScale(0.9);
    
    this->addChild( highScoreLabel );
    this->addChild( bestLabel );
    return true;
}
Example #20
0
//?????????研究放在init和enter中的区别对于像score这样的可变动的量
void InGameLayer::setViews()
{
	
	//////////////////添加UFO、Pause Menu start///////////////
	auto bombSp = Sprite::createWithSpriteFrameName("bomb.png");
	auto itemBomb = MenuItemSprite::create(bombSp,bombSp,CC_CALLBACK_0(InGameLayer::MenuBombCallback,this));
	itemBomb->setPosition(VisibleRect::leftBottom()+Vec2(bombSp->getContentSize().width/2,bombSp->getContentSize().height/2));

	auto menu = Menu::create(itemBomb, nullptr);
	menu->setPosition(VisibleRect::leftBottom());
	menu->setTag(GameSceneNodeTagMenuBomb);
	menu->setVisible(false);
	addChild(menu);

	auto PauseSp1 = Sprite::createWithSpriteFrameName("game_pause_nor.png");
	auto PauseSp2 = Sprite::createWithSpriteFrameName("game_pause_nor-44.png");
	auto visibleSize = Director::getInstance()->getVisibleSize();
	auto itemPause = MenuItemSprite::create(PauseSp1,PauseSp2,CC_CALLBACK_0(InGameLayer::MenuPauseCallback,this));
	itemPause->setPosition(VisibleRect::leftTop()+Vec2(PauseSp1->getContentSize().width/2, - PauseSp1->getContentSize().height/2));

	auto menu2 = Menu::create(itemPause,nullptr);
	menu2->setPosition(VisibleRect::leftBottom());
	addChild(menu2);

	auto BombNumLabel = Label::createWithTTF("x0","fonts/hanyi.ttf",36);
	BombNumLabel->setPosition(VisibleRect::leftBottom()+Vec2(bombSp->getContentSize().width/2+60,bombSp->getContentSize().height/2));
	BombNumLabel->setTag(GameSceneNodeTagNumLabel);
	BombNumLabel->setVisible(false);
	addChild(BombNumLabel);

	this->schedule(SEL_SCHEDULE(&InGameLayer::createBombs),20.0f);

	///////////////////添加UFO、Pause Menu end///////////////////////////////

	scoreLabel = Label::createWithTTF("0","fonts/hanyi.ttf",45);
	scoreLabel->setPosition(VisibleRect::leftTop()+Vec2(itemPause->getContentSize().width*2, -scoreLabel->getContentSize().height));
	addChild(scoreLabel,1000);

	/////////////////最高分 start////////////////////////
	UserDefault *defaults = UserDefault::getInstance();
	int highScore = defaults->getIntegerForKey("highscore_key");    
	if (highScore < score) {
		highScore = score;
		defaults->setIntegerForKey("highscore_key", highScore);
	}
	__String *text = __String::createWithFormat("%i", highScore);
	auto lblHighScore = Label::createWithTTF(MyUtility::getUTF8Char("lblHighScore"), "fonts/hanyi.ttf", 45);

	lblHighScore->setAnchorPoint(Vec2(0,0));

	lblHighScore->setPosition(Vec2(VisibleRect::rightTop().x-2*lblHighScore->getContentSize().width ,scoreLabel->getPosition().y-15));

	addChild(lblHighScore);

	auto lblScoreOfHigh = Label::createWithTTF(text->getCString(), "fonts/hanyi.ttf", 45);
	//lblScoreOfHigh->setColor(Color3B(75,255,255));	
	lblScoreOfHigh->setAnchorPoint(Vec2(0,0));
	lblScoreOfHigh->setPosition(lblHighScore->getPosition() + Vec2(200, 0));
	lblScoreOfHigh->setTag(GameSceneNodelblHighScore);
	addChild(lblScoreOfHigh);
	//////////////////最高分 end/////////////////////////////

	hero = FlyPlane::create();
	hero->setPosition(Vec2(VisibleRect::center().x,120));//hero的contentsize为0,为什么
	hero->setIsAlive(true);
	hero->setTag(GameSceneNodeTagFighter);
	addChild(hero);
	m_Pos = hero->getPosition();
	addEvents();

	//注册 碰撞事件监听器
	contactListener = EventListenerPhysicsContact::create();
	contactListener->onContactBegin = [this](PhysicsContact& contact)
	{
		auto spriteA = contact.getShapeA()->getBody()->getNode();
		auto spriteB = contact.getShapeB()->getBody()->getNode();
		Node* enemy1 = nullptr;

		////////////////////////////检测 飞机与敌人的碰撞 start//////////////////////////////////
		//Dlog::showLog("A = %d  ------------ B = %d", spriteA->getTag(), spriteB->getTag());		
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeTagFighter && spriteB->getTag() == GameSceneNodeBatchTagEnemy)
		{
			enemy1 = spriteB;
		}
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeBatchTagEnemy && spriteB->getTag() == GameSceneNodeTagFighter)
		{
			enemy1 = spriteA;
		}
		if (enemy1 != nullptr) {//发生碰撞
			if(hero&&hero->getIsAlive())
			{
				this->EnemyAttackPlane();
			}
		
			//this->handleFighterCollidingWithEnemy((Enemy*)enemy1);
			return false;
		}
		/////////////////////////检测 飞机与敌人的碰撞 end/////////////////////////////////////

		////////////////////////////检测 炮弹与敌人的碰撞 start////////////////////////////////
		Node* enemy2 = nullptr;
		Node* bullet = nullptr;
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeBatchTagBullet && 
			spriteB->getTag() == GameSceneNodeBatchTagEnemy)
		{
			//不可见的炮弹不发生碰撞
			//if (!spriteA->isVisible())
			//	return false;
			//使得炮弹消失
			//spriteA->setVisible(false);
			bullet = spriteA/*->removeFromParentAndCleanup(true)*/;
			enemy2 = spriteB;
		}
		
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeBatchTagEnemy 
			&& spriteB->getTag() == GameSceneNodeBatchTagBullet)
		{
			//不可见的炮弹不发生碰撞
			//if (!spriteB->isVisible())
			//	return false;
			//使得炮弹消失
			//spriteB->setVisible(false);
			bullet = spriteB/*->removeFromParent()*/;
			enemy2 = spriteA;
		}
		if (enemy2 != nullptr) {//发生碰撞
			bullet->removeFromParent();
			this->bulletAttackEnemy((EnemyBase*)enemy2);
			//this->handleBulletCollidingWithEnemy((Enemy*)enemy2);
			return false;
		}
		/////////////////////////检测 炮弹与敌人的碰撞 end/////////////////////////////////////

		////////////////////////////检测 飞机与UFO2的碰撞 start//////////////////////////////////
		Dlog::showLog("A = %d  ------------ B = %d", spriteA->getTag(), spriteB->getTag());		
		Node* enemy3 = nullptr;
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeTagFighter && spriteB->getTag() == GameSceneNodeBatchTagBomb2)
		{
			enemy3 = spriteB;
		}
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeBatchTagBomb2 && spriteB->getTag() == GameSceneNodeTagFighter)
		{
			enemy3 = spriteA;
		}
		if (enemy3 != nullptr) {//发生碰撞
			SimpleAudioEngine::getInstance()->playEffect("sound/get_bomb.mp3");
			enemy3->setVisible(false);
			enemy3->removeFromParent();
			this->BombAttackPlane();
			//this->handleFighterCollidingWithEnemy((Enemy*)enemy1);
			return false;
		}
		/////////////////////////检测 飞机与UFO2的碰撞 end/////////////////////////////////////

		////////////////////////////检测 飞机与UFO1的碰撞 start//////////////////////////////////
		Dlog::showLog("A = %d  ------------ B = %d", spriteA->getTag(), spriteB->getTag());		
		Node* enemy4 = nullptr;
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeTagFighter && spriteB->getTag() == GameSceneNodeBatchTagBomb1)
		{
			enemy4 = spriteB;
		}
		if (spriteA&&spriteB&&spriteA->getTag() == GameSceneNodeBatchTagBomb1 && spriteB->getTag() == GameSceneNodeTagFighter)
		{
			enemy4 = spriteA;
		}
		if (enemy4 != nullptr) {//发生碰撞
			SimpleAudioEngine::getInstance()->playEffect("sound/get_double_laser.mp3");
			enemy4->setVisible(false);
			enemy4->removeFromParent();
			this->DoubleBulletsIsOn = true;
			this->scheduleOnce(schedule_selector(InGameLayer::updateDoubleBulletsIsOn),11.0f);
			//this->handleFighterCollidingWithEnemy((Enemy*)enemy1);
			return false;
		}
		/////////////////////////检测 飞机与UFO1的碰撞 end/////////////////////////////////////
		return false;
	};	

	EventDispatcher* eventDispatcher = Director::getInstance()->getEventDispatcher();
	eventDispatcher->addEventListenerWithFixedPriority(contactListener,1); 
	this->schedule(SEL_SCHEDULE(&InGameLayer::createEnemys),CCRANDOM_0_1()*0.25+0.36f);
	this->schedule(SEL_SCHEDULE(&InGameLayer::moveAllEnemys),0.08f);
	this->schedule(SEL_SCHEDULE(&InGameLayer::createbullets),0.2f);
	//this->schedule(SEL_SCHEDULE(&InGameLayer::moveAllbullets),0.016f);

	this->scheduleUpdate();	
}
Example #21
0
void MyContactListener::BeginContact(b2Contact* contact)
{
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    UserDefault *def = UserDefault::getInstance();
    int visibleWidth = visibleSize.width;
    int visibleHeight = visibleSize. height;
    int halfVisibleWidth = visibleSize.width / 2;
    int halfVisibleHeight = visibleSize.height / 2;
    float positionX, positionY;
    long whichBird;
    
    b2Body* bird;
    b2Body* border;
    b2Fixture* a = contact->GetFixtureA();
    b2Fixture* b = contact->GetFixtureB();
    
    //make sure only one of the fixtures was a sensor
    bool sensorA = a->IsSensor();
    bool sensorB = b->IsSensor();
    if ( ! (sensorA && sensorB) )
    {
        if(a->IsSensor()){
            bird = a->GetBody();
            border = b->GetBody();
            whichBird = (long)a->GetUserData();
        } else {
            border = a->GetBody();
            bird = b->GetBody();
            whichBird = (long)b->GetUserData();
        }
        Sprite* birdSprite = (Sprite*)bird->GetUserData();
        float birdX = birdSprite->getPositionX();
        float birdY = birdSprite->getPositionY();
        auto birdTag = birdSprite->getTag();
        long borderCheck = (long)border->GetUserData();
        
        auto blue1 = def->getIntegerForKey("blue1");
        auto blue2 = def->getIntegerForKey("blue2");
        auto blue3 = def->getIntegerForKey("blue3");
        auto velocity = def->getFloatForKey("velocity", 0);
        
        auto rotation = rand() % 46 + 1;
        
        bool top = false;
        
        if(borderCheck == 1 || borderCheck == 3)  // bottom and right
        {
            if(birdY > visibleHeight / 2){
                top = true;
                rotation = rand() % 26 + 1;
            }
        } else {
            rotation = rotation + 45;
            if(birdX > visibleWidth / 2)
                top = true;
        }
        
        auto angle = rotation * M_PI / 180;
        auto xPos = cos(angle) * (visibleWidth * 1.5);
        auto yPos = sin(angle) * (visibleWidth * 1.5);
        
        // Add missed bird and stop redirection if 3 collisions. GameOver if 3 misses in total
        if(((birdTag == 1 || birdTag == 4) && (borderCheck == 1 || borderCheck == 3)) || ((birdTag == 2 || birdTag == 8) && (borderCheck == 2 || borderCheck == 3)) || ((birdTag == 3 || birdTag == 5) && (borderCheck == 1 || borderCheck == 4)) || ((birdTag == 6 || birdTag == 7) && (borderCheck == 2 || borderCheck == 4)))
        {
            if(whichBird == 1)
            {
                auto round1_misses = def->getBoolForKey("bird1_missed", 0);
                int bird1_collisions = def->getIntegerForKey("bird1_collisions", 0);
                bird1_collisions++;
                def->setIntegerForKey("bird1_collisions", bird1_collisions);
                if(bird1_collisions >= 3 && !round1_misses) {
                    auto misses = def->getIntegerForKey("misses", 0);
                    misses++;
                    def->setIntegerForKey("misses", misses);
                    auto bird_count = def->getIntegerForKey("bird_count", 0);
                    bird_count++;
                    def->setIntegerForKey("bird_count", bird_count);
                    def->setBoolForKey("bird1_missed", 1);
                    Director::getInstance()->getEventDispatcher()->removeEventListenersForTarget(birdSprite);
                    return;
                } else {
                    if(bird1_collisions >= 3) {
                        return;
                    }
                }
            }
            if(whichBird == 2)
            {
                auto round2_misses = def->getBoolForKey("bird2_missed", 0);
                int bird2_collisions = def->getIntegerForKey("bird2_collisions", 0);
                bird2_collisions++;
                def->setIntegerForKey("bird2_collisions", bird2_collisions);
                if(bird2_collisions >= 3  && !round2_misses) {
                    auto misses = def->getIntegerForKey("misses", 0);
                    misses++;
                    def->setIntegerForKey("misses", misses);
                    auto bird_count = def->getIntegerForKey("bird_count", 0);
                    bird_count++;
                    def->setIntegerForKey("bird_count", bird_count);
                    def->setBoolForKey("bird2_missed", 1);
                    Director::getInstance()->getEventDispatcher()->removeEventListenersForTarget(birdSprite);
                    return;
                } else {
                    if(bird2_collisions >= 3) {
                        return;
                    }
                }
            }
            if(whichBird == 3)
            {
                auto round3_misses = def->getBoolForKey("bird3_missed", 0);
                int bird3_collisions = def->getIntegerForKey("bird3_collisions", 0);
                bird3_collisions++;
                def->setIntegerForKey("bird3_collisions", bird3_collisions);
                if(bird3_collisions >= 3 && !round3_misses) {
                    auto misses = def->getIntegerForKey("misses", 0);
                    misses++;
                    def->setIntegerForKey("misses", misses);
                    auto bird_count = def->getIntegerForKey("bird_count", 0);
                    bird_count++;
                    def->setIntegerForKey("bird_count", bird_count);
                    def->setBoolForKey("bird3_missed", 1);
                    Director::getInstance()->getEventDispatcher()->removeEventListenersForTarget(birdSprite);
                    return;
                } else {
                    if(bird3_collisions >= 3) {
                        return;
                    }
                }
            }
        }
        
        // Redirect Bird
        if((birdTag == 1 || birdTag == 4) && (borderCheck == 1 || borderCheck == 3))  // LeftTop || TopLeft -> bottom and right
        {
            if(borderCheck == 1)  // Bottom
            {
                if( birdX > halfVisibleWidth )
                {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_left.png");
                    } else {
                        birdSprite->setTexture("blue_left.png");
                    }
                    birdSprite->setTag(7);
                    birdSprite->setRotation(rotation);
                    positionX = -(birdX + xPos);
                    positionY = birdY + yPos;
                } else {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_right.png");
                    } else {
                        birdSprite->setTexture("blue_right.png");
                    }
                    birdSprite->setTag(8);
                    birdSprite->setRotation(-rotation);
                    positionX = birdX + xPos;
                    positionY = birdY + yPos;
                }
            } else {  // Right
                if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                    birdSprite->setTexture("bird_left.png");
                } else {
                    birdSprite->setTexture("blue_left.png");
                }
                if( birdY > halfVisibleHeight )
                {
                    birdSprite->setTag(5);
                    birdSprite->setRotation(-rotation);
                    positionX = -(birdX + xPos);
                    positionY = -(birdY + yPos);
                } else {
                    birdSprite->setTag(6);
                    birdSprite->setRotation(rotation);
                    positionX = -(birdX + xPos);
                    positionY = birdY + yPos;
                }
            }
        }
        if((birdTag == 2 || birdTag == 8) && (borderCheck == 2 || borderCheck == 3))  // LeftBottom || BottomLeft -> top and right
        {
            if(borderCheck == 2)  // Top
            {
                if( birdX > halfVisibleWidth )
                {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_left.png");
                    } else {
                        birdSprite->setTexture("blue_left.png");
                    }

                    birdSprite->setTag(3);
                    birdSprite->setRotation(-rotation);
                    positionX = -(birdX + xPos);
                    positionY = -(birdY + yPos);
                } else {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_right.png");
                    } else {
                        birdSprite->setTexture("blue_right.png");
                    }
                    birdSprite->setTag(4);
                    birdSprite->setRotation(rotation);
                    positionX = birdX + xPos;
                    positionY = -(birdY + yPos);
                }
            } else {  // Right
                if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                    birdSprite->setTexture("bird_left.png");
                } else {
                    birdSprite->setTexture("blue_left.png");
                }

                if( birdY > halfVisibleHeight )
                {
                    birdSprite->setTag(5);
                    birdSprite->setRotation(-rotation);
                    positionX = -(birdX + xPos);
                    positionY = -(birdY + yPos);
                } else {
                    birdSprite->setTag(6);
                    birdSprite->setRotation(rotation);
                    positionX = -(birdX + xPos);
                    positionY = birdY + yPos;
                }
            }
        }
        if((birdTag == 3 || birdTag == 5) && (borderCheck == 1 || borderCheck == 4))  // TopRight || RightTop -> bottom and left
        {
            if(borderCheck == 1)  // Bottom
            {
                if( birdX > halfVisibleWidth )
                {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_left.png");
                    } else {
                        birdSprite->setTexture("blue_left.png");
                    }

                    birdSprite->setTag(7);
                    birdSprite->setRotation(rotation);
                    positionX = -(birdX + xPos);
                    positionY = birdY + yPos;
                } else {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_right.png");
                    } else {
                        birdSprite->setTexture("blue_right.png");
                    }
                    birdSprite->setTag(8);
                    birdSprite->setRotation(-rotation);
                    positionX = birdX + xPos;
                    positionY = birdY + yPos;
                }
            } else {  // Left
                if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                    birdSprite->setTexture("bird_right.png");
                } else {
                    birdSprite->setTexture("blue_right.png");
                }
                if( birdY > halfVisibleHeight )
                {
                    birdSprite->setTag(1);
                    birdSprite->setRotation(rotation);
                    positionX = birdX + xPos;
                    positionY = -(birdY + yPos);
                } else {
                    birdSprite->setTag(2);
                    birdSprite->setRotation(-rotation);
                    positionX = birdX + xPos;
                    positionY = birdY + yPos;
                }
            }
        }
        if((birdTag == 6 || birdTag == 7) && (borderCheck == 2 || borderCheck == 4))  // RightBottom || BottomRight -> top and left
        {
            if(borderCheck == 2)  // Top
            {
                if( birdX > halfVisibleWidth )
                {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_left.png");
                    } else {
                        birdSprite->setTexture("blue_left.png");
                    }

                    birdSprite->setTag(3);
                    birdSprite->setRotation(-rotation);
                    positionX = -(birdX + xPos);
                    positionY = -(birdY + yPos);
                } else {
                    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                        birdSprite->setTexture("bird_right.png");
                    } else {
                        birdSprite->setTexture("blue_right.png");
                    }
                    birdSprite->setTag(4);
                    birdSprite->setRotation(rotation);
                    positionX = birdX + xPos;
                    positionY = -(birdY + yPos);
                }
            } else {  // Left
                if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                    birdSprite->setTexture("bird_right.png");
                } else {
                    birdSprite->setTexture("blue_right.png");
                }
                if( birdY > halfVisibleHeight )
                {
                    birdSprite->setTag(1);
                    birdSprite->setRotation(rotation);
                    positionX = birdX + xPos;
                    positionY = -(birdY + yPos);
                } else {
                    birdSprite->setTag(2);
                    birdSprite->setRotation(-rotation);
                    positionX = birdX + xPos;
                    positionY = birdY + yPos;
                }
            }
        }
        
        if(((birdTag == 1 || birdTag == 4) && (borderCheck == 1 || borderCheck == 3)) || ((birdTag == 2 || birdTag == 8) && (borderCheck == 2 || borderCheck == 3)) || ((birdTag == 3 || birdTag == 5) && (borderCheck == 1 || borderCheck == 4)) || ((birdTag == 6 || birdTag == 7) && (borderCheck == 2 || borderCheck == 4)))
        {
            bird->SetLinearVelocity( b2Vec2(positionX * velocity / PTM_RATIO, positionY * velocity / PTM_RATIO));
        }
        
        def->flush();
        
        contact->SetEnabled(false);
    }
}
Example #22
0
void InGameLayer::bulletAttackEnemy(EnemyBase*Ene)
{

	/*Vector<bullet*>::iterator iter2=bulletVec.begin();
	for(int i=EneVec.size()-1;i>=0;--i)
	{
	auto Ene=EneVec.at(i);
	for(int j=bulletVec.size()-1;j>=0;--j)//如果就j!=0会出现越界
	{
	auto bult=bulletVec.at(j);
	if(bult->testhurt(Ene))
	{

	bult->removeFromParent();
	bulletVec.erase(j);*/
	Ene->hurt(1);
	if(Ene->getIsBlowUp())
	{
		
		switch (Ene->getEnemyType())
		{
		case 0:
			{
				SimpleAudioEngine::getInstance()->playEffect("sound/enemy3_down.mp3");
				score += 50;
				break;}
		case 1:
			{
				SimpleAudioEngine::getInstance()->playEffect("sound/enemy1_down.mp3");
				score += 10;
				break;
			}
		case 2:
			{
				SimpleAudioEngine::getInstance()->playEffect("sound/enemy2_down.mp3");
				score += 20;
				break;
			}
		default:
			break;
		}
		scoreLabel->setString(__String::createWithFormat("%d",score)->getCString());
		EneVec.eraseObject(Ene);

		UserDefault *defaults = UserDefault::getInstance();
		int highScore = defaults->getIntegerForKey("highscore_key");    
		if (highScore < score) {
			highScore = score;
			defaults->setIntegerForKey("highscore_key", highScore);
		}
		__String *text = __String::createWithFormat("%i", highScore);

		auto lblScoreOfHigh = static_cast<Label*>(this->getChildByTag(GameSceneNodelblHighScore));
		lblScoreOfHigh->setString(text->getCString());
	
	}
	/*
	break;
	}
	}
	//正序删与倒序删1  2  3  4
	}
	}*/

}
Example #23
0
void BBGameDataManager::addCanUseTipsCount()
{
    UserDefault* ud = UserDefault::getInstance();
    ud->setIntegerForKey("fingerLeftTimes", 3);
    ud->flush();
}
Example #24
0
Bird::Bird( cocos2d::Layer *layer, b2World *world )
{
    visibleSize = Director::getInstance()->getVisibleSize();
    int visibleWidth = visibleSize.width;
    int visibleHeight = visibleSize.height;
    float positionX, positionY;
    long whichBird;
    
    auto region = rand() % 4 + 1;
    
    // Adjust random region based on previous regions
    UserDefault *def = UserDefault::getInstance();
    auto velocity = def->getFloatForKey("velocity", 0);
    auto power3_activated = def->getIntegerForKey("power3_activated",0);
    auto bird1_region = def->getIntegerForKey("bird1_region", 0);
    auto bird2_region = def->getIntegerForKey("bird2_region", 0);
    auto blue1 = def->getIntegerForKey("blue1");
    auto blue2 = def->getIntegerForKey("blue2");
    auto blue3 = def->getIntegerForKey("blue3");
    
    if(bird1_region == 0) {
        def->setIntegerForKey("bird1_region", region);
        whichBird = 1;
    } else {
        if(bird2_region == 0){
            while(region == bird1_region){
                 region = rand() % 4 + 1;
            }
            def->setIntegerForKey("bird2_region", region);
            whichBird = 2;
        } else {
            while(region == bird1_region || region == bird2_region){
                region = rand() % 4 + 1;
            }
            whichBird = 3;
        }
    }
    
    if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
        bird = Sprite::create("bird_left.png");
    } else {
        bird = Sprite::create("blue_left.png");
    }
    
    def->flush();
    
    auto rotation = rand() % 46 + 1;
    
    int halfBird = bird->getContentSize().width / 2;
    auto birdY = rand() % (visibleHeight - halfBird) + halfBird;
    auto birdX = rand() % (visibleWidth - halfBird) + halfBird;
    bool top = false;
    
    if(region == 1 || region == 3)
    {
        if(birdY > visibleHeight / 2){
            top = true;
            rotation = rand() % 26 + 1;
        }
    } else {
        rotation = rotation + 45;
        if(birdX > visibleWidth / 2)
            top = true;
    }

    auto angle = rotation * M_PI / 180;
    auto xPos = cos(angle) * (visibleWidth * 1.5);
    auto yPos = sin(angle) * (visibleWidth * 1.5);
    
    // Set the bird's position based on region
    if(region == 1)  // Left
    {
        bird->setPosition(Point(-halfBird,birdY));
        if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
            bird->setTexture("bird_right.png");
        } else {
            bird->setTexture("blue_right.png");
        }
        if(top)  // Above middle of screen
        {
            bird->setRotation(rotation);
            bird->setTag(1);
            positionX = bird->getPositionX() + xPos;
            positionY = -(bird->getPositionY() + yPos);
        }
        else   // Below middle of screen
        {
            bird->setRotation(-rotation);
            bird->setTag(2);
            positionX = bird->getPositionX() + xPos;
            positionY = bird->getPositionY() + yPos;
        }
    }
    if(region == 2) // Top
    {
        bird->setPosition(Point(birdX, visibleHeight + halfBird));
        if(top)  // Past middle of screen on x axis
        {
            bird->setRotation(-rotation);
            bird->setTag(3);
            positionX = -(bird->getPositionX() + xPos);
            positionY = -(bird->getPositionY() + yPos);
        }
        else   // Before middle of screen on x axis
        {
            bird->setTag(4);
            if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                bird->setTexture("bird_right.png");
            } else {
                bird->setTexture("blue_right.png");
            }
            bird->setRotation(rotation);
            positionX = bird->getPositionX() + xPos;
            positionY = -(bird->getPositionY() + yPos);
        }
    }
    if(region == 3)  // Right
    {
        bird->setPosition(Point(visibleWidth + halfBird, birdY));
        if(top)  // Above middle of screen
        {
            bird->setRotation(-rotation);
            bird->setTag(5);
            positionX = -(bird->getPositionX() + xPos);
            positionY = -(bird->getPositionY() + yPos);
        }
        else   // Below middle of screen
        {
            bird->setRotation(rotation);
            bird->setTag(6);
            positionX = -(bird->getPositionX() + xPos);
            positionY = bird->getPositionY() + yPos;
        }
    }
    if(region == 4)  // Bottom
    {
        bird->setPosition(Point(birdX, -halfBird));
        if(top)  // Past middle of screen on x axis
        {
            bird->setRotation(rotation);
            bird->setTag(7);
            positionX = -(bird->getPositionX() + xPos);
            positionY = bird->getPositionY() + yPos;
        }
        else   // Before middle of screen on x axis
        {
            if((whichBird == 1 && !blue1) || (whichBird == 2 && !blue2) || (whichBird == 3 && !blue3)) {
                bird->setTexture("bird_right.png");
            } else {
                bird->setTexture("blue_right.png");
            }
            bird->setRotation(-rotation);
            bird->setTag(8);
            positionX = bird->getPositionX() + xPos;
            positionY = bird->getPositionY() + yPos;
        }
    }
    // Create ball body
    b2BodyDef ballBodyDef;
    ballBodyDef.type = b2_dynamicBody;
    ballBodyDef.userData = bird;
    ballBodyDef.position.Set(bird->getPositionX() / PTM_RATIO,bird->getPositionY() / PTM_RATIO);
    b2Body *ballBody = world->CreateBody(&ballBodyDef);
    
    // Create circle shape
    b2CircleShape circle;
    circle.m_radius = (bird->getContentSize().height / 2) / PTM_RATIO;
    
    // Create shape definition and add body
    b2FixtureDef ballShapeDef;
    ballShapeDef.shape = &circle;
    ballShapeDef.density = 1.0f;
    ballShapeDef.friction = 0.f;
    ballShapeDef.restitution = 0.f;
    ballShapeDef.isSensor = true;
    ballShapeDef.filter.categoryBits = BIRD_COLLISION_BITMASK;
    ballShapeDef.filter.maskBits = BIRD_COLLISION_BITMASK;
    ballShapeDef.userData = (void*) whichBird;
    ballBody->SetLinearVelocity( b2Vec2(positionX * velocity / PTM_RATIO, positionY * velocity / PTM_RATIO));
    ballBody->CreateFixture(&ballShapeDef);
    
    if(!power3_activated){
        auto tmpScale = bird->getScale();
        //tmpScale = tmpScale / 1.5;
        bird->setScale(tmpScale);
    } else {
        bird->setScale(1.5);
    }
    
    layer->addChild(bird, 100);
    
    //setup touch listener
    auto touchListener = EventListenerTouchOneByOne::create();
    touchListener->setSwallowTouches( true );
    touchListener->onTouchBegan = CC_CALLBACK_2( Bird::onTouchBegan, this );
    Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(touchListener, bird);
}