MenuState::MenuState(xy::StateStack& stack, xy::State::Context ctx, SharedStateData& sharedData, LoadingScreen& ls) : xy::State(stack, ctx), m_scene (ctx.appInstance.getMessageBus()), m_helpScene (ctx.appInstance.getMessageBus()), m_resource (), m_menuBGRes (m_resource.load<sf::Texture>("assets/images/menu_background.png")), m_grassRes (m_resource.load<sf::Texture>("assets/images/grass.png")), m_flowerRes (m_resource.load<sf::Texture>("assets/images/flower.png")), m_helpSignRes (m_resource.load<sf::Texture>("assets/images/help_sign.png")), m_caveStoryRes (m_resource.load<sf::Font>("assets/fonts/Cave-Story.ttf")), m_helpRes (m_resource.load<sf::Texture>("assets/images/help.png")), m_keyBindsRes (m_resource.load<sf::Texture>("assets/images/keybinds.png")), m_buttonRes (m_resource.load<sf::Texture>("assets/images/button.png")), m_sharedStateData (sharedData), m_loadingScreen (ls), m_helpShown (false), m_blurEffect (nullptr) { launchLoadingScreen(); loadKeybinds(); createScene(); createMenu(); createHelp(); ctx.appInstance.setClearColour({ 1, 0, 10 }); xy::App::setMouseCursorVisible(true); quitLoadingScreen(); }
TilemapDemoState::TilemapDemoState(xy::StateStack& stateStack, Context context) : State (stateStack, context), m_messageBus(context.appInstance.getMessageBus()), m_scene (m_messageBus), m_physWorld (m_messageBus) { launchLoadingScreen(); m_scene.setView(context.defaultView); m_shaderResource.preload(xy::Shader::Tilemap, xy::Shader::tmx::vertex, xy::Shader::tmx::fragment); m_physWorld.setGravity({ 0.f, 980.f }); buildScene(); REPORT("Q", "Show Debug"); //xy::StatsReporter::show(); quitLoadingScreen(); }
MenuMainState::MenuMainState(xy::StateStack& stack, Context context) : State (stack, context), m_messageBus (context.appInstance.getMessageBus()), m_uiContainer (m_messageBus) { launchLoadingScreen(); buildMenu(); buildSettings(); auto msg = m_messageBus.post<xy::Message::UIEvent>(xy::Message::UIMessage); msg->type = xy::Message::UIEvent::MenuOpened; msg->value = 0.f; msg->stateID = States::ID::MenuMain; xy::App::setMouseCursorVisible(true); getContext().renderWindow.setTitle("xy tools"); quitLoadingScreen(); }
PlatformDemoState::PlatformDemoState(xy::StateStack& stateStack, Context context) : State (stateStack, context), m_messageBus (context.appInstance.getMessageBus()), m_scene (m_messageBus), m_physWorld (m_messageBus), m_meshRenderer ({ context.appInstance.getVideoSettings().VideoMode.width, context.appInstance.getVideoSettings().VideoMode.height }, m_scene) { launchLoadingScreen(); xy::Stats::clear(); m_physWorld.setGravity({ 0.f, 1180.f }); m_physWorld.setPixelScale(120.f); m_scene.setView(context.defaultView); m_scene.setAmbientColour({ 76, 70, 72 }); m_scene.getSkyLight().setIntensity(0.5f); m_scene.getSkyLight().setDiffuseColour({ 255, 255, 200 }); m_scene.getSkyLight().setSpecularColour({ 120, 255, 58 }); m_scene.getSkyLight().setDirection({ 0.2f, 0.4f, -0.4f }); m_meshRenderer.setView(context.defaultView); cacheMeshes(); buildTerrain(); buildPhysics(); addItems(); addPlayer(); auto e = xy::Entity::create(m_messageBus); auto md = m_meshRenderer.createDrawable(m_messageBus); //md->enableWater(true); e->addComponent(md); m_scene.addEntity(e, xy::Scene::Layer::FrontFront); REPORT("Q", "Show Debug"); xy::App::setMouseCursorVisible(true); quitLoadingScreen(); }
GameState::GameState(StateStack& stack, Context context) : State (stack, context), m_textureResource (context.gameInstance.getTextureResource()), m_shaderResource (context.gameInstance.getShaderResource()), m_collisionWorld (70.f), m_npcController (m_commandStack, m_textureResource, m_shaderResource), m_scoreBoard (stack, context), m_particleController(m_textureResource, m_shaderResource), m_mapController (m_commandStack, m_textureResource, m_shaderResource) { //launch loading window launchLoadingScreen(); //build world Scene::defaultCamera.setView(getContext().defaultView); m_scene.addShader(m_shaderResource.get(Shader::Type::FlatShaded)); m_scene.addShader(m_shaderResource.get(Shader::Type::NormalMapSpecular)); m_scene.addShader(m_shaderResource.get(Shader::Type::NormalMap)); m_scene.addShader(m_shaderResource.get(Shader::Type::Metal)); m_scene.addShader(m_shaderResource.get(Shader::Type::Water)); m_scene.addShader(m_shaderResource.get(Shader::Type::WaterDrop)); m_scene.addObserver(m_scoreBoard); m_scene.addObserver(m_particleController); m_scene.addObserver(m_audioController); float origin = lightDrawable.getRadius(); lightDrawable.setOrigin(origin, origin); lightDrawable.setFillColor(sf::Color(255u, 255u, 255u, 140u)); lightDrawable.setOutlineColor(sf::Color(255u, 255u, 255u, 11u)); lightDrawable.setOutlineThickness(80.f); //parse map Map map("res/maps/" + context.gameData.mapList[context.gameData.mapIndex]); //set up controllers m_players.reserve(2); m_players.emplace_back(m_commandStack, Category::PlayerOne, m_textureResource, m_shaderResource.get(Shader::Type::NormalMapSpecular)); m_players.back().setKeyBinds(context.gameData.playerOne.keyBinds); m_players.emplace_back(m_commandStack, Category::PlayerTwo, m_textureResource, m_shaderResource.get(Shader::Type::NormalMapSpecular)); m_players.back().setKeyBinds(context.gameData.playerTwo.keyBinds); std::function<void(const sf::Vector2f&, Player&)> playerSpawnFunc = std::bind(&GameState::addPlayer, this, std::placeholders::_1, std::placeholders::_2); m_players[0].setSpawnFunction(playerSpawnFunc); m_players[1].setSpawnFunction(playerSpawnFunc); m_players[0].setSpawnPosition(map.getPlayerOneSpawn()); m_players[1].setSpawnPosition(map.getPlayerTwoSpawn()); std::function<void(const sf::Vector2f&, const sf::Vector2f&)> npcSpawnFunc = std::bind(&GameState::addNpc, this, std::placeholders::_1, std::placeholders::_2); m_npcController.setSpawnFunction(npcSpawnFunc); m_npcController.setNpcCount(map.getNpcCount()); std::function<void(const Map::Node&)> mapSpawnFunc = std::bind(&GameState::addMapBody, this, std::placeholders::_1); m_mapController.setSpawnFunction(mapSpawnFunc); m_mapController.loadMap(map); m_scoreBoard.addObserver(m_players[0]); m_scoreBoard.addObserver(m_players[1]); m_scoreBoard.addObserver(m_npcController); if (context.gameData.playerOne.enabled) m_scoreBoard.enablePlayer(Category::PlayerOne); if (context.gameData.playerTwo.enabled) m_scoreBoard.enablePlayer(Category::PlayerTwo); m_scoreBoard.setMaxNpcs(map.getNpcTotal()); m_scene.setLayerDrawable(m_mapController.getDrawable(MapController::MapDrawable::Solid), Scene::Solid); m_scene.setLayerDrawable(m_mapController.getDrawable(MapController::MapDrawable::RearDetail), Scene::RearDetail); m_scene.setLayerDrawable(m_mapController.getDrawable(MapController::MapDrawable::FrontDetail), Scene::FrontDetail); m_scene.setLayerDrawable(m_mapController.getDrawable(MapController::MapDrawable::Background), Scene::Background); m_scene.setAmbientColour(map.getAmbientColour()); m_scene.setSunLightColour(map.getSunlightColour()); //sf::Clock c; //while (c.getElapsedTime().asSeconds() < 5.f){} std::string theme = map.getAudioTheme(); std::string music; if (!theme.empty()) { m_audioController.loadTheme(theme); music = "res/sound/themes/" + theme + "/main.ogg"; } //close loading screen before starting music quitLoadingScreen(); if (!music.empty()) context.gameInstance.getMusicPlayer().play(music); registerConsoleCommands(); context.renderWindow.setMouseCursorVisible(false); }