Example #1
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();
}
Example #2
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);
}
Example #3
0
void SettingLayer::menuSoundToggleCallback(Ref* pSender)
{
	UserDefault *defaults  = UserDefault::getInstance();
	if (defaults->getBoolForKey(SOUND_KEY)) {
		defaults->setBoolForKey(SOUND_KEY, false);
	} else {
		defaults->setBoolForKey(SOUND_KEY, true);
		SimpleAudioEngine::getInstance()->playEffect(sound_1);
	}
}
Example #4
0
void SettingLayer::menuMusicToggleCallback(Ref* pSender)
{
	UserDefault *defaults  = UserDefault::getInstance();
	if (defaults->getBoolForKey(MUSIC_KEY)) {
		defaults->setBoolForKey(MUSIC_KEY, false);
		SimpleAudioEngine::getInstance()->stopBackgroundMusic();
	} else {
		defaults->setBoolForKey(MUSIC_KEY, true);
		SimpleAudioEngine::getInstance()->playBackgroundMusic(bg_music_2, true);
	}
}
Example #5
0
void Developer::menuSoundCallback( Ref *pSender )
{
	auto soundToggleMenuItem = (MenuItemToggle*)pSender;   
  
    UserDefault *defaults  = UserDefault::getInstance();  
	if (defaults->getBoolForKey(SOUND_KEY)) {                                      
        defaults->setBoolForKey(SOUND_KEY, false);  
    } 
	else {  
        defaults->setBoolForKey(SOUND_KEY, true);   
    }
}
Example #6
0
void Developer::menuMusicCallback( Ref *pSender )
{
	auto musicToggleMenuItem = (MenuItemToggle*)pSender;   
  
    UserDefault *defaults  = UserDefault::getInstance();  
    if (defaults->getBoolForKey(MUSIC_KEY)) {                                      
        defaults->setBoolForKey(MUSIC_KEY, false);  
        SimpleAudioEngine::getInstance()->stopBackgroundMusic();  
    } 
	else {  
        defaults->setBoolForKey(MUSIC_KEY, true);  
        SimpleAudioEngine::getInstance()->playBackgroundMusic("music_mainScene.wav");  
    }                                          
}
Example #7
0
void SettingsDialog::onPressMusic(cocos2d::Ref *sender, cocos2d::extension::Control::EventType pControlEvent)
{
	if (pControlEvent == Control::EventType::TOUCH_UP_INSIDE)
	{
        UserDefault *ud = UserDefault::getInstance();
        bool value = ud->getBoolForKey("music_enabled", true);
        ud->setBoolForKey("music_enabled", !value);
        
        if (value)
        {
            _checkBoxMusic->removeAllChildren();
            CocosDenshion::SimpleAudioEngine::getInstance()->stopBackgroundMusic(false);
        }
        else
        {
            Label *l = Label::create();
            l->setString("X");
            l->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
            
            _checkBoxMusic->addChild(l);

            CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("playing.mp3", true);
        }
        
        ud->flush();
	}
}
void UserDefaultManager::setDefault()
{
    
    UserDefault *userdefault = UserDefault::getInstance();
    if (!userdefault->getBoolForKey("isSetUp")) {
        userdefault->setBoolForKey("isSetUp", true);
        setIntegerForKey(DiamondCount, 10);
        setIntegerForKey(QuestionCount, 0);
        setIntegerForKey(StarCount, 0);
        setIntegerForKey(RecieveDiamond, 0);
        setIntegerForKey(StarCount, 0);
        setBoolForKey(kIsRemoveAds, false);
        setIntegerForKey(kTotalNum, 0);
        setBoolForKey(kFirstTime, true);
        time_t t = time(0);
        tm * now = localtime(&t);
        __String* timeString = __String::createWithFormat("%d年%d月%d日", now->tm_year, now->tm_mon, now->tm_mday-1);
        log("%d年%d月%d日", now->tm_year, now->tm_mon, now->tm_mday);
        setStringForKey(kLoginTime, timeString->getCString());
        setIntegerForKey(kLastCount, 10);
        setStringForKey(kRecordeTime1, timeString->getCString());
        setIntegerForKey(kViewState, 0);
    }
}
Example #9
0
void SettingsDialog::onPressSound(cocos2d::Ref *sender, cocos2d::extension::Control::EventType pControlEvent)
{
	if (pControlEvent == Control::EventType::TOUCH_UP_INSIDE)
    {
        UserDefault *ud = UserDefault::getInstance();
        bool value = ud->getBoolForKey("sound_enabled", true);
        ud->setBoolForKey("sound_enabled", !value);
        
        if (value)
        {
            _checkBoxSound->removeAllChildren();
        }
        else
        {
            Label *l = Label::create();
            l->setString("X");
            l->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
            
            _checkBoxSound->addChild(l);
        }
        
        ud->flush();
	}
}
void Controller::setVibrate(bool set)
{
    UserDefault * def = UserDefault::getInstance();
    def->setBoolForKey(SETTINGS_VIBRATE, set);
    if(set) Device::vibrate(Definitions::TIME_VIBRATION_ENABLED);
}
Example #11
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);
    }
}