void CMazeGameEngine::evolveWorld()
	{
		if (_isNextLevelRequested)
		{
			startNextLevel();
		}
		if (menu.isMenuShowing() || !_worldModel.isWorldInitialized())
		{ //world is not initialized yet, or menu is showing - no need to evolve.
			return;
		}
		float deltaT = getTimeFromPreviousFrame();
		if (deltaT > 0.3) //This probably happened because of a spike drop in framerate, ignore this long frame time.
		{ //if it happend due to the FPS droping to 3, the game is not playable anyway...
			LOG(DEBUG) << "Skipped frame, it was too late";
			return;
		}
		if (deltaT < _minTimeBetweenFrames) //I want max 60 FPS
		{
			_device->sleep((_minTimeBetweenFrames - deltaT) * 1000.0f);
			deltaT = getTimeFromPreviousFrame();
		}
		_worldModel.evolve(deltaT);
		for (auto & playerView : _playerViews)
			playerView.update(0);
		_camera.evolve(deltaT);
		if (_worldModel.isMazeGameWon() && !isWinScreenShowing)
		{
			showWinScreen();
		}
	}
Esempio n. 2
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;
}