Пример #1
0
	void HexagonGame::newGame(const string& mId, bool mFirstPlay, float mDifficultyMult)
	{
		initFlashEffect();

		firstPlay = mFirstPlay;
		setLevelData(assets.getLevelData(mId), mFirstPlay);
		difficultyMult = mDifficultyMult;

		// Audio cleanup
		assets.stopSounds(); stopLevelMusic();
		assets.playSound("go.ogg"); playLevelMusic();

		if(Config::getMusicSpeedDMSync())
		{
			auto current(assets.getMusicPlayer().getCurrent());
			if(current != nullptr) current->setPitch(pow(difficultyMult, 0.12f));
		}

		// Events cleanup
		messageText.setString("");
		eventTimeline.clear(); eventTimeline.reset();
		messageTimeline.clear(); messageTimeline.reset();

		// Manager cleanup
		manager.clear();
		factory.createPlayer();

		// Timeline cleanup
		timeline.clear(); timeline.reset();
		effectTimelineManager.clear();
		mustChangeSides = false;

		// FPSWatcher reset
		fpsWatcher.reset();
		if(Config::getOfficial()) fpsWatcher.enable();

		// LUA context and game status cleanup
		status = HexagonGameStatus{};
		if(!mFirstPlay) runLuaFunction<void>("onUnload");
		lua = Lua::LuaContext{};
		initLua();
		runLuaFile(levelData->luaScriptPath);
		runLuaFunction<void>("onInit");
		runLuaFunction<void>("onLoad");
		restartId = mId;
		restartFirstTime = false;
		setSides(levelStatus.sides);

		// Reset zoom
		overlayCamera.setView({{Config::getWidth() / 2.f, Config::getHeight() / 2.f}, Vec2f(Config::getWidth(), Config::getHeight())});
		backgroundCamera.setView({ssvs::zeroVec2f, {Config::getWidth() * Config::getZoomFactor(), Config::getHeight() * Config::getZoomFactor()}});
		backgroundCamera.setRotation(0);

		// 3D Cameras cleanup
		depthCameras.clear();
		auto depth(styleData._3dDepth);
		if(depth > Config::get3DMaxDepth()) depth = Config::get3DMaxDepth();
		for(auto i(0u); i < depth; ++i) depthCameras.push_back({window, {}});
	}
Пример #2
0
	HexagonGame::HexagonGame(HGAssets& mAssets, GameWindow& mGameWindow) : assets(mAssets), window(mGameWindow), fpsWatcher(window)
	{
		game.onUpdate += [this](float mFT) { update(mFT); };
		game.onDraw += [this]{ draw(); };
		window.onRecreation += [this]{ initFlashEffect(); };

		add3StateInput(game, Config::getTriggerRotateCCW(), Config::getTriggerRotateCW(), inputMovement);
		add2StateInput(game, Config::getTriggerFocus(), inputFocused);
		add2StateInput(game, Config::getTriggerSwap(), inputSwap);
		game.addInput(Config::getTriggerExit(),			[this](float){ goToMenu(); });
		game.addInput(Config::getTriggerForceRestart(),	[this](float){ status.mustRestart = true; });
		game.addInput(Config::getTriggerRestart(),		[this](float){ if(status.hasDied) status.mustRestart = true; });
		game.addInput(Config::getTriggerScreenshot(),	[this](float){ mustTakeScreenshot = true; }, Input::Trigger::Type::Once);
	}
Пример #3
0
	HexagonGame::HexagonGame(GameWindow& mGameWindow) : window(mGameWindow), fpsWatcher(window)
	{
		initFlashEffect();

		game.onUpdate += [&](float mFrameTime) { update(mFrameTime); };
		game.onDraw += [&]{ draw(); };

		add3StateInput(game, getTriggerRotateCCW(), getTriggerRotateCW(), inputMovement);
		add2StateInput(game, getTriggerFocus(), inputFocused);
		game.addInput(getTriggerExit(),			[&](float){ goToMenu(); });
		game.addInput(getTriggerForceRestart(),	[&](float){ status.mustRestart = true; });
		game.addInput(getTriggerRestart(),		[&](float){ if(status.hasDied) status.mustRestart = true; });
		game.addInput(getTriggerScreenshot(),	[&](float){ mustTakeScreenshot = true; }, Input::Trigger::Type::Single);
	}