diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index 45b1af9..4e7b0b0 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -49,6 +49,7 @@ typedef uint64_t Timestamp; #pragma comment(lib,"wsock32.lib") // Pour pouvoir faire fonctionner le linker sans le vcxproject #pragma comment(lib,"ws2_32.lib") + #include #include #include diff --git a/SQCSim2021/SQCSim2021.vcxproj b/SQCSim2021/SQCSim2021.vcxproj index 3aec273..31e1b8b 100644 --- a/SQCSim2021/SQCSim2021.vcxproj +++ b/SQCSim2021/SQCSim2021.vcxproj @@ -27,6 +27,7 @@ + @@ -44,6 +45,7 @@ + diff --git a/SQCSim2021/SQCSim2021.vcxproj.filters b/SQCSim2021/SQCSim2021.vcxproj.filters index 8246b5c..417ba37 100644 --- a/SQCSim2021/SQCSim2021.vcxproj.filters +++ b/SQCSim2021/SQCSim2021.vcxproj.filters @@ -56,6 +56,9 @@ Fichiers d%27en-tête + + Fichiers d%27en-tête + @@ -103,5 +106,8 @@ Fichiers sources + + Fichiers sources + \ No newline at end of file diff --git a/SQCSim2021/audio.cpp b/SQCSim2021/audio.cpp index e849c6f..7691f88 100644 --- a/SQCSim2021/audio.cpp +++ b/SQCSim2021/audio.cpp @@ -48,3 +48,7 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); } void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); } + +float Audio::GetMusicVolume() const { + return m_music->getVolume(); +} diff --git a/SQCSim2021/audio.h b/SQCSim2021/audio.h index 775f316..f19682a 100644 --- a/SQCSim2021/audio.h +++ b/SQCSim2021/audio.h @@ -33,6 +33,8 @@ public: void ToggleMusicState(); void PauseEngine(); + + float GetMusicVolume() const; }; #endif // AUDIO_H__ diff --git a/SQCSim2021/define.h b/SQCSim2021/define.h index e268b20..28168bb 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -37,4 +37,11 @@ #define MENU_ITEM_PATH "./media/menu_items/" #define BOOSTER_TEXTURE_PATH "./media/textures/Booster/" +enum Resolution { + HD = 0, // 1280x720 (High Definition) + FHD, // 1920x1080 (Full HD) + QHD, // 2560x1440 (Quad HD) + UHD // 3840x2160 (Ultra HD) +}; + #endif // DEFINE_H__ diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 32e18e0..39f3b72 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -13,7 +13,6 @@ struct Notification { float displayStartTime = 0.0f; }; - // Use a queue to manage notifications //std::queue notificationQueue; // Use a vector to manage notifications @@ -29,299 +28,6 @@ Engine::~Engine() { m_world.GetChunks().Get(x, y)->~Chunk(); } -void Engine::DrawSplachScreen() -{ - glDisable(GL_LIGHTING); - glDisable(GL_DEPTH_TEST); - glDisable(GL_STENCIL_TEST); - - // Définir la matrice de projection en mode orthographique - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(-Width() / 2, Width() / 2, -Height() / 2, Height() / 2, -1, 1); - - // Définir la matrice de modèle-vue - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - glLoadIdentity(); - - // L'image sera centrée autour de l'origine (0, 0, 0) - int imageWidth = Width(); // Remplacez par la largeur de votre image - int imageHeight = Height(); // Remplacez par la hauteur de votre image - - // Texture - SplachScreenTexture.Bind(); - - // Dessiner un quadrilatère centré - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(-imageWidth / 2, -imageHeight / 2); - glTexCoord2f(1, 0); - glVertex2i(imageWidth / 2, -imageHeight / 2); - glTexCoord2f(1, 1); - glVertex2i(imageWidth / 2, imageHeight / 2); - glTexCoord2f(0, 1); - glVertex2i(-imageWidth / 2, imageHeight / 2); - glEnd(); - - // Activer la transparence - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - glEnable(GL_BLEND); - - // Restaurer les matrices précédentes - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - - m_gamestate = GameState::MAIN_MENU; -} - - - -void Engine::DrawMenu() -{ - static const int sTitle = 400; - static const int sButton = 225; - - glDisable(GL_LIGHTING); - - - glDisable(GL_DEPTH_TEST); - glDisable(GL_STENCIL_TEST); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0, Width(), 0, Height(), -1, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - MenuBGTexture.Bind(); - glLoadIdentity(); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(Width(), 0); // - glTexCoord2f(1, 1); - glVertex2i(Width(), Height()); - glTexCoord2f(0, 1); - glVertex2i(0, Height()); - glEnd(); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - glEnable(GL_BLEND); - - if (m_gamestate != GameState::OPTIONS) - { - MenuTitleTexture.Bind(); - glTranslated(200, 300, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 200); - glTexCoord2f(1, 0); - glVertex2i(sTitle, 200); - glTexCoord2f(1, 1); - glVertex2i(sTitle, 300); - glTexCoord2f(0, 1); - glVertex2i(0, 300); - glEnd(); - - - - MenuStartTexture.Bind(); - glTranslated(80, -225, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 100); - glTexCoord2f(1, 0); - glVertex2i(sButton , 100); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - - /*MenuResumeTexture.Bind(); - glTranslated(0, -100, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - //glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd();*/ - - MenuOptionsTexture.Bind(); - glTranslated(0, -100, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - MenuQuitTexture.Bind(); - glTranslated(0, -100, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 100); - glTexCoord2f(1, 0); - glVertex2i(sButton, 100); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - } - else - { - MenuOptionsTexture.Bind(); - glTranslated(200, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(sTitle, 0); - glTexCoord2f(1, 1); - glVertex2i(sTitle, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - /*WireFrameTexture.Bind(); - glTranslated(0, 300, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd();*/ - - /*OnOffBtnTexture.Bind(); - glTranslated(200, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - glTranslated(-400, -300, 0);*/ - - MusicTexture.Bind(); - glTranslated(200, 200, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - OnOffBtnTexture.Bind(); - glTranslated(200, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 125); - glTexCoord2f(1, 0); - glVertex2i(sButton, 125); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - - BackBtnTexture.Bind(); - glTranslated(-375, 175, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 140); - glTexCoord2f(1, 0); - glVertex2i(sButton, 140); - glTexCoord2f(1, 1); - glVertex2i(sButton, 200); - glTexCoord2f(0, 1); - glVertex2i(0, 200); - glEnd(); - } - - //glEnable(GL_LIGHTING); - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - ShowCursor(); -} - -void Engine::DrawOption() -{ - static const int sTitle = 400; - static const int sButton = 225; - - glDisable(GL_LIGHTING); - - - glDisable(GL_DEPTH_TEST); - glDisable(GL_STENCIL_TEST); - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - glLoadIdentity(); - glOrtho(0, Width(), 0, Height(), -1, 1); - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - MenuBGTexture.Bind(); - glLoadIdentity(); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(Width(), 0); // - glTexCoord2f(1, 1); - glVertex2i(Width(), Height()); - glTexCoord2f(0, 1); - glVertex2i(0, Height()); - glEnd(); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - glEnable(GL_BLEND); - - //glEnable(GL_LIGHTING); - glDisable(GL_BLEND); - glEnable(GL_DEPTH_TEST); - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); - ShowCursor(); -} - void Engine::Init() { GLenum glewErr = glewInit(); @@ -355,10 +61,8 @@ void Engine::Init() { return; else m_istarted = true; - // // Objet de skybox avec sa propre texture et son propre shader! m_skybox.Init(0.2f); - //m_skybox2.Init(1.f); // Objet de musique! //m_audio.ToggleMusicState(); @@ -422,7 +126,7 @@ void Engine::Init() { m_startTime = std::chrono::high_resolution_clock::now(); - m_remotePlayer.SetPosition(Vector3f(.5,CHUNK_SIZE_Y + 10., .5)); + m_remotePlayer.SetPosition(Vector3f(.5, CHUNK_SIZE_Y + 10., .5)); // Gestion de souris. CenterMouse(); HideCursor(); @@ -442,11 +146,29 @@ void Engine::LoadResource() { LoadTexture(m_textureMultiText, TEXTURE_PATH "multi_player.png", false); LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false); LoadTexture(m_textureTitle, TEXTURE_PATH "title.png", false); + LoadTexture(m_textureOptions, TEXTURE_PATH "Buttons/options.png", false); + LoadTexture(m_textureRetour, TEXTURE_PATH "Buttons/retour.png", false); + LoadTexture(m_textureVolume, TEXTURE_PATH "Buttons/volume.png", false); + LoadTexture(m_textureMusique, TEXTURE_PATH "Buttons/musique.png", false); + LoadTexture(m_textureGraphiques, TEXTURE_PATH "Buttons/graphiques.png", false); + LoadTexture(m_textureSensibilite, TEXTURE_PATH "Buttons/sensibilite.png", false); + LoadTexture(m_textureResolution, TEXTURE_PATH "Buttons/resolution.png", false); + LoadTexture(m_texturePrincipal, TEXTURE_PATH "Buttons/principal.png", false); + LoadTexture(m_textureEffets, TEXTURE_PATH "Buttons/effets.png", false); + LoadTexture(m_textureGameplay, TEXTURE_PATH "Buttons/gameplay.png", false); + LoadTexture(m_textureHd, TEXTURE_PATH "Buttons/hd.png", false); + LoadTexture(m_textureFhd, TEXTURE_PATH "Buttons/fhd.png", false); + LoadTexture(m_textureQhd, TEXTURE_PATH "Buttons/qhd.png", false); + LoadTexture(m_textureUhd, TEXTURE_PATH "Buttons/uhd.png", false); + LoadTexture(m_textureCheck, TEXTURE_PATH "Buttons/check.png", false); + LoadTexture(m_textureChecked, TEXTURE_PATH "Buttons/checked.png", false); + + // Pourquoi on load 3 fois la meme texture? LoadTexture(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); - LoadTexture(MenuBGOptionTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); + LoadTexture(MenuBGFlouTexture, TEXTURE_PATH "BackgroundMenuFlou.png"); LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png"); LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png"); @@ -519,8 +241,6 @@ void Engine::LoadResource() { m_textureAtlas.TextureIndexToCoord(texIceIndex, u, v, s, s); m_boostinfo[BTYPE_INVINCIBLE] = new BoostInfo(BTYPE_INVINCIBLE, "Inv", u, v, s, 1); - - m_animeAtlas.TextureIndexToCoord(0, u, v, s, s); std::cout << " Loading and compiling shaders ..." << std::endl; @@ -537,6 +257,544 @@ void Engine::LoadResource() { void Engine::UnloadResource() {} +void Engine::DrawSplachScreen() +{ + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + glDisable(GL_STENCIL_TEST); + + // Définir la matrice de projection en mode orthographique + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-Width() / 2, Width() / 2, -Height() / 2, Height() / 2, -1, 1); + + // Définir la matrice de modèle-vue + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + // L'image sera centrée autour de l'origine (0, 0, 0) + int imageWidth = Width(); // Remplacez par la largeur de votre image + int imageHeight = Height(); // Remplacez par la hauteur de votre image + + // Texture + SplachScreenTexture.Bind(); + + // Dessiner un quadrilatère centré + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(-imageWidth / 2, -imageHeight / 2); + glTexCoord2f(1, 0); + glVertex2i(imageWidth / 2, -imageHeight / 2); + glTexCoord2f(1, 1); + glVertex2i(imageWidth / 2, imageHeight / 2); + glTexCoord2f(0, 1); + glVertex2i(-imageWidth / 2, imageHeight / 2); + glEnd(); + + // Activer la transparence + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + glEnable(GL_BLEND); + + // Restaurer les matrices précédentes + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + + m_gamestate = GameState::MAIN_MENU; +} + +void Engine::DrawMenu() +{ + static const int sTitle = 400; + static const int sButton = 225; + + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + glDisable(GL_STENCIL_TEST); + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + MenuBGTexture.Bind(); + glLoadIdentity(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 0); + glTexCoord2f(1, 0); + glVertex2i(Width(), 0); // + glTexCoord2f(1, 1); + glVertex2i(Width(), Height()); + glTexCoord2f(0, 1); + glVertex2i(0, Height()); + glEnd(); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + glEnable(GL_BLEND); + + if (m_gamestate != GameState::OPTIONS) + { + MenuTitleTexture.Bind(); + glTranslated(200, 300, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 200); + glTexCoord2f(1, 0); + glVertex2i(sTitle, 200); + glTexCoord2f(1, 1); + glVertex2i(sTitle, 300); + glTexCoord2f(0, 1); + glVertex2i(0, 300); + glEnd(); + + MenuStartTexture.Bind(); + glTranslated(80, -225, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 100); + glTexCoord2f(1, 0); + glVertex2i(sButton , 100); + glTexCoord2f(1, 1); + glVertex2i(sButton, 200); + glTexCoord2f(0, 1); + glVertex2i(0, 200); + glEnd(); + + MenuOptionsTexture.Bind(); + glTranslated(0, -100, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 125); + glTexCoord2f(1, 0); + glVertex2i(sButton, 125); + glTexCoord2f(1, 1); + glVertex2i(sButton, 200); + glTexCoord2f(0, 1); + glVertex2i(0, 200); + glEnd(); + + MenuQuitTexture.Bind(); + glTranslated(0, -100, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 100); + glTexCoord2f(1, 0); + glVertex2i(sButton, 100); + glTexCoord2f(1, 1); + glVertex2i(sButton, 200); + glTexCoord2f(0, 1); + glVertex2i(0, 200); + glEnd(); + + } + else + { + MenuOptionsTexture.Bind(); + glTranslated(200, 0, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 0); + glTexCoord2f(1, 0); + glVertex2i(sTitle, 0); + glTexCoord2f(1, 1); + glVertex2i(sTitle, 200); + glTexCoord2f(0, 1); + glVertex2i(0, 200); + glEnd(); + + MusicTexture.Bind(); + glTranslated(200, 200, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 125); + glTexCoord2f(1, 0); + glVertex2i(sButton, 125); + glTexCoord2f(1, 1); + glVertex2i(sButton, 200); + glTexCoord2f(0, 1); + glVertex2i(0, 200); + glEnd(); + + OnOffBtnTexture.Bind(); + glTranslated(200, 0, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 125); + glTexCoord2f(1, 0); + glVertex2i(sButton, 125); + glTexCoord2f(1, 1); + glVertex2i(sButton, 200); + glTexCoord2f(0, 1); + glVertex2i(0, 200); + glEnd(); + + BackBtnTexture.Bind(); + glTranslated(-375, 175, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 140); + glTexCoord2f(1, 0); + glVertex2i(sButton, 140); + glTexCoord2f(1, 1); + glVertex2i(sButton, 200); + glTexCoord2f(0, 1); + glVertex2i(0, 200); + glEnd(); + } + + //glEnable(GL_LIGHTING); + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); + ShowCursor(); +} + +void Engine::DrawOption() +{ + static const int sTitle = 400; + static const int sButton = 225; + + int centerX = Width() * 0.5f; + int centerY = Height() * 0.5f; + + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + MenuBGFlouTexture.Bind(); + glLoadIdentity(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(0, 0); + glTexCoord2f(1, 0); glVertex2i(Width(), 0); + glTexCoord2f(1, 1); glVertex2i(Width(), Height()); + glTexCoord2f(0, 1); glVertex2i(0, Height()); + glEnd(); + + glColor4f(0.85f, 0.95f, 0.0f, 1.0f); + m_textureOptions.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.175, centerY + Height() * 0.35); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.175, centerY + Height() * 0.35); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.175, centerY + Height() * 0.45); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.175, centerY + Height() * 0.45); + glEnd(); + + if (m_selectedOption == 0) { + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + } + m_textureVolume.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.35, centerY + Height() * 0.2); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.2); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.35, centerY + Height() * 0.25); + glEnd(); + + glColor4f(0.85f, 0.95f, 0.0f, 1.0f); + if (m_selectedOption == 1) { + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + } + m_textureGraphiques.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.4, centerY + Height() * 0.05); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.05); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.2, centerY + Height() * 0.1); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.4, centerY + Height() * 0.1); + glEnd(); + + glColor4f(0.85f, 0.95f, 0.0f, 1.0f); + if (m_selectedOption == 2) { + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + } + m_textureGameplay.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.375, centerY - Height() * 0.1); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.2, centerY - Height() * 0.1); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.2, centerY - Height() * 0.05); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.375, centerY - Height() * 0.05); + glEnd(); + + // Séparateur + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.175, centerY - Height() * 0.1); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.1751, centerY - Height() * 0.1); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.1751, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.175, centerY + Height() * 0.25); + glEnd(); + + glColor4f(0.85f, 0.95f, 0.0f, 1.0f); + m_textureRetour.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.25); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.075, centerY - Height() * 0.25); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.075, centerY - Height() * 0.2); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.2); + glEnd(); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + if (m_selectedOption == 0) { + DisplayAudioMenu(centerX, centerY); + } + else if (m_selectedOption == 1) { + DisplayGraphicsMenu(centerX, centerY); + } + else if (m_selectedOption == 2) { + DisplayGameplayMenu(centerX, centerY); + } + + glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); + + glEnable(GL_STENCIL_TEST); + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::DisplayAudioMenu(float centerX, float centerY) { + float minBar = centerX - Width() * 0.15; + float maxBar = centerX + Width() * 0.3; + float percentPosX = centerX + Width() * 0.31f; + + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_texturePrincipal.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.025, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.025, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); + + float principalBottom = centerY + Height() * 0.165f; + float principalTop = centerY + Height() * 0.2f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, principalBottom, principalTop); + RedrawSlider(centerX, centerY, m_volPrincipal, minBar, maxBar, principalBottom, principalTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, principalBottom, minBar, maxBar, m_volPrincipal); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureMusique.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.09); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.05, centerY + Height() * 0.09); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.05, centerY + Height() * 0.125); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.125); + glEnd(); + + float musiqueBottom = centerY + Height() * 0.04f; + float musiqueTop = centerY + Height() * 0.075f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, musiqueBottom, musiqueTop); + RedrawSlider(centerX, centerY, m_volMusique, minBar, maxBar, musiqueBottom, musiqueTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, musiqueBottom, minBar, maxBar, m_volMusique); + + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureEffets.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.035); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.035); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.075, centerY - Height() * 0.00001); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.00001); + glEnd(); + + float effectsBottom = centerY - Height() * 0.085f; + float effectsTop = centerY - Height() * 0.05f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, effectsBottom, effectsTop); + RedrawSlider(centerX, centerY, m_volEffets, minBar, maxBar, effectsBottom, effectsTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, effectsBottom, minBar, maxBar, m_volEffets); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +} + +void Engine::DisplayGraphicsMenu(float centerX, float centerY) { + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureResolution.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); + + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + m_textureHd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.125); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.05, centerY + Height() * 0.125); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.05, centerY + Height() * 0.15); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.15); + glEnd(); + + m_textureFhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.075); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.075); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.1); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.1); + glEnd(); + + m_textureQhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.025); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.025); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.05); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.05); + glEnd(); + + m_textureUhd.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY - Height() * 0.025); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.015, centerY - Height() * 0.025); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.015, centerY); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY); + glEnd(); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + + float heightRatioBottom = 0.125f; + float heightRatioTop = 0.15; + + // Checkboxes + for (int i = 0; i < 4; i++) { + if (static_cast(m_resolution) == i) { + m_textureChecked.Bind(); + } + else { + m_textureCheck.Bind(); + } + + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX + Width() * 0.075, centerY + Height() * heightRatioBottom); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.09, centerY + Height() * heightRatioBottom); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.09, centerY + Height() * heightRatioTop); + glTexCoord2f(0, 1); glVertex2i(centerX + Width() * 0.075, centerY + Height() * heightRatioTop); + glEnd(); + + heightRatioBottom -= 0.05f; + heightRatioTop -= 0.05f; + } + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +} + +void Engine::DisplayGameplayMenu(float centerX, float centerY) { + float minBar = centerX - Width() * 0.15; + float maxBar = centerX + Width() * 0.3; + float percentPosX = centerX + Width() * 0.31f; + + glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureSensibilite.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); + + float sensibleBottom = centerY + Height() * 0.165f; + float sensibleTop = centerY + Height() * 0.2f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, sensibleBottom, sensibleTop); + RedrawSlider(centerX, centerY, m_volSensible, minBar, maxBar, sensibleBottom, sensibleTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, sensibleBottom, minBar, maxBar, m_volSensible); + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); +} + +void Engine::DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue) { + glColor4f(0.0f, 0.0f, 0.0f, 1.0f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(minVal, bottomSideValue); + glTexCoord2f(1, 0); glVertex2i(maxVal, bottomSideValue); + glTexCoord2f(1, 1); glVertex2i(maxVal, topSideValue); + glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue); + glEnd(); +} + +void Engine::DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value) { + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + + float percentage = (value / (maxVal - minVal)) * 100; + + if (percentage < 0.0f) { + percentage = 0.0f; + } + else if (percentage > 100.0f) { + percentage = 100.0f; + } + + m_textureFont.Bind(); + std::ostringstream ss; + ss.str(""); + ss << std::fixed << std::setprecision(2); + ss << percentage << "%"; + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + PrintText(posX, posY, ss.str(), 2.0f); + + glDisable(GL_BLEND); +} + +void Engine::RedrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue) { + if (value < 0.0f) { + value = 0.0f; + } + else if (value > (maxVal - minVal)) { + value = (maxVal - minVal); + } + + if (value >= 0.0f && value <= (maxVal - minVal)) { + glColor4f(0.0f, 1.0f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(minVal, bottomSideValue); + glTexCoord2f(1, 0); glVertex2i(minVal + value, bottomSideValue); + glTexCoord2f(1, 1); glVertex2i(minVal + value, topSideValue); + glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue); + glEnd(); + } +} + void Engine::InstantDamage() { m_player.InflictDamage(0.10f); @@ -693,9 +951,7 @@ void Engine::DisplayPovGun() { glPopMatrix(); } -void Engine::DisplayCurrentItem() { -} - +void Engine::DisplayCurrentItem() {} void Engine::DisplayHud(int timer) { glBindTexture(GL_TEXTURE_2D, 0); @@ -1046,6 +1302,7 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul float baseCharSize = 20 + (24 - 20) * (windowWidth - 1600) / (1920 - 1600); float charSize = baseCharSize * charSizeMultiplier; + glPushMatrix(); glLoadIdentity(); glTranslated(x, y, 0); @@ -1063,6 +1320,7 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul glTranslated(0.5555f * charSize, 0, 0); } + glPopMatrix(); } int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } @@ -1082,6 +1340,10 @@ int Engine::GetCountdown(float elapsedTime) { return m_countdown - (int)m_time; } +int Engine::GetOptionsChoice() { + return m_selectedOption; +} + void Engine::Render(float elapsedTime) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); @@ -1307,7 +1569,7 @@ void Engine::Render(float elapsedTime) { } else if (m_gamestate == GameState::SINGLEMULTI) DisplaySingleOrMultiplayerMenu(); - else if (m_gamestate == GameState::OPTIONS) + else if (m_gamestate == GameState::OPTIONS || m_gamestate == GameState::PAUSE) { DrawOption(); } @@ -1404,7 +1666,6 @@ void Engine::KeyReleaseEvent(unsigned char key) { break; case 2: // C - Toggle crosshair m_displayCrosshair = !m_displayCrosshair; - std::cout << "DISPLAY CROSSHAIR " << (m_displayCrosshair ? "enabled" : "disabled") << std::endl; break; case 3: // D - Stop droite m_keyD = false; @@ -1477,17 +1738,37 @@ void Engine::KeyReleaseEvent(unsigned char key) { } void Engine::MouseMoveEvent(int x, int y) { - m_player.TurnLeftRight(x - (Width() / 2)); - m_player.TurnTopBottom(y - (Height() / 2)); + if (m_gamestate == GameState::PLAY) { + m_player.TurnLeftRight(x - (Width() / 2)); + m_player.TurnTopBottom(y - (Height() / 2)); - // Centrer la souris seulement si elle n'est pas d�j� centr�e - // Il est n�cessaire de faire la v�rification pour �viter de tomber - // dans une boucle infinie o� l'appel � CenterMouse g�n�re un - // MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre - // MouseMoveEvent, etc - if (x == (Width() / 2) && y == (Height() / 2)) - return; + // Centrer la souris seulement si elle n'est pas d�j� centr�e + // Il est n�cessaire de faire la v�rification pour �viter de tomber + // dans une boucle infinie o� l'appel � CenterMouse g�n�re un + // MouseMoveEvent, qui rapelle CenterMouse qui rapelle un autre + // MouseMoveEvent, etc + if (x == (Width() / 2) && y == (Height() / 2)) + return; + } + else if (m_gamestate == GameState::OPTIONS) { + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; + float leftBar = centerX - Width() * 0.15f; + float rightBar = centerX + Width() * 0.3f; + if (m_selectedOption == 0 && m_selectedPrincipalBar) { + m_volPrincipal = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedMusiqueBar) { + m_volMusique = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedEffetsBar) { + m_volEffets = x - leftBar; + } + else if (m_selectedOption == 2 && m_selectedSensibleBar) { + m_volSensible = x - leftBar; + } + } } void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { @@ -1524,6 +1805,104 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 450 && m_mousemy <= 500)) m_gamestate = GameState::QUIT; } + else if (m_gamestate == GameState::OPTIONS) { + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; + + float leftVol = centerX - Width() * 0.35f; + float rightVol = centerX - Width() * 0.2f; + float topVol = (Height() * 0.25f) + ((Height() * 0.25f) - (Height() * 0.2f)); + float bottomVol = (Height() * 0.2f) + ((Height() * 0.25f) - (Height() * 0.2f)); + + float leftGraph = centerX - Width() * 0.4f; + float rightGraph = centerX - Width() * 0.2f; + float topGraph = centerY - Height() * 0.05f; + float bottomGraph = centerY - Height() * 0.1f; + + float leftGameplay = centerX - Width() * 0.375f; + float rightGameplay = centerX - Width() * 0.2f; + float topGameplay = centerY + Height() * 0.1f; + float bottomGameplay = centerY + Height() * 0.05f; + + float leftRetour = centerX - Width() * 0.075f; + float rightRetour = centerX + Width() * 0.075f; + float topRetour = centerY + Height() * 0.25f; + float bottomRetour = centerY + Height() * 0.2f; + + if (x > leftVol && x < rightVol && y > bottomVol && y < topVol) { + m_selectedOption = 0; // Volume + } + else if (x > leftGraph && x < rightGraph && y > bottomGraph && y < topGraph) { + m_selectedOption = 1; // Graphics + } + else if (x > leftGameplay && x < rightGameplay && y > bottomGameplay && y < topGameplay) { + m_selectedOption = 2; // Gameplay + } + else if (x > leftRetour && x < rightRetour && y > bottomRetour && y < topRetour) { + m_gamestate = GameState::MAIN_MENU; + } + + // Volume + float leftBar = centerX - Width() * 0.15f; + float rightBar = centerX + Width() * 0.3f; + + float topBarPrincipal = centerY - Height() * 0.165f; + float bottomBarPrincipal = centerY - Height() * 0.2f; + + float topBarMusique = centerY - Height() * 0.0415f; + float bottomBarMusique = centerY - Height() * 0.075f; + + float topBarEffets = centerY + Height() * 0.085f; + float bottomBarEffets = centerY + Height() * 0.05f; + + if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) { + m_volPrincipal = x - leftBar; + m_selectedPrincipalBar = true; + } + else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarMusique && y < topBarMusique) { + m_volMusique = x - leftBar; + m_selectedMusiqueBar = true; + } + else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarEffets && y < topBarEffets) { + m_volEffets = x - leftBar; + m_selectedEffetsBar = true; + } + + // Resolution + float leftChk = centerX + Width() * 0.075f; + float rightChk = centerX + Width() * 0.09f; + + float topChkHD = centerY - Height() * 0.125f; + float bottomChkHD = centerY - Height() * 0.155f; + + float topChkFHD = centerY - Height() * 0.0725f; + float bottomChkFHD = centerY - Height() * 0.1f; + + float topChkQHD = centerY - Height() * 0.025f; + float bottomChkQHD = centerY - Height() * 0.05f; + + float topChkUHD = centerY + Height() * 0.025f; + float bottomChkUHD = centerY; + + if (m_selectedOption == 1 && leftChk && x < rightChk && y > bottomChkHD && y < topChkHD) { + m_resolution = HD; + } + else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkFHD && y < topChkFHD) { + m_resolution = FHD; + } + else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkQHD && y < topChkQHD) { + m_resolution = QHD; + } + else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkUHD && y < topChkUHD) { + m_resolution = UHD; + } + + // Gameplay + if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) { + m_volSensible = x - leftBar; + m_selectedSensibleBar = true; + } + } else if (m_gamestate == GameState::SINGLEMULTI) { float buttonWidthProportion = 0.4f; @@ -1542,7 +1921,6 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { if (m_mousemx >= buttonPosX && m_mousemx <= (buttonPosX + buttonWidth) && adjustedMouseY >= buttonSinglePosY && adjustedMouseY <= (buttonSinglePosY + buttonHeight)) { - std::cout << "Single Player button clicked" << std::endl; m_soloMultiChoiceMade = true; m_gamestate = GameState::PLAY; } @@ -1550,7 +1928,6 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { else if (m_mousemx >= buttonPosX && m_mousemx <= (buttonPosX + buttonWidth) && adjustedMouseY >= buttonMultiPosY && adjustedMouseY <= (buttonMultiPosY + buttonHeight)) { - std::cout << "Multiplayer button clicked" << std::endl; m_soloMultiChoiceMade = true; m_gamestate = GameState::PLAY; } @@ -1562,6 +1939,10 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) { case MOUSE_BUTTON_LEFT: m_mouseL = false; m_block = false; + m_selectedPrincipalBar = false; + m_selectedMusiqueBar = false; + m_selectedEffetsBar = false; + m_selectedSensibleBar = false; break; case MOUSE_BUTTON_RIGHT: m_mouseR = false; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 3d6823f..093c4cb 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -24,7 +24,7 @@ #include "renderer.h" #include "remoteplayer.h" #include "booster.h" - +#include "settings.h" class Engine : public OpenglContext { public: @@ -47,6 +47,7 @@ public: private: int GetFps(float elapsedTime) const; int GetCountdown(float elapsedTime); + int GetOptionsChoice(); bool LoadTexture(Texture& texture, const std::string& filename, bool useMipmaps = true, bool stopOnError = true); @@ -54,19 +55,21 @@ private: void SystemNotification(std::string systemLog); void KillNotification(Player killer, Player killed); void DisplayNotification(std::string message); - void ProcessNotificationQueue(); void DisplayCrosshair(); void DisplayPovGun(); void DisplayCurrentItem(); void DisplayHud(int timer); void DisplayInfo(float elapsedTime, BlockType bloc); void DisplaySingleOrMultiplayerMenu(); + void DisplayAudioMenu(float centerX, float centerY); + void DisplayGraphicsMenu(float centerX, float centerY); + void DisplayGameplayMenu(float centerX, float centerY); + void DrawSliderBackground(float centerX, float centerY, float minVal, float maxVal, float bottomSideValue, float topSideValue); + void DisplayBarPercentValue(float centerX, float centerY, float posX, float posY, float minVal, float maxVal, float value); + void RedrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue); void DrawHud(float elapsedTime, BlockType bloc); void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); - - - - + void ProcessNotificationQueue(); Connector m_conn; Shader m_shader01; @@ -88,6 +91,22 @@ private: Texture m_textureSoloText; Texture m_textureMultiText; Texture m_textureTitle; + Texture m_textureOptions; + Texture m_textureRetour; + Texture m_textureVolume; + Texture m_textureMusique; + Texture m_textureGraphiques; + Texture m_textureSensibilite; + Texture m_textureResolution; + Texture m_texturePrincipal; + Texture m_textureEffets; + Texture m_textureGameplay; + Texture m_textureHd; + Texture m_textureFhd; + Texture m_textureQhd; + Texture m_textureUhd; + Texture m_textureCheck; + Texture m_textureChecked; TextureAtlas::TextureIndex texBoostHeal; @@ -99,6 +118,7 @@ private: irrklang::ISound *m_whoosh[MAX_BULLETS]; Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); + Settings m_parameters = Settings(m_audio); Bullet* m_bullets[MAX_BULLETS]; @@ -107,11 +127,12 @@ private: std::chrono::high_resolution_clock::time_point m_startTime; //Menu - enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE, SINGLEMULTI }; + enum class GameState: uint8_t { MAIN_MENU, OPTIONS, SETTINGS, QUIT, NEWG, PLAY, PAUSE, SINGLEMULTI }; GameState m_gamestate = GameState::MAIN_MENU; Texture MenuTitleTexture; Texture MenuBGTexture; + Texture MenuBGFlouTexture; Texture MenuBGOptionTexture; Texture MenuStartTexture; Texture MenuQuitTexture; @@ -122,20 +143,31 @@ private: Texture OnOffBtnTexture;//TODO Texture BackBtnTexture;//TODO + Resolution m_resolution = HD; float m_scale; float m_time = 0; float m_time_SplashScreen = 0; float m_titleX = 0; float m_titleY = 0; - float m_Width = 0; - float m_Height = 0; int m_renderCount = 0; int m_countdown = COUNTDOWN; int m_nbReductionChunk = 4; int m_timerReductionChunk = 30; + float m_volPrincipal = 0.0f; + float m_volMusique = 0.0f; + float m_volEffets = 0.0f; + float m_volSensible = 0.0f; + + int m_selectedOption = 0; + + bool m_selectedPrincipalBar = false; + bool m_selectedMusiqueBar = false; + bool m_selectedEffetsBar = false; + bool m_selectedSensibleBar = false; + bool m_damage = false; bool m_wireframe = false; diff --git a/SQCSim2021/media/textures/BackgroundMenuFlou.png b/SQCSim2021/media/textures/BackgroundMenuFlou.png new file mode 100644 index 0000000..84840f7 Binary files /dev/null and b/SQCSim2021/media/textures/BackgroundMenuFlou.png differ diff --git a/SQCSim2021/media/textures/Bouton/BasicPlay.png b/SQCSim2021/media/textures/Bouton/BasicPlay.png deleted file mode 100644 index 109f65a..0000000 Binary files a/SQCSim2021/media/textures/Bouton/BasicPlay.png and /dev/null differ diff --git a/SQCSim2021/media/textures/Bouton/BasicQuit.png b/SQCSim2021/media/textures/Bouton/BasicQuit.png deleted file mode 100644 index db7ad29..0000000 Binary files a/SQCSim2021/media/textures/Bouton/BasicQuit.png and /dev/null differ diff --git a/SQCSim2021/media/textures/Buttons/check.png b/SQCSim2021/media/textures/Buttons/check.png new file mode 100644 index 0000000..9b3968b Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/check.png differ diff --git a/SQCSim2021/media/textures/Buttons/checked.png b/SQCSim2021/media/textures/Buttons/checked.png new file mode 100644 index 0000000..2debe55 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/checked.png differ diff --git a/SQCSim2021/media/textures/Buttons/effets.png b/SQCSim2021/media/textures/Buttons/effets.png new file mode 100644 index 0000000..30c8be6 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/effets.png differ diff --git a/SQCSim2021/media/textures/Buttons/fhd.png b/SQCSim2021/media/textures/Buttons/fhd.png new file mode 100644 index 0000000..0e78428 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/fhd.png differ diff --git a/SQCSim2021/media/textures/Buttons/gameplay.png b/SQCSim2021/media/textures/Buttons/gameplay.png new file mode 100644 index 0000000..687c857 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/gameplay.png differ diff --git a/SQCSim2021/media/textures/Buttons/graphiques.png b/SQCSim2021/media/textures/Buttons/graphiques.png new file mode 100644 index 0000000..860179f Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/graphiques.png differ diff --git a/SQCSim2021/media/textures/Buttons/hd.png b/SQCSim2021/media/textures/Buttons/hd.png new file mode 100644 index 0000000..9594d91 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/hd.png differ diff --git a/SQCSim2021/media/textures/Buttons/musique.png b/SQCSim2021/media/textures/Buttons/musique.png new file mode 100644 index 0000000..37707b2 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/musique.png differ diff --git a/SQCSim2021/media/textures/Buttons/options.png b/SQCSim2021/media/textures/Buttons/options.png new file mode 100644 index 0000000..5c15729 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/options.png differ diff --git a/SQCSim2021/media/textures/Buttons/principal.png b/SQCSim2021/media/textures/Buttons/principal.png new file mode 100644 index 0000000..ad06d7d Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/principal.png differ diff --git a/SQCSim2021/media/textures/Buttons/qhd.png b/SQCSim2021/media/textures/Buttons/qhd.png new file mode 100644 index 0000000..1da6626 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/qhd.png differ diff --git a/SQCSim2021/media/textures/Buttons/resolution.png b/SQCSim2021/media/textures/Buttons/resolution.png new file mode 100644 index 0000000..8003a75 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/resolution.png differ diff --git a/SQCSim2021/media/textures/Buttons/retour.png b/SQCSim2021/media/textures/Buttons/retour.png new file mode 100644 index 0000000..8f676d5 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/retour.png differ diff --git a/SQCSim2021/media/textures/Buttons/sensibilite.png b/SQCSim2021/media/textures/Buttons/sensibilite.png new file mode 100644 index 0000000..47208b6 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/sensibilite.png differ diff --git a/SQCSim2021/media/textures/Buttons/uhd.png b/SQCSim2021/media/textures/Buttons/uhd.png new file mode 100644 index 0000000..696a558 Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/uhd.png differ diff --git a/SQCSim2021/media/textures/Buttons/volume.png b/SQCSim2021/media/textures/Buttons/volume.png new file mode 100644 index 0000000..043432c Binary files /dev/null and b/SQCSim2021/media/textures/Buttons/volume.png differ diff --git a/SQCSim2021/settings.cpp b/SQCSim2021/settings.cpp new file mode 100644 index 0000000..b84effc --- /dev/null +++ b/SQCSim2021/settings.cpp @@ -0,0 +1,146 @@ +#include "settings.h" + +Settings::Settings(Audio& audio) + : m_audio(audio), + m_mainVolume(0.5f), + m_musicVolume(0.5f), + m_sfxVolume(0.5f), + m_resolution(FHD), + m_fullscreen(false), + m_brightness(0.5f), + m_contrast(0.5f), + m_mouseSensitivity(0.5f) { + ApplyResolution(m_resolution); +} + +void Settings::SaveFile(const std::string& filename) { + std::ofstream file(filename); + if (!file.is_open()) { + std::cerr << "Failed to open file for saving parameters" << std::endl; + return; + } + + file << m_mainVolume << '\n'; + file << m_musicVolume << '\n'; + file << m_sfxVolume << '\n'; + + file << static_cast(m_resolution) << '\n'; + file << m_fullscreen << '\n'; + file << m_brightness << '\n'; + file << m_contrast << '\n'; + + file << m_mouseSensitivity << '\n'; + + file.close(); +} + +void Settings::LoadFile(const std::string& filename) { + std::ifstream file(filename); + if (!file.is_open()) { + std::cerr << "Failed to open file for loading parameters" << std::endl; + return; + } + + file >> m_mainVolume; + file >> m_musicVolume; + file >> m_sfxVolume; + + int resolutionValue; + file >> resolutionValue; + m_resolution = static_cast(resolutionValue); + + file >> m_fullscreen; + file >> m_brightness; + file >> m_contrast; + + file >> m_mouseSensitivity; + + file.close(); +} + +float Settings::GetMainVolume() const { + return m_mainVolume; +} + +void Settings::SetMainVolume(float volume) { + m_mainVolume = volume; +} + +void Settings::GetMusicVolume() { + m_musicVolume = m_audio.GetMusicVolume(); +} + +void Settings::SetMusicVolume(float volume) { + m_musicVolume = volume; +} + +float Settings::GetSfxVolume() const { + return m_sfxVolume; +} + +void Settings::SetSfxVolume(float volume) { + m_sfxVolume = volume; +} + +float Settings::GetBrightness() const { + return m_brightness; +} + +void Settings::SetBrightness(float brightness) { + m_brightness = brightness; +} + +float Settings::GetContrast() const { + return m_contrast; +} + +void Settings::SetContrast(float contrast) { + m_contrast = contrast; +} + +bool Settings::GetFullscreen() const { + return m_fullscreen; +} + +void Settings::SetFullscreen(bool fullscreen) { + m_fullscreen = fullscreen; +} + +const Resolution& Settings::GetResolution() const { + return m_resolution; +} + +void Settings::SetResolution(const Resolution& resolution) { + m_resolution = resolution; +} + +float Settings::GetMouseSensitivity() const { + return m_mouseSensitivity; +} + +void Settings::SetMouseSensitivity(float sensitivity) { + m_mouseSensitivity = sensitivity; +} + +void Settings::ApplyResolution(Resolution resolution) { + switch (resolution) { + case HD: + m_rezWidth = 1280; + m_rezHeight = 720; + break; + case FHD: + m_rezWidth = 1920; + m_rezHeight = 1080; + break; + case QHD: + m_rezWidth = 2560; + m_rezHeight = 1440; + break; + case UHD: + m_rezWidth = 3840; + m_rezHeight = 2160; + break; + default: + break; + } +} diff --git a/SQCSim2021/settings.h b/SQCSim2021/settings.h new file mode 100644 index 0000000..e871529 --- /dev/null +++ b/SQCSim2021/settings.h @@ -0,0 +1,70 @@ +#ifndef SETTINGS_H__ +#define SETTINGS_H__ + +#include +#include +#include +#include +#include + +#include "define.h" +#include "audio.h" + +class Settings { +public: + Settings(Audio& audio); + + void SaveFile(const std::string& filename); + void LoadFile(const std::string& filename); + + // Audio + float GetMainVolume() const; + void SetMainVolume(float volume); + + void GetMusicVolume(); + void SetMusicVolume(float volume); + + float GetSfxVolume() const; + void SetSfxVolume(float volume); + + // Graphic + float GetBrightness() const; + void SetBrightness(float brightness); + + float GetContrast() const; + void SetContrast(float contrast); + + bool GetFullscreen() const; + void SetFullscreen(bool fullscreen); + + const Resolution& GetResolution() const; + void SetResolution(const Resolution& resolution); + + // Gameplay + float GetMouseSensitivity() const; + void SetMouseSensitivity(float sensitivity); + + void ApplyResolution(Resolution resolution); + +private: + + Audio& m_audio; + // Audio + float m_mainVolume; + float m_musicVolume; + float m_sfxVolume; + + // Graphic + Resolution m_resolution; + bool m_fullscreen; + int m_rezWidth; + int m_rezHeight; + float m_brightness; + float m_contrast; + + // Gameplay + float m_mouseSensitivity; +}; + + +#endif // PARAMETERS_H \ No newline at end of file