Push menu solo/multi avec titre et quads contenant choix. Manque persistence du menu en 2D et nom des choix dans les quads.

This commit is contained in:
mduval76 2023-10-25 01:01:25 -04:00
parent df5b7960b2
commit 8ebe7b95fc
4 changed files with 68 additions and 49 deletions

View File

@ -95,7 +95,8 @@ 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);
LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.png", false);
LoadTexture(m_textureTitle, TEXTURE_PATH "title.png", false);
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
@ -291,12 +292,9 @@ void Engine::DisplayCurrentItem() {
void Engine::DisplayHud(int timer) {
glBindTexture(GL_TEXTURE_2D, 0);
glLoadIdentity();
glDisable(GL_BLEND);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
auto [scaleX, scaleY] = GetScale();
// Create a low opacity white background with border radius
float fBackPosX = (Width() / 25.0f) * scaleX;
float fBackPosY = (Height() - (Height() * 0.815) * scaleY);
float fBackWidth = (Width() / 4.0f) * scaleX;
@ -310,34 +308,6 @@ void Engine::DisplayHud(int timer) {
glVertex2f(fBackPosX, fBackPosY + fBackHeight);
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;
@ -393,11 +363,13 @@ void Engine::DisplayHud(int timer) {
m_textureFont.Bind();
std::ostringstream ss;
float fUsernamePosY = fBarPosY - (fBarHeight * 2);
float fUsernamePosY = fBarPosY - (fBarHeight * 2) * scaleY;
ss.str("");
ss << m_player.GetUsername();
PrintText(fPosX, fUsernamePosY, ss.str(), 1.5f);
ss.str("");
ss.str("");
ss << m_player.GetHP() * 100 << "%";
PrintText(fPosX * 6.25, fUsernamePosY, ss.str(), 1.5f);
@ -460,12 +432,13 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
}
void Engine::DisplaySingleOrMultiplayerMenu() {
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD);
glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBlendEquation(GL_FUNC_ADD);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
@ -475,23 +448,62 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
// Create a low opacity white background with border radius
auto [scaleX, scaleY] = GetScale();
float fBackPosX = 0.0f;
float fBackPosY = 0.0f;
float fBackWidth = (Width() / 4.0f);
float fBackHeight = (Height() / 5.5f);
float fBackPosY = 0.0f;
float fBackWidth = Width();
float fBackHeight = Height();
glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
m_textureSoloMultiMenu.Bind();
glBegin(GL_QUADS);
glVertex2f(fBackPosX, fBackPosY);
glVertex2f(fBackPosX + fBackWidth, fBackPosY);
glVertex2f(fBackPosX + fBackWidth, fBackPosY + fBackHeight);
glVertex2f(fBackPosX, fBackPosY + fBackHeight);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fBackPosX, fBackPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fBackWidth, fBackPosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fBackWidth, fBackHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fBackPosX, fBackHeight);
glEnd();
float centerX = (Width() / 2.0f);
float centerY = (Height() / 2.0f);
float titleWidth = (centerX * 1.85f) * scaleX;
float titleHeight = (centerY * 1.85f) * scaleY;
glBlendFunc(GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR);
glBlendEquation(GL_FUNC_SUBTRACT);
// Solo game indicator
m_textureTitle.Bind();
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX, centerY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(titleWidth, centerY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(titleWidth, titleHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX, titleHeight);
glEnd();
glBindTexture(GL_TEXTURE_2D, 0);
// Solo game indicator
float fPosX = (centerX * 1.1f) * scaleX;
float fPosXWidth = (centerX * 1.75f) * scaleX;
float soloPosY = (centerY * 0.75f) * scaleY;
float soloHeight = (centerY * 0.9f) * scaleY;
glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, soloPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, soloPosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, soloHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, soloHeight);
glEnd();
// Multiplayer game indicator
float multiPosY = (centerY * 0.5f) * scaleY;
float multiHeight = (centerY * 0.65f) * scaleY;
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, multiPosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, multiPosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, multiHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, multiHeight);
glEnd();
// TODO: Add SOLO / MULTIPLAYER text with font
glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST);
@ -698,10 +710,15 @@ void Engine::Render(float elapsedTime) {
if (m_isSkybox) m_skybox.Render(skybox);
DrawHud(elapsedTime, bloc);
DisplayPovGun();
ProcessNotificationQueue();
if (m_soloMultiChoiceMade) {
DisplaySingleOrMultiplayerMenu();
}
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);

View File

@ -69,7 +69,8 @@ private:
Texture m_textureGun;
Texture m_texturePovGun;
Texture m_textureSkybox;
Texture m_textureStartMenu;
Texture m_textureSoloMultiMenu;
Texture m_textureTitle;
Skybox m_skybox;
Audio m_audio = Audio(AUDIO_PATH "start.wav");
@ -95,6 +96,7 @@ private:
bool m_displayHud = true;
bool m_displayInfo = false;
bool m_resetcountdown = false;
bool m_soloMultiChoiceMade = true;
bool m_stopcountdown = false;
bool m_keyK = false;

View File

Before

Width:  |  Height:  |  Size: 1.3 MiB

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB