diff --git a/SQCSim-common/chunk.cpp b/SQCSim-common/chunk.cpp index 9fd6387..9f2e6f7 100644 --- a/SQCSim-common/chunk.cpp +++ b/SQCSim-common/chunk.cpp @@ -9,6 +9,10 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y //if (input.fail()) { OpenSimplexNoise::Noise simplex = OpenSimplexNoise::Noise(seed); m_blocks.Reset(BTYPE_AIR); + int ratio = 0; + + ratio = x * y % 7; + for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // Montagnes for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { @@ -47,8 +51,8 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y } } - int rnd = rand() % 15; - if (rnd == 4) + //int rnd = rand() % 15; + if (ratio == 1) for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { for (int iy = 0; iy < 14; ++iy) { @@ -57,16 +61,16 @@ Chunk::Chunk(unsigned int x, unsigned int y, int64_t seed) : m_posX(x), m_posY(y Structure(ix, iy, iz, 2); } } - if (rnd == 3) + if (ratio == 3) for (int ix = 0; ix < CHUNK_SIZE_Z; ++ix) // structure for (int iz = 0; iz < CHUNK_SIZE_X; ++iz) { for (int iy = 0; iy < 14; ++iy) { if (iz == 4) if (GetBlock(ix, iy, iz) == BTYPE_AIR) - Structure(ix, iy, iz, 2); + Structure(ix, iy, iz, 1); } } - if (rnd == 6) + if (ratio == 5) for (int ix = 0; ix < CHUNK_SIZE_X; ++ix) // structure for (int iz = 0; iz < CHUNK_SIZE_Z; ++iz) { for (int iy = 0; iy < 14; ++iy) { diff --git a/SQCSim-common/define.h b/SQCSim-common/define.h index b018971..685bf5d 100644 --- a/SQCSim-common/define.h +++ b/SQCSim-common/define.h @@ -52,6 +52,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 ec07173..cc5a3d1 100644 --- a/SQCSim2021/define.h +++ b/SQCSim2021/define.h @@ -43,7 +43,22 @@ #define SHADER_PATH "./media/shaders/" #define AUDIO_PATH "./media/audio/" #define CHUNK_PATH "./media/chunks/" -#define MENU_ITEM_PATH "./media/menu_items/" #define BOOSTER_TEXTURE_PATH "./media/textures/Booster/" +enum GameState { + MAIN_MENU, + SPLASH, + OPTIONS, + QUIT, + PLAY, + PAUSE +}; + +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 18a170a..1a5bbd6 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -13,13 +13,12 @@ struct Notification { float displayStartTime = 0.0f; }; - // Use a queue to manage notifications //std::queue notificationQueue; // Use a vector to manage notifications std::vector notifications; -Engine::Engine() : m_remotePlayer(&m_pinfo), m_pinfo(){} +Engine::Engine() : m_remotePlayer(&m_pinfo), m_pinfo() {} Engine::~Engine() { m_world.CleanUpWorld(m_renderCount, true); @@ -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() { uint64_t seed = SEED; @@ -330,10 +36,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(); @@ -434,26 +138,42 @@ void Engine::LoadResource() { glBlendEquation(GL_FUNC_SUBTRACT); LoadTexture(m_skybox.GetTexture(), TEXTURE_PATH "skybox.png", true); - //LoadTexture(m_skybox2.GetTexture(), TEXTURE_PATH "skybox.png", true); LoadTexture(m_textureCrosshair, TEXTURE_PATH "cross.bmp", true); LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true); LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false); LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false); - LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false); - LoadTexture(m_textureSoloText, TEXTURE_PATH "single_player.png", false); - 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(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); - LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); + LoadTexture(m_textureMainMenu, TEXTURE_PATH "menus/backgrounds/bgMainMenu.png", false); + LoadTexture(m_texturePauseMenu, TEXTURE_PATH "menus/backgrounds/bgPause.png", false); + LoadTexture(m_textureOptionsMenu, TEXTURE_PATH "menus/backgrounds/bgOptions.png", false); + LoadTexture(m_textureSplashScreen, TEXTURE_PATH "menus/backgrounds/bgSplash.png", false); - LoadTexture(MenuBGOptionTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png"); + LoadTexture(m_textureCheck, TEXTURE_PATH "menus/others/check.png", false); + LoadTexture(m_textureChecked, TEXTURE_PATH "menus/others/checked.png", false); - LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png"); - LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png"); - LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png"); - LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png"); + LoadTexture(m_textureOptAudio, TEXTURE_PATH "menus/buttons/options/optAudio.png", false); + LoadTexture(m_textureOptBack, TEXTURE_PATH "menus/buttons/options/optBack.png", false); + LoadTexture(m_textureOptGameplay, TEXTURE_PATH "menus/buttons/options/optGameplay.png", false); + LoadTexture(m_textureOptGraphics, TEXTURE_PATH "menus/buttons/options/optGraphics.png", false); + LoadTexture(m_textureOptMain, TEXTURE_PATH "menus/buttons/options/optMain.png", false); + LoadTexture(m_textureOptMusic, TEXTURE_PATH "menus/buttons/options/optMusic.png", false); + LoadTexture(m_textureOptOptions, TEXTURE_PATH "menus/buttons/options/optOptions.png", false); + LoadTexture(m_textureOptResolution, TEXTURE_PATH "menus/buttons/options/optResolution.png", false); + LoadTexture(m_textureOptSensitivity, TEXTURE_PATH "menus/buttons/options/optSensitivity.png", false); + LoadTexture(m_textureOptSfx, TEXTURE_PATH "menus/buttons/options/optSfx.png", false); + + LoadTexture(m_textureHd, TEXTURE_PATH "menus/labels/labelHd.png", false); + LoadTexture(m_textureFhd, TEXTURE_PATH "menus/labels/labelFhd.png", false); + LoadTexture(m_textureQhd, TEXTURE_PATH "menus/labels/labelQhd.png", false); + LoadTexture(m_textureUhd, TEXTURE_PATH "menus/labels/labelUhd.png", false); + LoadTexture(m_textureMenuTitle, TEXTURE_PATH "menus/labels/labelTitle.png", false); + + LoadTexture(m_textureMenuBack, TEXTURE_PATH "menus/buttons/main/mainBack.png", false); + LoadTexture(m_textureMenuMulti, TEXTURE_PATH "menus/buttons/main/mainMulti.png", false); + LoadTexture(m_textureMenuOptions, TEXTURE_PATH "menus/buttons/main/mainOptions.png", false); + LoadTexture(m_textureMenuPlay, TEXTURE_PATH "menus/buttons/main/mainPlay.png", false); + LoadTexture(m_textureMenuQuit, TEXTURE_PATH "menus/buttons/main/mainQuit.png", false); + LoadTexture(m_textureMenuSingle, TEXTURE_PATH "menus/buttons/main/mainSingle.png", false); TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); @@ -465,7 +185,6 @@ void Engine::LoadResource() { TextureAtlas::TextureIndex texBoostSpd = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterBleu.png"); TextureAtlas::TextureIndex texBoostInv = m_textureAtlas.AddTexture(BOOSTER_TEXTURE_PATH "BoosterJaune.png"); - //AJOUTER LES TEXTURES DANS L'ORDRE DE L'ÉNUM //STILL//STANDING @@ -563,8 +282,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; @@ -581,8 +298,9 @@ void Engine::LoadResource() { void Engine::UnloadResource() {} -void Engine::InstantDamage() -{ + + +void Engine::InstantDamage() { m_player.InflictDamage(0.10f); m_damage = false; } @@ -685,61 +403,7 @@ void Engine::DisplayCrosshair() { glEnd(); } -void Engine::DisplayPovGun() { - // Setter le blend function, tout ce qui sera noir sera transparent - glDisable(GL_STENCIL_TEST); - glDisable(GL_DEPTH_TEST); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glBlendEquation(GL_FUNC_ADD); - - glMatrixMode(GL_PROJECTION); - glPushMatrix(); - - glLoadIdentity(); - glOrtho(0, Width(), 0, Height(), -1, 1); - - glMatrixMode(GL_MODELVIEW); - glPushMatrix(); - - float baseXOffsetPercentage = 0.4958; - float baseWidthPercentage = 0.4688; - float baseHeightPercentage = 0.5787; - - float xTranslation = baseXOffsetPercentage * Width(); - float quadWidth = baseWidthPercentage * Width(); - float quadHeight = baseHeightPercentage * Height(); - - m_texturePovGun.Bind(); - glLoadIdentity(); - glTranslated(xTranslation, 0, 0); - glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(quadWidth, 0); - glTexCoord2f(1, 1); - glVertex2i(quadWidth, quadHeight); - glTexCoord2f(0, 1); - glVertex2i(0, quadHeight); - glEnd(); - - // Reset du blend function - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); - glBlendEquation(GL_FUNC_SUBTRACT); - - glEnable(GL_STENCIL_TEST); - glEnable(GL_DEPTH_TEST); - - glMatrixMode(GL_PROJECTION); - glPopMatrix(); - glMatrixMode(GL_MODELVIEW); - glPopMatrix(); -} - -void Engine::DisplayCurrentItem() { -} - +void Engine::DisplayCurrentItem() {} void Engine::DisplayHud(int timer) { glBindTexture(GL_TEXTURE_2D, 0); @@ -802,12 +466,12 @@ void Engine::DisplayHud(int timer) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage); - float equipWidthProportion = 0.8f; - float equipHeightProportion = 0.7f; + float equipWidthProportion = 0.8f; + float equipHeightProportion = 0.7f; float equipWidth = itemBackgroundWidth * equipWidthProportion; float equipHeight = itemBackgroundHeight * equipHeightProportion; float equipXOffset = itemBackgroundXPos + (itemBackgroundWidth - equipWidth) * 0.1f; - float equipYOffset = itemBackgroundYPos + (itemBackgroundHeight - equipHeight) * 0.75f; + float equipYOffset = itemBackgroundYPos + (itemBackgroundHeight - equipHeight) * 0.75f; glTranslatef(equipXOffset, equipYOffset, 0); @@ -835,7 +499,7 @@ void Engine::DisplayHud(int timer) { ss.str(""); ss << m_player.GetHP() * 100 << "%"; PrintText(itemBackgroundXPos * 5.25f, fUsernamePosY, ss.str(), 1.5f); - + float countdownXOffset = Width() * 0.2f; float countdownYOffset = Height() * 0.1f; float countdownXPos = Width() - countdownXOffset; @@ -847,6 +511,169 @@ void Engine::DisplayHud(int timer) { PrintText(countdownXPos, countdownYPos, ss.str(), 2.0f); } +void Engine::DrawHud(float elapsedTime, BlockType bloc) { + // Setter le blend function, tout ce qui sera noir sera transparent + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendEquation(GL_FUNC_ADD); + glEnable(GL_BLEND); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + int timer = GetCountdown(elapsedTime); + for (int i = 1; i < WORLD_SIZE_X; i++) { + if (timer <= COUNTDOWN - m_timerReductionChunk * i) { + m_world.RemoveChunk(m_nbReductionChunk * i); + m_renderer.RemoveChunk(m_nbReductionChunk * i); + } + } + if (m_keyK) { + SystemNotification(m_messageNotification); + m_keyK = false; + } + if (m_keyL) { + + KillNotification(m_player, m_player); + m_keyL = false; + } + + if (m_displayInfo) { + DisplayInfo(elapsedTime, bloc); + } + + if (m_displayHud) { + DisplayHud(timer); + } + + if (m_displayCrosshair) { + DisplayCrosshair(); + } + + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); + + glEnable(GL_STENCIL_TEST); + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::DisplayPovGun() { + // Setter le blend function, tout ce qui sera noir sera transparent + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + float baseXOffsetPercentage = 0.4958; + float baseWidthPercentage = 0.4688; + float baseHeightPercentage = 0.5787; + + float xTranslation = baseXOffsetPercentage * Width(); + float quadWidth = baseWidthPercentage * Width(); + float quadHeight = baseHeightPercentage * Height(); + + m_texturePovGun.Bind(); + glLoadIdentity(); + glTranslated(xTranslation, 0, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); + glVertex2i(0, 0); + glTexCoord2f(1, 0); + glVertex2i(quadWidth, 0); + glTexCoord2f(1, 1); + glVertex2i(quadWidth, quadHeight); + glTexCoord2f(0, 1); + glVertex2i(0, quadHeight); + glEnd(); + + // Reset du blend function + glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); + glBlendEquation(GL_FUNC_SUBTRACT); + + glEnable(GL_STENCIL_TEST); + glEnable(GL_DEPTH_TEST); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) { + float windowWidth = static_cast(Width()); + float windowHeight = static_cast(Height()); + + float posX = x * windowWidth; + float posY = y * windowHeight; + + float baseCharSize = 20 + (24 - 20) * (windowWidth - 1600) / (1920 - 1600); + float charSize = baseCharSize * charSizeMultiplier; + + glPushMatrix(); + glLoadIdentity(); + glTranslated(x, y, 0); + + for (unsigned int i = 0; i < t.length(); ++i) { + float left = (float)((t[i] - 32) % 16) / 16.f; + float top = (float)((t[i] - 32) / 16) / 16.f; + top += 0.5f; + + glBegin(GL_QUADS); + glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0); + glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(charSize, 0); + glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(charSize, charSize); + glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize); + glEnd(); + + glTranslated(0.5555f * charSize, 0, 0); + } + glPopMatrix(); +} + +int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } + +int Engine::GetCountdown(float elapsedTime) { + if (m_resetcountdown) { + m_nbReductionChunk = 4; + m_timerReductionChunk = 30; + m_countdown = m_time + COUNTDOWN; + m_resetcountdown = false; + } + if (m_countdown < m_time) + Stop(); + if (!m_stopcountdown) + m_time += elapsedTime; + return m_countdown - (int)m_time; +} + +int Engine::GetOptionsChoice() { + return m_selectedOption; +} + void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { m_textureFont.Bind(); std::ostringstream ss; @@ -901,17 +728,58 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { PrintText(fPosX, fPosYJump, ss.str()); } -void Engine::DisplaySingleOrMultiplayerMenu() { +void Engine::DisplaySplashScreen() { + glDisable(GL_LIGHTING); + glDisable(GL_DEPTH_TEST); + glDisable(GL_STENCIL_TEST); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + glOrtho(-Width() / 2, Width() / 2, -Height() / 2, Height() / 2, -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + int imageWidth = Width(); + int imageHeight = Height(); + + m_textureSplashScreen.Bind(); + 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(); + + glMatrixMode(GL_PROJECTION); + glPopMatrix(); + glMatrixMode(GL_MODELVIEW); + glPopMatrix(); +} + +void Engine::DisplayPauseMenu() { + + m_texturePauseMenu.Bind(); + 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(); +} + +void Engine::DisplayMainMenu() { GLint viewport[4]; glGetIntegerv(GL_VIEWPORT, viewport); + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); 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(); @@ -922,7 +790,7 @@ void Engine::DisplaySingleOrMultiplayerMenu() { glPushMatrix(); // Background - m_textureSoloMultiMenu.Bind(); + m_textureMainMenu.Bind(); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex2f(Width(), 0.0f); @@ -931,81 +799,31 @@ void Engine::DisplaySingleOrMultiplayerMenu() { glEnd(); // Title - float titleWidthProportion = 0.4f; - float titleHeightProportion = 0.4f; - float titleWidth = titleWidthProportion * Width(); - float titleHeight = titleHeightProportion * Height(); - float offsetTitleXFactor = 0.05f; - float offsetTitleYFactor = 0.05f; - m_titleX = (Width() - titleWidth) - (offsetTitleXFactor * Width()); - m_titleY = (Height() - titleHeight) - (offsetTitleYFactor * Height()); + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; - m_textureTitle.Bind(); glColor4f(1.0f, 0.5f, 0.0f, 1.0f); + m_textureMenuTitle.Bind(); glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(m_titleX, m_titleY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(m_titleX + titleWidth, m_titleY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(m_titleX + titleWidth, m_titleY + titleHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(m_titleX, m_titleY + titleHeight); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.05, centerY + Height() * 0.05); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.45, centerY + Height() * 0.05); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.45, centerY + Height() * 0.45); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.05, centerY + Height() * 0.45); glEnd(); - glBindTexture(GL_TEXTURE_2D, 0); + DrawButtonBackgrounds(centerX, centerY, 3); - - // Single Player and Multiplayer button background quads - float buttonWidthProportion = 0.4f; - float buttonHeightProportion = 0.075f; - float buttonWidth = buttonWidthProportion * Width(); - float buttonHeight = buttonHeightProportion * Height(); - float offsetSingleButtonXFactor = 0.075f; - float offsetSingleButtonYFactor = 0.05f; - - float buttonPosX = m_titleX; - float buttonSinglePosY = m_titleY - buttonHeight - (offsetSingleButtonYFactor * Height()); - float buttonMultiPosY = (buttonSinglePosY * 0.75); - - // Single Player background - glColor4f(1.0f, 1.0f, 1.0f, 0.5f); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(buttonPosX, buttonSinglePosY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY + buttonHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(buttonPosX, buttonSinglePosY + buttonHeight); - glEnd(); - - // Single Player text - m_textureSoloText.Bind(); - glColor4f(0.75f, 0.05f, 0.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(buttonPosX, buttonSinglePosY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY + buttonHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(buttonPosX, buttonSinglePosY + buttonHeight); - glEnd(); - - glBindTexture(GL_TEXTURE_2D, 0); - // Multi Player background - glColor4f(1.0f, 1.0f, 1.0f, 0.5f); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(buttonPosX, buttonMultiPosY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(buttonPosX + buttonWidth, buttonMultiPosY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(buttonPosX + buttonWidth, buttonMultiPosY + buttonHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(buttonPosX, buttonMultiPosY + buttonHeight); - glEnd(); - - // Multi Player text - m_textureMultiText.Bind(); - glColor4f(0.75f, 0.05f, 0.0f, 1.0f); - glBegin(GL_QUADS); - glTexCoord2f(0.0f, 0.0f); glVertex2f(buttonPosX, buttonMultiPosY); - glTexCoord2f(1.0f, 0.0f); glVertex2f(buttonPosX + buttonWidth, buttonMultiPosY); - glTexCoord2f(1.0f, 1.0f); glVertex2f(buttonPosX + buttonWidth, buttonMultiPosY + buttonHeight); - glTexCoord2f(0.0f, 1.0f); glVertex2f(buttonPosX, buttonMultiPosY + buttonHeight); - glEnd(); + if (m_gamestate == GameState::MAIN_MENU) { + if (m_selectedPlayOptions) { + DrawSingleMultiButtons(centerX, centerY); + } + else { + DrawMainMenuButtons(centerX, centerY); + } + } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); - // Reset the state glViewport(viewport[0], viewport[1], viewport[2], viewport[3]); glEnable(GL_STENCIL_TEST); @@ -1020,122 +838,379 @@ void Engine::DisplaySingleOrMultiplayerMenu() { ShowCursor(); } -void Engine::DrawHud(float elapsedTime, BlockType bloc) { - // Setter le blend function, tout ce qui sera noir sera transparent +void Engine::DrawMainMenuButtons(float centerX, float centerY) { + m_textureMenuPlay.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.01); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.01); + glEnd(); + + m_textureMenuOptions.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.11); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.11); + glEnd(); + + m_textureMenuQuit.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.21); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.21); + glEnd(); +} + +void Engine::DrawSingleMultiButtons(float centerX, float centerY) { + m_textureMenuSingle.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.06, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.44, centerY - Height() * 0.065); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.44, centerY - Height() * 0.01); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.06, centerY - Height() * 0.01); + glEnd(); + + m_textureMenuMulti.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.165); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.42, centerY - Height() * 0.11); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.08, centerY - Height() * 0.11); + glEnd(); + + m_textureMenuBack.Bind(); + glColor4f(0.75f, 0.05f, 0.0f, 1.0f); + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.265); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.34, centerY - Height() * 0.21); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.16, centerY - Height() * 0.21); + glEnd(); +} + +void Engine::DrawButtonBackgrounds(float centerX, float centerY, int iterations) { + glColor4f(1.0f, 1.0f, 1.0f, 0.5f); + glBindTexture(GL_TEXTURE_2D, 0); + + float bottomOffset = 0.075f; + float topOffset = 0.0f; + float distanceBetween = 0.1f; + + for (int i = 0; i < iterations; i++) { + glBegin(GL_QUADS); + glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX + Width() * 0.05, centerY - Height() * bottomOffset); + glTexCoord2f(1.0f, 0.0f); glVertex2f(centerX + Width() * 0.45, centerY - Height() * bottomOffset); + glTexCoord2f(1.0f, 1.0f); glVertex2f(centerX + Width() * 0.45, centerY - Height() * topOffset); + glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX + Width() * 0.05, centerY - Height() * topOffset); + glEnd(); + + bottomOffset += distanceBetween; + topOffset += distanceBetween; + } +} + +void Engine::DisplayOptionsMenu() { + static const int sTitle = 400; + static const int sButton = 225; + + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; + + GLint viewport[4]; + glGetIntegerv(GL_VIEWPORT, viewport); + glDisable(GL_STENCIL_TEST); glDisable(GL_DEPTH_TEST); - - glBlendFunc(GL_SRC_ALPHA, GL_ONE); - glBlendEquation(GL_FUNC_ADD); glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); glMatrixMode(GL_PROJECTION); glPushMatrix(); - glLoadIdentity(); glOrtho(0, Width(), 0, Height(), -1, 1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); - int timer = GetCountdown(elapsedTime); - for (int i = 1; i < WORLD_SIZE_X; i++) - { - if (timer <= COUNTDOWN - m_timerReductionChunk * i) { - m_world.RemoveChunk(m_nbReductionChunk * i); - m_renderer.RemoveChunk(m_nbReductionChunk * i); - } - } - if (m_keyK) { - SystemNotification(m_messageNotification); - m_keyK = false; - } - if (m_keyL) { + m_textureOptionsMenu.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(); - KillNotification(m_player, m_player); - m_keyL = false; + glColor4f(1.0f, 0.0f, 1.0f, 1.0f); + m_textureOptOptions.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(0.5f, 1.0f, 0.0f, 1.0f); + } + m_textureOptAudio.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(1.0f, 0.0f, 1.0f, 1.0f); + if (m_selectedOption == 1) { + glColor4f(0.5f, 1.0f, 0.0f, 1.0f); + } + m_textureOptGraphics.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(1.0f, 0.0f, 1.0f, 1.0f); + if (m_selectedOption == 2) { + glColor4f(0.5f, 1.0f, 0.0f, 1.0f); + } + m_textureOptGameplay.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.18, centerY - Height() * 0.1); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.18, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.175, centerY + Height() * 0.25); + glEnd(); + + glColor4f(1.0f, 0.0f, 1.0f, 1.0f); + m_textureOptBack.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); } - if (m_displayInfo) { - DisplayInfo(elapsedTime, bloc); - } - - if (m_displayHud) { - DisplayHud(timer); - } - - if (m_displayCrosshair) { - DisplayCrosshair(); - } - - glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR); - glBlendEquation(GL_FUNC_SUBTRACT); + 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::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) { - float windowWidth = static_cast(Width()); - float windowHeight = static_cast(Height()); +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; - float posX = x * windowWidth; - float posY = y * windowHeight; + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptMain.Bind(); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.215); + glTexCoord2f(1, 0); glVertex2i(centerX - Width() * 0.075, centerY + Height() * 0.215); + glTexCoord2f(1, 1); glVertex2i(centerX - Width() * 0.075, centerY + Height() * 0.25); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.15, centerY + Height() * 0.25); + glEnd(); - float baseCharSize = 20 + (24 - 20) * (windowWidth - 1600) / (1920 - 1600); - float charSize = baseCharSize * charSizeMultiplier; + float principalBottom = centerY + Height() * 0.165f; + float principalTop = centerY + Height() * 0.2f; - glLoadIdentity(); - glTranslated(x, y, 0); + DrawSliderBackground(centerX, centerY, minBar, maxBar, principalBottom, principalTop); + DrawSlider(centerX, centerY, m_volPrincipal, minBar, maxBar, principalBottom, principalTop); + DisplayBarPercentValue(centerX, centerY, percentPosX, principalBottom, minBar, maxBar, m_volPrincipal); - for (unsigned int i = 0; i < t.length(); ++i) { - float left = (float)((t[i] - 32) % 16) / 16.f; - float top = (float)((t[i] - 32) / 16) / 16.f; - top += 0.5f; + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glBlendEquation(GL_FUNC_ADD); - glBegin(GL_QUADS); - glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0); - glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(charSize, 0); - glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(charSize, charSize); - glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize); - glEnd(); + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptMusic.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(); - glTranslated(0.5555f * charSize, 0, 0); - } + float musiqueBottom = centerY + Height() * 0.04f; + float musiqueTop = centerY + Height() * 0.075f; + + DrawSliderBackground(centerX, centerY, minBar, maxBar, musiqueBottom, musiqueTop); + DrawSlider(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, 1.0f, 0.0f, 1.0f); + m_textureOptSfx.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); + DrawSlider(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); } -int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } +void Engine::DisplayGraphicsMenu(float centerX, float centerY) { + glColor4f(1.0f, 1.0f, 0.0f, 1.0f); + m_textureOptResolution.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(); -int Engine::GetCountdown(float elapsedTime) { - if (m_resetcountdown) - { - m_nbReductionChunk = 4; - m_timerReductionChunk = 30; - m_countdown = m_time + COUNTDOWN; - m_resetcountdown = false; + glColor4f(1.0f, 1.0f, 1.0f, 0.5f); + glBindTexture(GL_TEXTURE_2D, 0); + glBegin(GL_QUADS); + glTexCoord2f(0, 0); glVertex2i(centerX - Width() * 0.16, centerY + Height() * 0.165); + glTexCoord2f(1, 0); glVertex2i(centerX + Width() * 0.1, centerY + Height() * 0.165); + glTexCoord2f(1, 1); glVertex2i(centerX + Width() * 0.1, centerY - Height() * 0.04); + glTexCoord2f(0, 1); glVertex2i(centerX - Width() * 0.16, centerY - Height() * 0.04); + 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; } - if (m_countdown < m_time) - Stop(); - if (!m_stopcountdown) - m_time += elapsedTime; - return m_countdown - (int)m_time; + + glColor4f(1.0f, 1.0f, 1.0f, 1.0f); } void Engine::Render(float elapsedTime) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - /*m_time_SplashScreen += elapsedTime; - if (m_time_SplashScreen < 2) { - DrawSplachScreen(); + if (m_gamestate == GameState::SPLASH) { + if (m_splashTime > 0.0f) { + DisplaySplashScreen(); + } + else { + m_gamestate = GameState::MAIN_MENU; + } + + m_splashTime -= elapsedTime; + return; } - else */if (m_gamestate == GameState::PLAY) - { + + if (m_gamestate == GameState::MAIN_MENU) { + DisplayMainMenu(); + return; + } + + if (m_gamestate == GameState::OPTIONS) { + DisplayOptionsMenu(); + return; + } + + if (m_gamestate == GameState::PAUSE) { + DisplayPauseMenu(); + return; + } + + if (m_gamestate == GameState::PLAY) { HideCursor(); CenterMouse(); //D�placement de centermouse dans l'action de jouer @@ -1189,7 +1264,7 @@ void Engine::Render(float elapsedTime) { m_player.ApplyTransformation(skybox, false); // Version d'ApplyTransformation qui ne tient compte que de la rotation // (donc l'objet ne bouge pas relativement au joueur, ce qui est pratique pour une skybox!). - + m_player.ApplyTransformation(remotePlayer, true, false); if (m_key1) bloc++; @@ -1264,8 +1339,7 @@ void Engine::Render(float elapsedTime) { DrawHud(elapsedTime, bloc); DisplayPovGun(); ProcessNotificationQueue(); - if (m_damage) - { + if (m_damage) { InstantDamage(); } static bool fell = false; @@ -1391,20 +1465,88 @@ void Engine::Render(float elapsedTime) { } } - else if (m_gamestate == GameState::MAIN_MENU) - { - DrawMenu(); - } - else if (m_gamestate == GameState::SINGLEMULTI) - DisplaySingleOrMultiplayerMenu(); - else if (m_gamestate == GameState::OPTIONS) - { - DrawOption(); - } - else if (m_gamestate == GameState::QUIT) - Stop(); } +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, 1.0f, 0.0f, 1.0f); + m_textureOptSensitivity.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); + DrawSlider(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::DrawSlider(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::KeyPressEvent(unsigned char key) { switch (key) { case 0: // A - Gauche @@ -1428,12 +1570,10 @@ void Engine::KeyPressEvent(unsigned char key) { } break; case 36: // ESC - Quitter - if (m_gamestate == GameState::PLAY) - { + if (m_gamestate == GameState::PLAY) { m_gamestate = GameState::PAUSE; } - else if (m_gamestate == GameState::PAUSE) - { + else if (m_gamestate == GameState::PAUSE) { m_gamestate = GameState::PLAY; } //Stop(); @@ -1494,7 +1634,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; @@ -1567,25 +1706,49 @@ 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::MAIN_MENU) { + DisplayMainMenu(); + } + 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_selectedOptAudioMainBar) { + m_volPrincipal = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) { + m_volMusique = x - leftBar; + } + else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) { + m_volEffets = x - leftBar; + } + else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) { + m_volSensible = x - leftBar; + } + } } void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { m_mousemx = x; m_mousemy = y; + float centerX = Width() * 0.5f; + float centerY = Height() * 0.5f; - if (m_gamestate == GameState::PLAY) - { + if (m_gamestate == GameState::PLAY) { switch (button) { case MOUSE_BUTTON_LEFT: m_mouseL = true; @@ -1605,44 +1768,138 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) { case MOUSE_BUTTON_NONE: break; } } - else if (m_gamestate == GameState::MAIN_MENU) - { - if ((m_mousemx >= 285 && m_mousemx <= 490) && (m_mousemy >= 150 && m_mousemy <= 250)) - m_gamestate = GameState::SINGLEMULTI; - if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 300 && m_mousemy <= 400)) - m_gamestate = GameState::OPTIONS; - if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 450 && m_mousemy <= 500)) - m_gamestate = GameState::QUIT; - } - else if (m_gamestate == GameState::SINGLEMULTI) - { - float buttonWidthProportion = 0.4f; - float buttonHeightProportion = 0.075f; - float buttonWidth = buttonWidthProportion * Width(); - float buttonHeight = buttonHeightProportion * Height(); - float offsetSingleButtonXFactor = 0.075f; - float offsetSingleButtonYFactor = 0.05f; + else if (m_gamestate == GameState::MAIN_MENU) { - float buttonPosX = m_titleX; - float buttonSinglePosY = m_titleY - buttonHeight - (offsetSingleButtonYFactor * Height()); - float buttonMultiPosY = buttonSinglePosY * 0.75; - float adjustedMouseY = Height() - m_mousemy; + float leftButton = centerX + Width() * 0.045f; + float rightButton = centerX + Width() * 0.4455f; - // Single Player - 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; + float topFirst = centerY + Height() * 0.073f; + float bottomFirst = centerY; + + float topSecond = centerY + Height() * 0.177f; + float bottomSecond = centerY + Height() * 0.105f; + + float topThird = centerY + Height() * 0.275f; + float bottomThird = centerY + Height() * 0.198f; + + if (x > leftButton && x < rightButton && y > bottomFirst && y < topFirst) { + if (m_selectedPlayOptions) { + m_gamestate = GameState::PLAY; + } + else { + m_selectedPlayOptions = true; + } } - // Multiplayer - 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; + else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) { + if (m_selectedPlayOptions) { + m_gamestate = GameState::PLAY; + } + else { + m_gamestate = GameState::OPTIONS; + } + } + else if (x > leftButton && x < rightButton && y > bottomThird && y < topThird) { + if (m_selectedPlayOptions) { + m_selectedPlayOptions = false; + } + else { + m_gamestate = GameState::QUIT; + } + } + } + else if (m_gamestate == GameState::OPTIONS) { + float leftAudio = centerX - Width() * 0.35f; + float rightAudio = centerX - Width() * 0.2f; + float topAudio = (Height() * 0.25f) + ((Height() * 0.25f) - (Height() * 0.2f)); + float bottomAudio = (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 leftBack = centerX - Width() * 0.075f; + float rightBack = centerX + Width() * 0.075f; + float topBack = centerY + Height() * 0.25f; + float bottomBack = centerY + Height() * 0.2f; + + if (x > leftAudio && x < rightAudio && y > bottomAudio && y < topAudio) { + 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 > leftBack && x < rightBack && y > bottomBack && y < topBack) { + m_gamestate = GameState::MAIN_MENU; + } + + // Audio + 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_selectedOptAudioMainBar = true; + } + else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarMusique && y < topBarMusique) { + m_volMusique = x - leftBar; + m_selectedOptAudioMusicBar = true; + } + else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarEffets && y < topBarEffets) { + m_volEffets = x - leftBar; + m_selectedOptAudioSfxBar = 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_selectedGameplaySensitivityBar = true; } } } @@ -1652,6 +1909,10 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) { case MOUSE_BUTTON_LEFT: m_mouseL = false; m_block = false; + m_selectedOptAudioMainBar = false; + m_selectedOptAudioMusicBar = false; + m_selectedOptAudioSfxBar = false; + m_selectedGameplaySensitivityBar = false; break; case MOUSE_BUTTON_RIGHT: m_mouseR = false; diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 484982d..6f23719 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -24,15 +24,12 @@ #include "renderer.h" #include "remoteplayer.h" #include "booster.h" - +#include "settings.h" class Engine : public OpenglContext { public: Engine(); virtual ~Engine(); - virtual void DrawMenu(); - virtual void DrawOption(); - virtual void DrawSplachScreen(); virtual void Init(); virtual void DeInit(); virtual void LoadResource(); @@ -47,98 +44,137 @@ 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); void InstantDamage(); 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 DrawHud(float elapsedTime, BlockType bloc); + void DisplayInfo(float elapsedTime, BlockType bloc); + + void DisplaySplashScreen(); + void DisplayPauseMenu(); + + void DisplayMainMenu(); + void DrawButtonBackgrounds(float centerX, float centerY, int iterations); + void DrawMainMenuButtons(float centerX, float centerY); + void DrawSingleMultiButtons(float centerX, float centerY); + + void DisplayOptionsMenu(); + 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 DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue); + + void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); + void ProcessNotificationQueue(); + Audio m_audio = Audio(AUDIO_PATH "start.wav"); + irrklang::ISound* m_powpow, * m_scream; + irrklang::ISound* m_whoosh[MAX_BULLETS]; - + Bullet* m_bullets[MAX_BULLETS]; + //Menu + enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE, SINGLEMULTI }; - Connector m_conn; - Shader m_shader01; + Vector3f m_otherplayerpos = Vector3f(999, 999, 999); + + World m_world = World(); + Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); + + Renderer m_renderer = Renderer(); + + Booster m_booster = Booster(); BlockInfo* m_blockinfo[BTYPE_LAST]; BoostInfo* m_boostinfo[BTYPE_BOOST_LAST]; + + GameState m_gamestate = GameState::SPLASH; + + Shader m_shader01; + + Skybox m_skybox; + TextureAtlas m_textureAtlas = TextureAtlas(BTYPE_LAST); TextureAtlas m_animeAtlas = TextureAtlas(TYPE_LAST + POS_LAST); - World m_world = World(); - Renderer m_renderer = Renderer(); - Booster m_booster = Booster(); + TextureAtlas::TextureIndex texBoostHeal; Texture m_textureCrosshair; Texture m_textureFont; Texture m_textureGun; Texture m_texturePovGun; Texture m_textureSkybox; - Texture m_textureSoloMultiMenu; - Texture m_textureSoloText; - Texture m_textureMultiText; - Texture m_textureTitle; - TextureAtlas::TextureIndex texBoostHeal; + Texture m_textureMainMenu; + Texture m_textureOptionsMenu; + Texture m_texturePauseMenu; + Texture m_textureSplashScreen; - Skybox m_skybox; - Audio m_audio = Audio(AUDIO_PATH "start.wav"); + Texture m_textureHd; + Texture m_textureFhd; + Texture m_textureQhd; + Texture m_textureUhd; + Texture m_textureCheck; + Texture m_textureChecked; - irrklang::ISound* m_powpow, - * m_scream; - irrklang::ISound *m_whoosh[MAX_BULLETS]; + Texture m_textureOptAudio; + Texture m_textureOptBack; + Texture m_textureOptGameplay; + Texture m_textureOptGraphics; + Texture m_textureOptMain; + Texture m_textureOptMusic; + Texture m_textureOptOptions; + Texture m_textureOptResolution; + Texture m_textureOptSensitivity; + Texture m_textureOptSfx; - Player m_player = Player(Vector3f(.5f, CHUNK_SIZE_Y + 1.8f, .5f)); - - Bullet* m_bullets[MAX_BULLETS]; - std::vector m_chunkmod_manifest; + Texture m_textureMenuBack; + Texture m_textureMenuMulti; + Texture m_textureMenuOptions; + Texture m_textureMenuPlay; + Texture m_textureMenuQuit; + Texture m_textureMenuSingle; + Texture m_textureMenuTitle; - std::unordered_map m_players; - netprot::Buffer m_buf, m_bufout; - std::chrono::high_resolution_clock::time_point m_startTime; - netprot::ChunkMod* m_chunkmod = nullptr; + Settings m_options = Settings(m_audio); - //Menu - enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE, SINGLEMULTI }; - GameState m_gamestate = GameState::PLAY; - - Texture MenuTitleTexture; - Texture MenuBGTexture; - Texture MenuBGOptionTexture; - Texture MenuStartTexture; - Texture MenuQuitTexture; - Texture MenuOptionsTexture; - Texture PauseBGTexture; - Texture SplachScreenTexture; - Texture MusicTexture; //TODO - Texture OnOffBtnTexture;//TODO - Texture BackBtnTexture;//TODO - - Vector3f m_otherplayerpos = Vector3f(999, 999, 999); + Resolution m_resolution = HD; + float m_splashTime = 2.0f; 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_selectedOptAudioMainBar = false; + bool m_selectedOptAudioMusicBar = false; + bool m_selectedOptAudioSfxBar = false; + bool m_selectedGameplaySensitivityBar = false; + bool m_damage = false; bool m_wireframe = false; @@ -151,10 +187,13 @@ private: bool m_resetcountdown = false; bool m_soloMultiChoiceMade = false; bool m_stopcountdown = false; + + bool m_selectedPlayOptions = false; + bool m_selectedOptions = false; + bool m_selectedQuit = false; bool m_key1 = false; bool m_key2 = false; - bool m_keyK = false; bool m_keyL = false; bool m_keyW = false; @@ -162,16 +201,24 @@ private: bool m_keyS = false; bool m_keyD = false; bool m_keySpace = false; + bool m_mouseL = false; bool m_mouseR = false; bool m_mouseC = false; bool m_mouseWU = false; bool m_mouseWD = false; - //Pour trouver ou est la souris + float m_mousemx = 0; float m_mousemy = 0; bool m_networkgame = false; + + Connector m_conn; + std::vector m_chunkmod_manifest; + std::chrono::high_resolution_clock::time_point m_startTime; + std::unordered_map m_players; + netprot::Buffer m_buf, m_bufout; + netprot::ChunkMod* m_chunkmod = nullptr; netprot::PlayerInfo m_pinfo; std::unordered_map m_syncs; RemotePlayer m_remotePlayer = RemotePlayer(netprot::PlayerInfo(),Vector3f(5.5f, CHUNK_SIZE_Y + 1.8f, 5.5f)); 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/BrouillonbackgroundMenu.png b/SQCSim2021/media/textures/BrouillonbackgroundMenu.png deleted file mode 100644 index ba8631c..0000000 Binary files a/SQCSim2021/media/textures/BrouillonbackgroundMenu.png and /dev/null differ diff --git a/SQCSim2021/media/textures/single_multi.png b/SQCSim2021/media/textures/menus/backgrounds/bgMainMenu.png similarity index 100% rename from SQCSim2021/media/textures/single_multi.png rename to SQCSim2021/media/textures/menus/backgrounds/bgMainMenu.png diff --git a/SQCSim2021/media/textures/menus/backgrounds/bgOptions.png b/SQCSim2021/media/textures/menus/backgrounds/bgOptions.png new file mode 100644 index 0000000..3a8dc45 Binary files /dev/null and b/SQCSim2021/media/textures/menus/backgrounds/bgOptions.png differ diff --git a/SQCSim2021/media/textures/menus/backgrounds/bgPause.png b/SQCSim2021/media/textures/menus/backgrounds/bgPause.png new file mode 100644 index 0000000..c236e26 Binary files /dev/null and b/SQCSim2021/media/textures/menus/backgrounds/bgPause.png differ diff --git a/SQCSim2021/media/textures/sc2.png b/SQCSim2021/media/textures/menus/backgrounds/bgSplash.png similarity index 100% rename from SQCSim2021/media/textures/sc2.png rename to SQCSim2021/media/textures/menus/backgrounds/bgSplash.png diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainBack.png b/SQCSim2021/media/textures/menus/buttons/main/mainBack.png new file mode 100644 index 0000000..8a0e568 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainBack.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainMulti.png b/SQCSim2021/media/textures/menus/buttons/main/mainMulti.png new file mode 100644 index 0000000..502891a Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainMulti.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainOptions.png b/SQCSim2021/media/textures/menus/buttons/main/mainOptions.png new file mode 100644 index 0000000..8984ca6 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainOptions.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainPlay.png b/SQCSim2021/media/textures/menus/buttons/main/mainPlay.png new file mode 100644 index 0000000..0cfbb14 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainPlay.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainQuit.png b/SQCSim2021/media/textures/menus/buttons/main/mainQuit.png new file mode 100644 index 0000000..0c61ab4 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainQuit.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/main/mainSingle.png b/SQCSim2021/media/textures/menus/buttons/main/mainSingle.png new file mode 100644 index 0000000..6fe2074 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/main/mainSingle.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optAudio.png b/SQCSim2021/media/textures/menus/buttons/options/optAudio.png new file mode 100644 index 0000000..de3bbf4 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optAudio.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optBack.png b/SQCSim2021/media/textures/menus/buttons/options/optBack.png new file mode 100644 index 0000000..03e2563 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optBack.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optGameplay.png b/SQCSim2021/media/textures/menus/buttons/options/optGameplay.png new file mode 100644 index 0000000..687c857 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optGameplay.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optGraphics.png b/SQCSim2021/media/textures/menus/buttons/options/optGraphics.png new file mode 100644 index 0000000..8aa8b66 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optGraphics.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optMain.png b/SQCSim2021/media/textures/menus/buttons/options/optMain.png new file mode 100644 index 0000000..c9e1098 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optMain.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optMusic.png b/SQCSim2021/media/textures/menus/buttons/options/optMusic.png new file mode 100644 index 0000000..c6f4d57 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optMusic.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optOptions.png b/SQCSim2021/media/textures/menus/buttons/options/optOptions.png new file mode 100644 index 0000000..5c15729 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optOptions.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optResolution.png b/SQCSim2021/media/textures/menus/buttons/options/optResolution.png new file mode 100644 index 0000000..8003a75 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optResolution.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optSensitivity.png b/SQCSim2021/media/textures/menus/buttons/options/optSensitivity.png new file mode 100644 index 0000000..b8af10f Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optSensitivity.png differ diff --git a/SQCSim2021/media/textures/menus/buttons/options/optSfx.png b/SQCSim2021/media/textures/menus/buttons/options/optSfx.png new file mode 100644 index 0000000..43babb6 Binary files /dev/null and b/SQCSim2021/media/textures/menus/buttons/options/optSfx.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelFhd.png b/SQCSim2021/media/textures/menus/labels/labelFhd.png new file mode 100644 index 0000000..0e78428 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelFhd.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelHd.png b/SQCSim2021/media/textures/menus/labels/labelHd.png new file mode 100644 index 0000000..9594d91 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelHd.png differ diff --git a/SQCSim2021/media/textures/menus/labels/labelQhd.png b/SQCSim2021/media/textures/menus/labels/labelQhd.png new file mode 100644 index 0000000..1da6626 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelQhd.png differ diff --git a/SQCSim2021/media/textures/title.png b/SQCSim2021/media/textures/menus/labels/labelTitle.png similarity index 100% rename from SQCSim2021/media/textures/title.png rename to SQCSim2021/media/textures/menus/labels/labelTitle.png diff --git a/SQCSim2021/media/textures/menus/labels/labelUhd.png b/SQCSim2021/media/textures/menus/labels/labelUhd.png new file mode 100644 index 0000000..696a558 Binary files /dev/null and b/SQCSim2021/media/textures/menus/labels/labelUhd.png differ diff --git a/SQCSim2021/media/textures/menus/others/check.png b/SQCSim2021/media/textures/menus/others/check.png new file mode 100644 index 0000000..9b3968b Binary files /dev/null and b/SQCSim2021/media/textures/menus/others/check.png differ diff --git a/SQCSim2021/media/textures/menus/others/checked.png b/SQCSim2021/media/textures/menus/others/checked.png new file mode 100644 index 0000000..2debe55 Binary files /dev/null and b/SQCSim2021/media/textures/menus/others/checked.png differ diff --git a/SQCSim2021/media/textures/multi_player.png b/SQCSim2021/media/textures/multi_player.png deleted file mode 100644 index d8db6e0..0000000 Binary files a/SQCSim2021/media/textures/multi_player.png and /dev/null differ diff --git a/SQCSim2021/media/textures/single_player.png b/SQCSim2021/media/textures/single_player.png deleted file mode 100644 index f553d08..0000000 Binary files a/SQCSim2021/media/textures/single_player.png and /dev/null 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