Ejemplo n.º 1
0
bool GameOver::init() {
    
    if(!LayerColor::initWithColor(MENU_BACKGROUND_COLOR)) {
        return false;
    }
    
    gameMode = static_cast<GameMode>(UserDefault::getInstance()->getIntegerForKey("mode", GameMode::ARCADE));
    
    switch (gameMode) {
        case GameMode::ARCADE:
            addChild(sprite("ArcadeMode", Point(VisibleRect::top().x, VisibleRect::top().y - 200)));
            break;
            
        case GameMode::TIME_ATTACK:
            addChild(sprite("TimeAttackMode", Point(VisibleRect::top().x, VisibleRect::top().y - 200)));
            break;
            
        default:
            addChild(sprite("ZenMode", Point(VisibleRect::top().x, VisibleRect::top().y - 200)));
    }
    
    if(UserDefault::getInstance()->getBoolForKey(IS_WIN_KEY)) {
        showWinScreen();
    } else {
        playSoundEffect("Fail");
        label("FAILED")->size(MENU_FONT_SIZE * 3)->color(TIME_ATTACK_TEXT_COLOR)->position(VisibleRect::center())->addTo(this);
    }
    
    auto homeButton = MenuItemSprite::create(sprite("HomeButtonNormal"), sprite("HomeButtonPressed"), [=] (Ref* sender) {
        playSoundEffect("Click");
        Director::getInstance()->replaceScene(TransitionSlideInL::create(SCENE_TRANSITION_TIME, MainMenu::createScene()));
    });
    homeButton->setPosition(Point(202, 1920 - 1600));

    auto retryButton = MenuItemSprite::create(sprite("RetryButtonNormal"), sprite("RetryButtonPressed"), [=] (Ref* sender) {
        playSoundEffect("Click");
        Director::getInstance()->replaceScene(TransitionSlideInL::create(SCENE_TRANSITION_TIME, CountDown::createScene()));
    });
    retryButton->setPosition(Point(545, 1920 - 1600));
    
#if(CC_TARGET_PLATFORM != CC_PLATFORM_IOS)

    auto shareButton = MenuItemSprite::create(sprite("ShareButtonNormal"), sprite("ShareButtonPressed"), [=] (Ref*) {
        playSoundEffect("Click");
        NativeUtils::share();
    });
    shareButton->setPosition(Point(886, 1920 - 1600));
    
    auto menu = Menu::create(homeButton, retryButton, shareButton, NULL);
    menu->setPosition(Point::ZERO);
    addChild(menu);
#else
    auto menu = Menu::create(homeButton, retryButton, NULL);
    menu->setPosition(Point::ZERO);
    addChild(menu);
#endif
    return true;
}
Ejemplo n.º 2
0
void PongApp::purchaseFlowFinished(const char *productId) {
    engine->setUpdateAndPauseState(false, false);
    currentMenu->click(0);
    playSoundEffect( sampleMenuTick, 1.0f );

    (void*)productId;
    //qDebug() << "purchaseFlowFinished" << productId;
}
Ejemplo n.º 3
0
void Game::onSwitchBonusPressed(CCObject* sender) {
	if (activeBonus) {
		return;
	}
	playSoundEffect("ButtonClick");
	swapRemaining--;
	activeBonus = SwitchDotBonus::create(inventoryDot, bonusLayer, board, this);
	activeBonus->start();
	disableIfNoBonusRemaining(swapRemaining, sender);
}
Ejemplo n.º 4
0
void Game::onRemoveBonusPressed(CCObject* sender) {
	if (activeBonus) {
		return;
	}
	playSoundEffect("ButtonClick");
	removeRemaining--;
	activeBonus = RemoveDotBonus::create(bonusLayer, board, this);
	activeBonus->start();
	updateBonusLabel(removeBonusCountLabel, removeRemaining);
	disableIfNoBonusRemaining(removeRemaining, sender);
}
Ejemplo n.º 5
0
//! use this item
bool CGameNodeItem::use()
{
	if (m_ParentInventory)
	{
		IGameManager::getSingleton().onUseItem(m_ParentInventory->getOwner(), this);

		playSoundEffect(ITEM_SOUND_USE);

		return true;
	}

	return false;	
}
Ejemplo n.º 6
0
//! take this item to inventory
void CGameNodeItem::collectToInventory(IGameInventory& inventory)
{
	inventory.addItem(this);

	m_SceneNode->setParent(inventory.getOwner()->getSceneNode());
	m_SceneNode->setVisible(false);		

	IGameManager::getSingleton().onCollectItem(inventory.getOwner(), this);

	playSoundEffect(ITEM_SOUND_COLLECT);			

	use();
}
Ejemplo n.º 7
0
void Music::loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished) {
	stopSoundEffect();

	Common::File *file = _vm->_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F'));
	if (!file)
		return;

	_vm->_anim->_doBlack = false;

	uint32 magicBytes = file->readUint32LE();
	if (magicBytes != 1219009121) {
		warning("readSound: Bad signature, skipping");
		return;
	}
	uint32 soundTag = file->readUint32LE();
	uint32 soundSize = file->readUint32LE();

	if (soundTag != 0)
		return;

	file->skip(soundSize);	// skip the header

	while (soundTag != 65535) {
		_vm->updateEvents();
		soundTag = file->readUint32LE();
		soundSize = file->readUint32LE() - 8;

		if ((soundTag == 30) || (soundTag == 31)) {
			if (waitTillFinished) {
				while (isSoundEffectActive()) {
					_vm->updateEvents();
					_vm->waitTOF();
				}
			}

			file->skip(4);

			uint16 sampleRate = file->readUint16LE();
			file->skip(2);
			playSoundEffect(sampleRate, soundSize, loop, file);
		} else if (soundTag == 65535) {
			if (waitTillFinished) {
				while (isSoundEffectActive()) {
					_vm->updateEvents();
					_vm->waitTOF();
				}
			}
		} else
			file->skip(soundSize);
	}
}
Ejemplo n.º 8
0
//! throw this item from inventory
void CGameNodeItem::throwFromInventory()
{
	if (m_ParentInventory)
	{
		m_ParentInventory->removeObject(this);

		m_SceneNode->setParent(m_ParentInventory->getOwner()->getSceneNode()->getParent());
		m_SceneNode->setVisible(true);			

		IGameManager::getSingleton().onThrowItem(m_ParentInventory->getOwner(), this);

		playSoundEffect(ITEM_SOUND_THROW);
	}
}
Ejemplo n.º 9
0
bool TimeAttackHUD::init() {
    std::string name = "TimeAttack";
    auto backgroundSprite = sprite(Formatter::toString("%sBackground", name.c_str()));
    addChild(backgroundSprite);
    setContentSize(backgroundSprite->getContentSize());
    backgroundSprite->setPosition(getContentSize().width * getAnchorPoint().x,
                                  getContentSize().height * getAnchorPoint().y);
    auto labelPosition = Point(getContentSize().width * getAnchorPoint().x + 250,
                               getContentSize().height * getAnchorPoint().y + 10);
    
    timerLabel = label("0.000")->position(labelPosition)->color(SCORE_COLOR)->addTo(this);
    
    auto pauseNormalSprite = sprite(Formatter::toString("%sPauseButtonNormal", name.c_str()));
    auto pausePressedSprite = sprite(Formatter::toString("%sPauseButtonPressed", name.c_str()));
    
    auto pauseButton = MenuItemSprite::create(pauseNormalSprite, pausePressedSprite, [=](Ref* sender) {
        playSoundEffect("Click");
        stopTimer();
        EventCustom event("PauseGame");
        _eventDispatcher->dispatchEvent(&event);
    });
    pauseButton->setPosition(Point(labelPosition.x + 220, labelPosition.y));
    auto menu = Menu::create(pauseButton, NULL);
    menu->setPosition(Point::ZERO);
    addChild(menu);
    
    startTimer();
    
    _eventDispatcher->addCustomEventListener("ResumeGame", [=](EventCustom* e) {
        startTimer();
    });
    
    _eventDispatcher->addCustomEventListener("PauseGame", [=](EventCustom* e) {
        stopTimer();
    });
    
    _eventDispatcher->addCustomEventListener("GameWin", [=](EventCustom* e) {
        pauseButton->setEnabled(false);
        stopTimer();
    });
    
    _eventDispatcher->addCustomEventListener("GameLose", [=] (EventCustom* e){
        stopTimer();
    });
    
    return true;
}
Ejemplo n.º 10
0
void Music::readSound(bool waitTillFinished, bool loop, Common::File *file) {
	uint32 magicBytes = file->readUint32LE();
	if (magicBytes != 1219009121) {
		warning("readSound: Bad signature, skipping");
		return;
	}
	uint32 soundTag = file->readUint32LE();
	uint32 soundSize = file->readUint32LE();

	if (soundTag == 0)
		file->skip(soundSize);	// skip the header
	else
		return;

	while (soundTag != 65535) {
		_vm->updateEvents();
		soundTag = file->readUint32LE();
		soundSize = file->readUint32LE() - 8;

		if ((soundTag == 30) || (soundTag == 31)) {
			if (waitTillFinished) {
				while (isSoundEffectActive()) {
					_vm->updateEvents();
					_vm->waitTOF();
				}
			}

			file->skip(4);

			uint16 sampleRate = file->readUint16LE();
			file->skip(2);
			playSoundEffect(sampleRate, soundSize, loop, file);
		} else if (soundTag == 65535) {
			if (waitTillFinished) {
				while (isSoundEffectActive()) {
					_vm->updateEvents();
					_vm->waitTOF();
				}
			}
		} else
			file->skip(soundSize);
	}
}
Ejemplo n.º 11
0
//! 
bool CGameNodeButton::activate(IGameNode* activator)
{
	if (State == EBS_UNPUSHED)
	{
		m_Activated = true;						

		State = EBS_PUSHING;

		dyn::IDynamicObject *dynobj = getDynamicObject();

		if (dynobj)
		{
			dyn::SDynamicObjectParams Button_dynparams = dynobj->getParameters();
										
			Button_dynparams.DynamicConstraints = DynamicConstraints;

			dynobj->setParameters(Button_dynparams);
		}

		IGameNode *activator = this;

		game::IGameTasksManager &gtmgr = GAME_TASK_MANAGER;

		for (u32 i=0; i<m_TargetNodes.size(); i++)
		{
			// registering task (node activation)

			gtmgr.registerGameTask( new game::SGameTaskActivate(activator, m_TargetNodes[i]) ); 
		}

		//stopSoundEffect(BUTTON_DEACTIVATED_SOUND);
		playSoundEffect(BUTTON_ACTIVATED_SOUND);

		return true;
	}

	return false;
}
Ejemplo n.º 12
0
bool MainMenu::init() {
    if(!LayerColor::initWithColor(MENU_BACKGROUND_COLOR)) {
        return false;
    }
    
    auto titleFinalPosition = Point(VisibleRect::top().x, 1920 - 202);
    auto titleSprite = sprite("Title", Point(titleFinalPosition.x, titleFinalPosition.y + 300));
    
    addChild(titleSprite);
    
    titleSprite->runAction(EaseSineOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, titleFinalPosition)));
    
    auto menuBackground = sprite("MenuBackground", Point(VisibleRect::center().x, 1920 - 966));
    menuBackground->setScale(1.0f, 0.1);
    menuBackground->runAction(ScaleTo::create(DEFAULT_ANIMATION_TIME, 1.0f));
    addChild(menuBackground);

    auto arcadeButtonFinalPosition = Point(335, 1288);
    
    auto arcadeButton = MenuItemSprite::create(sprite("ArcadeButtonNormal"), sprite("ArcadeButtonPressed"), [=] (Ref* sender) {
        auto userDefault = UserDefault::getInstance();
        userDefault->setIntegerForKey("mode", GameMode::ARCADE);
        onPlayPress(sender);
    });
    arcadeButton->setPosition(arcadeButtonFinalPosition.x, arcadeButtonFinalPosition.y + 2000);
    arcadeButton->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME), EaseBounceOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, arcadeButtonFinalPosition)), CallFunc::create([=](){
        arcadeButton->runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4), RotateTo::create(DEFAULT_ANIMATION_TIME / 2, TILE_ROTATION_DEGREE), RotateTo::create(DEFAULT_ANIMATION_TIME, -TILE_ROTATION_DEGREE),RotateTo::create(DEFAULT_ANIMATION_TIME / 2, 0.0f),NULL)));
    }), NULL) );
    
    auto timeAttackButtonFinalPosition = Point(788, 1920 - 932);
    auto timeAttackButton = MenuItemSprite::create(sprite("TimeAttackButtonNormal"), sprite("TimeAttackButtonPressed"), [=] (Ref* sender) {
        auto userDefault = UserDefault::getInstance();
        userDefault->setIntegerForKey("mode", GameMode::TIME_ATTACK);
        onPlayPress(sender);
    });
    timeAttackButton->setPosition(timeAttackButtonFinalPosition.x, timeAttackButtonFinalPosition.y + 2000);
    
    timeAttackButton->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 2), EaseBounceOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, timeAttackButtonFinalPosition)), CallFunc::create([=](){
        timeAttackButton->runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4), RotateTo::create(DEFAULT_ANIMATION_TIME / 2, TILE_ROTATION_DEGREE), RotateTo::create(DEFAULT_ANIMATION_TIME, -TILE_ROTATION_DEGREE),RotateTo::create(DEFAULT_ANIMATION_TIME / 2, 0.0f),NULL)));
    }), NULL) );

    auto zenButtonFinalPosition = Point(335, 1920 - 1251);
    auto zenButton = MenuItemSprite::create(sprite("ZenButtonNormal"), sprite("ZenButtonPressed"), [=] (Ref* sender) {
        auto userDefault = UserDefault::getInstance();
        userDefault->setIntegerForKey("mode", GameMode::ZEN);
        onPlayPress(sender);
    });
    zenButton->setPosition(zenButtonFinalPosition.x, zenButtonFinalPosition.y + 2000);
    zenButton->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 3), EaseBounceOut::create(MoveTo::create(DEFAULT_ANIMATION_TIME, zenButtonFinalPosition)), CallFunc::create([=](){
        zenButton->runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4), RotateTo::create(DEFAULT_ANIMATION_TIME / 2, TILE_ROTATION_DEGREE), RotateTo::create(DEFAULT_ANIMATION_TIME, -TILE_ROTATION_DEGREE),RotateTo::create(DEFAULT_ANIMATION_TIME / 2, 0.0f),NULL)));
    }), NULL) );
    
    auto arcadeLabel = label("ARCADE")->size(MENU_FONT_SIZE)->position(Point(timeAttackButtonFinalPosition.x, arcadeButtonFinalPosition.y))->color(ARCADE_TEXT_COLOR)->addTo(this);
    arcadeLabel->setVisible(false);
    arcadeLabel->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 3),  Show::create(), NULL));
    
    auto timeAttackLabel = label("  TIME\nATTACK")->size(MENU_FONT_SIZE)->position(Point(arcadeButtonFinalPosition.x, timeAttackButtonFinalPosition.y))->color(TIME_ATTACK_TEXT_COLOR)->addTo(this);
    timeAttackLabel->setVisible(false);
    timeAttackLabel->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 4),  Show::create(), NULL));
    
    auto zenLabel = label("ZEN")->size(MENU_FONT_SIZE)->position(Point(timeAttackButtonFinalPosition.x, zenButtonFinalPosition.y))->color(ZEN_TEXT_COLOR)->addTo(this);
    zenLabel->setVisible(false);
    zenLabel->runAction(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 5),  Show::create(), NULL));
    
    auto soundManager = SoundManager::sharedSoundManager();
    
    auto soundButtonOn = MenuItemSprite::create(sprite("SoundButtonOn"), nullptr);
    auto soundButton = MenuItemToggle::createWithCallback([=](Ref* sender) {
        auto button = (MenuItemToggle*) sender;
        if(button->getSelectedItem() == soundButtonOn) {
            soundManager->unmuteSound();
        } else {
            soundManager->muteSound();
        }
        playSoundEffect("Click");
    }, soundButtonOn, MenuItemSprite::create(sprite("SoundButtonOff"), nullptr), NULL);
    
    if(soundManager->isSoundEnabled()) {
        soundButton->setSelectedIndex(0);
    } else {
        soundButton->setSelectedIndex(1);
    }
    
    soundButton->setPosition(Point(291, 1920 - 1710));
    
#if (CC_TARGET_PLATFORM != CC_PLATFORM_IOS)
    auto leaderBoardButton = MenuItemSprite::create(sprite("LeaderboardButtonNormal"), sprite("LeaderboardButtonPressed"), [=] (Ref* sender) {
        playSoundEffect("Click");
        NativeUtils::showLeaderboards();
    });
    leaderBoardButton->setPosition(Point(796, 1920 - 1710));
    
    auto menu = Menu::create(arcadeButton, timeAttackButton, zenButton, soundButton, leaderBoardButton, NULL);
    menu->setPosition(Point::ZERO);
    addChild(menu);
#else
    
    auto menu = Menu::create(arcadeButton, timeAttackButton, zenButton, soundButton, NULL);
    menu->setPosition(Point::ZERO);
    addChild(menu);
    
#endif
    
    
    runAction(RepeatForever::create(Sequence::create(DelayTime::create(DEFAULT_ANIMATION_TIME * 12), CallFunc::create([=] () {
        playSoundEffect("Giggle");
    }) , NULL)));
    
    return true;
}
Ejemplo n.º 13
0
void MainMenu::onPlayPress(Ref* sender) {
    playSoundEffect("Click");
    Director::getInstance()->replaceScene(TransitionSlideInR::create(SCENE_TRANSITION_TIME, CountDown::createScene()));
}
Ejemplo n.º 14
0
//! calling every time after doing all game stuff (dynamic, scriptin, etc.)
void CGameNodeButton::OnPostDynamic(f64 delta_time_sec)
{
	IGameNodeActivatable::OnPostDynamic(delta_time_sec);

	s32 now = m_NowTimeMs;

	CurrentPos = m_SceneNode->getPosition();	

	if (State == EBS_PUSHING)
	{
		dyn::IDynamicObject *dynobj = getDynamicObject();

		if (dynobj)
		{
			core::vector3df vec = PushedPos-CurrentPos;

			f32 angle = PushDir.getAngleDeg(vec);	
			
			if (angle>85)
			{
				State = EBS_WAITING;

				dyn::SDynamicObjectParams Button_dynparams = dynobj->getParameters();

				Button_dynparams.DynamicConstraints = dyn::EDTC_NO_TRANSF;

				dynobj->setParameters(Button_dynparams);

				StartUnpushTime = now + m_WaitTimeSec * 1000;

				//stopSoundEffect(BUTTON_ACTIVATED_SOUND);
				playSoundEffect(BUTTON_DEACTIVATED_SOUND);
			}
		}
	}
	else if (State == EBS_UNPUSHING)
	{
		dyn::IDynamicObject *dynobj = getDynamicObject();

		if (dynobj)
		{
			core::vector3df vec = UnpushedPos-CurrentPos;
			f32 angle = PushDir.getAngleDeg(vec);	
				
			if (angle<90)
			{
				State = EBS_UNPUSHED;

				dyn::SDynamicObjectParams Button_dynparams = dynobj->getParameters();

				Button_dynparams.DynamicConstraints = dyn::EDTC_NO_TRANSF;

				dynobj->setParameters(Button_dynparams);

				m_Activated = false;
			}
		}
	}
	else if (State == EBS_WAITING)
	{
		if (now>StartUnpushTime)
		{
			State = EBS_UNPUSHING;

			dyn::IDynamicObject *dynobj = getDynamicObject();

			if (dynobj)
			{
				dyn::SDynamicObjectParams Button_dynparams = dynobj->getParameters();
						
				Button_dynparams.DynamicConstraints = DynamicConstraints;

				dynobj->setParameters(Button_dynparams);
			}
		}
	} 
}
Ejemplo n.º 15
0
void PongApp::mouseEvent( GF::MOUSE_EVENT_TYPE type, int x, int y, int button ) {
    if (button>1 || button<0) {
        return;          // ignore.. cannot fit
    }

    float worldx = (float)x / (float)currentWidth*2.0f - 1.0f;
    float worldy = (float)y / (float)currentHeight*2.0f - 1.0f;
    worldy *= -((float)currentHeight/(float)currentWidth);

#ifdef EPONG_DEBUG
    if (type==GF::MOUSE_DOWN && y < 24)
    {
        playSoundEffect( sampleLatencyTest, 1.0f );
    }
#endif

    if (currentMenu) currentMenu->keyControlEnd();


    if (highScores) {
        if (type==GF::MOUSE_DOWN) {
            highScores->die();
        }
        return;
    };

    if (credits) {
        if (type==GF::MOUSE_DOWN) {
            credits->die();
        }
        return;
    };

    if (currentMenu) {
        if (currentMenu->alreadyClicked() == false && type==GF::MOUSE_DOWN) {
            int itemCount = currentMenu->getItemCount();
            // similar as in menuItemRender
            float scale = MENU_ITEM_HEIGHT/2.0f;
            float ystart = scale*0.65f*itemCount + scale;
            float ystep = MENU_ITEM_HEIGHT;



            if (worldy<ystart) {
                int clickIndex = -(worldy-ystart) / ystep;
                if (currentMenu->click( clickIndex ))
                    playSoundEffect( sampleMenuTick, 1.0f );
            }

        };
        return;
    }


    switch (type) {
        case GF::MOUSE_DOWN:
            if (worldy>getTop()-0.1f) {
                if (worldx > 0.7f) {
                    if (worldx > 0.8f) {
                        if (currentGame && currentGame->getGameState()==PGS_RUNNING && !currentMenu) {
                            // create pause menu
                            currentMenu = createPauseMenu();
                        }
                    } else {

                    };

                };

                return;
            };
            buttonDown[button] = true;
        break;
        case GF::MOUSE_UP:
            buttonDown[button] = false;
    };



    pointerX[button] = worldx;
    pointerY[button] = worldy;


}
Ejemplo n.º 16
0
void
Cave01::ouchSound(Entity&, Tile&) noexcept {
    playSoundEffect("sounds/ouch.oga");
}
Ejemplo n.º 17
0
void GameOver::onNewHighScore(const char* highScoreKey, float score) {
    HighScoreManager::saveHighScore(highScoreKey, score);
    playSoundEffect("Success");
    addChild(sprite("BestScore", Point(VisibleRect::center().x, scoreBox->getPositionY() + scoreBox->getContentSize().height / 2 + 80)));
}
Ejemplo n.º 18
0
void Game::onResetPressed(CCObject* sender) {
	playSoundEffect("ButtonClick");
	timer->stop();
	GameManager::sharedGameManager()->runScene(Game::scene());
}
Ejemplo n.º 19
0
void Game::onPausePressed(CCObject* sender) {
	playSoundEffect("ButtonClick");
}