Пример #1
0
		void MainMenuState::update(GameBase &game, GameTime &gameTime)
		{
			game.getEngine()->getInputEngine()->update(game);

			if (_advertisementIndex >= 0.0f && _shouldRefreshAdvertisement)
			{
				int timeSinceLastUpdate = game.getGameTime()->getElapsedSinceLastUpdate() / 1000.0f;
				if (timeSinceLastUpdate >= 0.0f)
				{
					if ((_lastTimeSinceAdvertisementChange += timeSinceLastUpdate) >= _advertisementRefreshRate)
					{
						loadAdvertisement();
						_lastTimeSinceAdvertisementChange = 0.0f;
					}
				}
			}
		}
Пример #2
0
		void GameOverState::init(GameBase &game)
		{
			_game = &game;

			_game->getEngine()->getPhysicsEngine()->pause();
			
			_isLoaded = false;
			_savedReplay = false;
			_enteredGameOverState = game.getGameTime()->getTotalSecondsRunning();

			game.getEngine()->getAudioEngine()->stopMusic();
			
			_menu = new Menu(game.getEngine()->getDrawEngine()->getWindowWidth() - (187.5f * 3), 50.0f, game);

			const std::vector<GameObject*> &deadList = game.getWorld()->getDeadList();
			bool unlocked = false;

			model::Character *chas = nullptr;

			if (game.getGameMode() == GameBase::GameMode::SinglePlayer)
			{
				static_cast<Character*>(game.getWorld()->getPlayers()[1])->getAI()->pause();

				if (!LoadingSinglePlayerState::getInstance().hasFinished())
				{
					if (static_cast<Character*>(deadList[1])->getKey() == LoadingSinglePlayerState::getInstance().getPlayerName())
					{
						game.getEngine()->getDrawEngine()->load("gameoverbackground", "assets/screens/winner");
						_menu->addMenuTextItem("Next", (std::function<void()>)std::bind(&GameOverState::next, this));
						game.getEngine()->getAudioEngine()->load("winner", "assets/sounds/effects/win.ogg", AUDIOTYPE::SOUND_EFFECT);
						game.getEngine()->getAudioEngine()->play("winner", 0);
					}
					else
					{
						chas = static_cast<model::Character*>(deadList[0]);
						game.getEngine()->getDrawEngine()->load("gameoverbackground", "assets/screens/loser");

						game.getEngine()->getAudioEngine()->load("loser", "assets/sounds/effects/lose.ogg", AUDIOTYPE::SOUND_EFFECT);
						game.getEngine()->getAudioEngine()->play("loser", 0);
					}
				}
				else if (static_cast<Character*>(deadList[1])->getKey() == LoadingSinglePlayerState::getInstance().getPlayerName())
				{
					game.getEngine()->getDrawEngine()->load("gameoverbackground", "assets/screens/winner");

					ProgressManager &manager = ProgressManager::getInstance();

					if (!manager.isUnlockedCharacter(static_cast<Character*>(deadList[0])->getName()))
					{
						std::string asd = static_cast<Character*>(deadList[0])->getKey();
						std::string has = LoadingSinglePlayerState::getInstance().getLevelName();
						UnlockedState::getInstance().setPlayerName(static_cast<Character*>(deadList[0])->getKey());
						UnlockedState::getInstance().setLevelName(LoadingSinglePlayerState::getInstance().getLevelName());
						manager.setIsUnlockedCharacter(static_cast<Character*>(deadList[0])->getName(), true);
						manager.setIsUnlockedLevel(LoadingSinglePlayerState::getInstance().getLevelName(), true);
						//  UnlockedState::getInstance().cleanup(game);
						unlocked = true;
					}

					game.getEngine()->getAudioEngine()->load("winner", "assets/sounds/effects/win.ogg", AUDIOTYPE::SOUND_EFFECT);
					game.getEngine()->getAudioEngine()->play("winner", 0);
				}
				_menu->addMenuTextItem("Achievements", (std::function<void()>)[&] { _game->getStateManager()->pushState(StatisticsState::getInstance()); });
			}
			else if (game.getGameMode() == GameBase::GameMode::Versus)
			{
				game.getEngine()->getAudioEngine()->load("winner", "assets/sounds/effects/win.ogg", AUDIOTYPE::SOUND_EFFECT);
				game.getEngine()->getAudioEngine()->play("winner", 0);
				game.getEngine()->getDrawEngine()->load("gameoverbackground", "assets/screens/winner");
				_menu->addMenuTextItem("Play again", (std::function<void()>)std::bind(&GameOverState::replay, this));
				_menu->addMenuTextItem("Save replay", (std::function<void()>)std::bind(&GameOverState::saveReplay, this));
				_menu->addMenuTextItem("Statistics", (std::function<void()>)[&] { _game->getStateManager()->pushState(StatisticsState::getInstance()); });
			}
			else if (game.getGameMode() == GameBase::GameMode::Playback)
			{
				game.getEngine()->getAudioEngine()->load("winner", "assets/sounds/effects/win.ogg", AUDIOTYPE::SOUND_EFFECT);
				game.getEngine()->getAudioEngine()->play("winner", 0);
				game.getEngine()->getDrawEngine()->load("gameoverbackground", "assets/screens/winner");
			}

			_menu->addMenuTextItem("Main menu", (std::function<void()>)[&] {
				if (game.getGameMode() == GameBase::GameMode::SinglePlayer)
					LoadingSinglePlayerState::getInstance().unloadAll();
				changeState(*_game, MainMenuState::getInstance());
			});
		
			Uint8 color = 255;
			for (int i = deadList.size() - 1; i >= 0; i--) {
				int rank = (deadList.size() - i);
				game.getEngine()->getDrawEngine()->loadText("rank" + std::to_string(rank), std::to_string(rank) + ". " + deadList[i]->getName(), { color, color, color }, "arial", 54);
				std::string asd = deadList[i]->getName();
				color = 64;
			}

			_characterCount = deadList.size();
			if (!chas)
				chas = static_cast<model::Character*>(deadList[_characterCount - 1]);

			game.getEngine()->getDrawEngine()->load("winner", "assets/characters/" + chas->getKey() + "/win");

			// Update statistics
			JSON::JSONArray &statistics = ProgressManager::getInstance().getStatistics();
			
			for (size_t rank = 0, ranklen = deadList.size(); rank < ranklen; rank++) {

				for (auto i = 0; i < statistics.size(); i++) {
					JSON::JSONObject &characterObj = statistics.getObject(i);

					if (characterObj.getString("name") == deadList.at(rank)->getName()) {
						if (rank == (deadList.size() - 1))
							characterObj.getVariable("wins").setValue(std::to_string(1 + characterObj.getInt("wins")));
						else
							characterObj.getVariable("losses").setValue(std::to_string(1 + characterObj.getInt("losses")));
						break;
					}
				}
			}
			
			// Save progress if autosave is enabled
			if (ProgressManager::getInstance().autosaveEnabled())
				ProgressManager::getInstance().save();

			if (unlocked)
			{
				if (ProgressManager::getInstance().autosaveEnabled())
					ProgressManager::getInstance().save();
				unlocked = false;
				game.getStateManager()->pushState(UnlockedState::getInstance());
			}
		}
Пример #3
0
		void GameOverState::update(GameBase &game, GameTime &gameTime)
		{
			if (game.getGameTime()->getTotalSecondsRunning() - _enteredGameOverState > 3)
				_isLoaded = true;
		}