void Deadstorm::OnStartup() { Gem::GameStatePtr preloaderState(new PreloaderState()); Gem::GameStatePtr menuState(new MenuState()); Gem::GameStatePtr gamePlayState(new GameplayState()); g_gameStateManager.Register(g_gameStateId_Preloader, preloaderState); g_gameStateManager.Register(g_gameStateId_Menu, menuState); g_gameStateManager.Register(g_gameStateId_GamePlay, gamePlayState); g_gameStateManager.PushState(g_gameStateId_Preloader); }
void menuClass::displayMenu() { int menuPos = 0; //fill black background for (int yPlace = 1; yPlace < 14; yPlace++) { for (int xPlace = 1; xPlace < 19; xPlace++) { game_graphics->drawSprite(blackTile, 0, 0, xPlace * 32, yPlace * 32,32,32); } } drawBorder(18, 13); while (inMenu) { drawMenuItems(menuPos); game_graphics->endScene(); int tempNum = menuState(); if (tempNum != 3) //sloppy, I'm sure... but '3' represents a selection { menuPos += tempNum; if (menuPos < 0) {menuPos = (menuItemList.size() - 1);} else if (menuPos > (menuItemList.size() - 1)) {menuPos = 0;} } else if (tempNum == 3) { doMenuItem(menuPos); } } }
void Game::run() { m_window.create(sf::VideoMode{ 1280, 720 }, "Dodaren", sf::Style::Titlebar | sf::Style::Close); std::unique_ptr<State> menuState(new MenuState(m_stateManager, m_window)); m_stateManager.changeState(std::move(menuState)); sf::Clock clock; sf::Time timeSinceLastUpdate = sf::Time::Zero; while (m_stateManager.running()) { sf::Time elapsedTime = clock.restart(); timeSinceLastUpdate += elapsedTime; while (timeSinceLastUpdate > TimePerFrame) { timeSinceLastUpdate -= TimePerFrame; m_stateManager.processEvents(); m_stateManager.update(TimePerFrame); } m_stateManager.draw(); } }