diff --git a/SQCSim2021/engine.cpp b/SQCSim2021/engine.cpp index 64c9a06..eac9feb 100644 --- a/SQCSim2021/engine.cpp +++ b/SQCSim2021/engine.cpp @@ -5,8 +5,6 @@ #include #include - - // Define a structure to represent notifications struct Notification { std::string message; @@ -97,6 +95,7 @@ void Engine::LoadResource() { 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_textureStartMenu, TEXTURE_PATH "startmenu.png", false); TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); @@ -147,7 +146,6 @@ void Engine::KillNotification(Player killer, Player killed) { DisplayNotification(message); } - void Engine::DisplayNotification(std::string message) { if (message.length() > 45) { @@ -157,23 +155,27 @@ void Engine::DisplayNotification(std::string message) { Notification newNotification; newNotification.message = message; newNotification.displayStartTime = m_time; - + notifications.push_back(newNotification); } // Add a method to process the notification queue void Engine::ProcessNotificationQueue() { + //PrintText(fPosX, fUsernamePosY, ss.str(), 1.5f); + //float fPosX = (Width() / 100.0f) * scaleX; + //float fPosY = Height() - (Height() * 0.05) * scaleY; + m_textureFont.Bind(); auto [scaleX, scaleY] = GetScale(); - unsigned int xOffset = static_cast((BASE_WIDTH - BASE_WIDTH * 0.26f) * scaleX); - unsigned int yOffset = static_cast((BASE_HEIGHT - (BASE_HEIGHT / 2.2f)) * scaleY); + float xOffset = (Width() / 1.5f) * scaleX; + float yOffset = (Height() / 1.2f) * scaleY; for (auto it = notifications.begin(); it != notifications.end(); ) { float timeSinceDisplay = m_time - it->displayStartTime; - unsigned int y = yOffset - static_cast(20.0f * scaleX * (it - notifications.begin())); + float y = yOffset - (20.0f * scaleX * (it - notifications.begin())); glDisable(GL_STENCIL_TEST); glDisable(GL_DEPTH_TEST); @@ -212,21 +214,20 @@ void Engine::ProcessNotificationQueue() { } } - void Engine::DisplayCrosshair() { m_textureCrosshair.Bind(); static const int crossSize = 32; glLoadIdentity(); glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0); glBegin(GL_QUADS); - glTexCoord2f(0, 0); - glVertex2i(0, 0); - glTexCoord2f(1, 0); - glVertex2i(crossSize, 0); - glTexCoord2f(1, 1); - glVertex2i(crossSize, crossSize); - glTexCoord2f(0, 1); - glVertex2i(0, crossSize); + glTexCoord2f(0, 0); + glVertex2i(0, 0); + glTexCoord2f(1, 0); + glVertex2i(crossSize, 0); + glTexCoord2f(1, 1); + glVertex2i(crossSize, crossSize); + glTexCoord2f(0, 1); + glVertex2i(0, crossSize); glEnd(); } @@ -247,8 +248,8 @@ void Engine::DisplayPovGun() { glMatrixMode(GL_MODELVIEW); glPushMatrix(); - float scaleX = static_cast(Width()) / BASE_WIDTH; - float scaleY = static_cast(Height()) / BASE_HEIGHT; + float scaleX = (Width()) / BASE_WIDTH; + float scaleY = (Height()) / BASE_HEIGHT; float baseXOffset = 0.4958 * BASE_WIDTH; float baseWidth = 0.4688 * BASE_WIDTH; float baseHeight = 0.5787 * BASE_HEIGHT; @@ -310,6 +311,33 @@ void Engine::DisplayHud(int timer) { glEnd(); + float centerX = Width() / 2.0f; + float centerY = Height() / 2.0f; + float quadWidth = 200.0f; + float quadHeight = fBackHeight; + + float thickness = quadHeight / 2.5; + float xOffset = quadWidth * 2; + float yOffset = quadWidth; + + // Top Quad (unchanged) + glColor4f(1.0f, 1.0f, 1.0f, 0.2f); + glBegin(GL_QUADS); + glVertex2f(centerX - quadWidth + xOffset, (centerY - thickness) + 1.5f * thickness - yOffset); // Bottom-left + glVertex2f(centerX + quadWidth + xOffset, (centerY - thickness) + 1.5f * thickness - yOffset); // Bottom-right + glVertex2f(centerX + quadWidth + xOffset, (centerY - thickness) + 2.5f * thickness - yOffset); // Top-right + glVertex2f(centerX - quadWidth + xOffset, (centerY - thickness) + 2.5f * thickness - yOffset); // Top-left + glEnd(); + + // Adjusted Bottom Quad (moved down by an additional thickness) + glColor4f(1.0f, 1.0f, 1.0f, 0.2f); + glBegin(GL_QUADS); + glVertex2f(centerX - quadWidth + xOffset, centerY - 1.5f * thickness - yOffset); // Bottom-left + glVertex2f(centerX + quadWidth + xOffset, centerY - 1.5f * thickness - yOffset); // Bottom-right + glVertex2f(centerX + quadWidth + xOffset, centerY - 0.5f * thickness - yOffset); // Top-right + glVertex2f(centerX - quadWidth + xOffset, centerY - 0.5f * thickness - yOffset); // Top-left + glEnd(); + // HP Bar float fBarWidth = (Width() / 4.0f) * scaleX; float fBarHeight = (Height() / 25.0f) * scaleY; @@ -388,7 +416,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { float fPosX = (Width() / 100.0f) * scaleX; float fPosY = Height() - (Height() * 0.05) * scaleY; float charSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600); - + ss << " Fps : " << GetFps(elapsedTime); PrintText(fPosX, fPosY, ss.str()); ss.str(""); @@ -404,7 +432,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { ss.str(""); fPosY -= charSize; - float fPosYJump = static_cast((Height() - (Height() * 0.9f)) * scaleY); + float fPosYJump = ((Height() - (Height() * 0.9f)) * scaleY); fPosY = fPosYJump; fPosY -= charSize; @@ -431,6 +459,50 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { PrintText(fPosX, fPosYJump, ss.str()); } +void Engine::DisplaySingleOrMultiplayerMenu() { + glDisable(GL_STENCIL_TEST); + glDisable(GL_DEPTH_TEST); + + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glBlendEquation(GL_FUNC_ADD); + + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + + glLoadIdentity(); + glOrtho(0, Width(), 0, Height(), -1, 1); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + // Create a low opacity white background with border radius + float fBackPosX = 0.0f; + float fBackPosY = 0.0f; + float fBackWidth = (Width() / 4.0f); + float fBackHeight = (Height() / 5.5f); + + glColor4f(1.0f, 1.0f, 1.0f, 0.2f); + glBegin(GL_QUADS); + glVertex2f(fBackPosX, fBackPosY); + glVertex2f(fBackPosX + fBackWidth, fBackPosY); + glVertex2f(fBackPosX + fBackWidth, fBackPosY + fBackHeight); + glVertex2f(fBackPosX, fBackPosY + fBackHeight); + glEnd(); + + + 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::DrawHud(float elapsedTime, BlockType bloc) { // Setter le blend function, tout ce qui sera noir sera transparent glDisable(GL_STENCIL_TEST); @@ -455,7 +527,7 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) { m_keyK = false; } if (m_keyL) { - + KillNotification(m_player, m_player); m_keyL = false; } @@ -487,7 +559,7 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) { void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) { auto [scaleX, scaleY] = GetScale(); - float scale = std::min(scaleX, scaleY); + float scale = std::min(scaleX, scaleY); float baseCharSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600); float charSize = baseCharSize * charSizeMultiplier; @@ -507,7 +579,7 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize * scale); glEnd(); - glTranslated(0.5555f * charSize * scale, 0, 0); + glTranslated(0.5555f * charSize * scale, 0, 0); } } @@ -526,7 +598,7 @@ int Engine::GetCountdown(float elapsedTime) { } if (m_countdown < m_time) Stop(); - if(!m_stopcountdown) + if (!m_stopcountdown) m_time += elapsedTime; return m_countdown - (int)m_time; } @@ -626,10 +698,10 @@ void Engine::Render(float elapsedTime) { if (m_isSkybox) m_skybox.Render(skybox); - ProcessNotificationQueue(); DrawHud(elapsedTime, bloc); DisplayPovGun(); - + ProcessNotificationQueue(); + static bool fell = false; if (m_player.GetPosition().y < 1.7f && !fell) { m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), 1.f); @@ -697,7 +769,7 @@ void Engine::KeyPressEvent(unsigned char key) { case 17: // R - Ignorer break; case 19: // T - Ignorer - break; + break; case 24: // Y - Ignorer break; case 255: // Fn - Ignorer diff --git a/SQCSim2021/engine.h b/SQCSim2021/engine.h index 53ed25e..64ce95e 100644 --- a/SQCSim2021/engine.h +++ b/SQCSim2021/engine.h @@ -52,6 +52,7 @@ private: void DisplayCurrentItem(); void DisplayHud(int timer); void DisplayInfo(float elapsedTime, BlockType bloc); + void DisplaySingleOrMultiplayerMenu(); void DrawHud(float elapsedTime, BlockType bloc); void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f); @@ -63,11 +64,12 @@ private: World m_world = World(); WorldRenderer m_wrenderer = WorldRenderer(); - Texture m_textureSkybox; - Texture m_textureFont; Texture m_textureCrosshair; + Texture m_textureFont; Texture m_textureGun; Texture m_texturePovGun; + Texture m_textureSkybox; + Texture m_textureStartMenu; Skybox m_skybox; Audio m_audio = Audio(AUDIO_PATH "start.wav"); diff --git a/SQCSim2021/media/textures/StartMenu.png b/SQCSim2021/media/textures/StartMenu.png new file mode 100644 index 0000000..ef0d7b1 Binary files /dev/null and b/SQCSim2021/media/textures/StartMenu.png differ diff --git a/SQCSim2021/media/textures/Titre.png b/SQCSim2021/media/textures/Titre.png new file mode 100644 index 0000000..4a58469 Binary files /dev/null and b/SQCSim2021/media/textures/Titre.png differ