Compare commits

...

11 Commits

Author SHA1 Message Date
Rynort
cd921b3ab3 Réparation du Merge du Pause 2023-11-06 16:04:34 -05:00
MarcEricMartel
ef7851bebf Merge branch 'master' into SQC-22 2023-11-06 15:39:54 -05:00
Jonathan Trottier
79013fe5d1 Merge pull request #21 from CegepSTH/SQC_21_MenuSoloMulti
Push menu solo ou multi.
2023-11-01 10:04:30 -04:00
MarcEricMartel
11e8684ee0 Merge pull request #23 from CegepSTH/SQC-54_MenuBackGround
Sqc 54 menu back ground
2023-11-01 06:20:44 -04:00
mduval76
9dd2e1b821 Fix pour resize dynamique de la fenetre de jeu (positionnement et scalaires).
Fix pour le maudit F10-fullscreen
2023-10-31 11:11:14 -04:00
Frederic Leger
3e89035de5 Merge branch 'master' into SQC-54_MenuBackGround 2023-10-30 16:21:16 -04:00
Louis-Charles Gaumond
0c8772edbf Changer l'image background du menu 2023-10-30 15:52:15 -04:00
Rynort
e5189f437c Finission du code pour le Pause 2023-10-30 15:49:17 -04:00
MarcEricMartel
851d5f0c0b Merge pull request #20 from CegepSTH/SQC-18_Mecanique_de_combat
Sqc 18 mecanique de combat
2023-10-30 15:44:41 -04:00
mduval76
eed8f5f04a Push menu solo ou multi. 2023-10-29 15:39:29 -04:00
Rynort
85f4f82660 avancement menu pause 2023-10-23 17:51:29 -04:00
5 changed files with 263 additions and 122 deletions

View File

@@ -72,6 +72,8 @@ void Engine::DrawSplachScreen()
glPopMatrix(); glPopMatrix();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopMatrix(); glPopMatrix();
m_gamestate = GameState::OPTIONS;
} }
@@ -82,7 +84,7 @@ void Engine::DrawMenu()
static const int sButton = 225; static const int sButton = 225;
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
@@ -99,11 +101,11 @@ void Engine::DrawMenu()
glTexCoord2f(0, 0); glTexCoord2f(0, 0);
glVertex2i(0, 0); glVertex2i(0, 0);
glTexCoord2f(1, 0); glTexCoord2f(1, 0);
glVertex2i(800, 0); glVertex2i(Width(), 0); //
glTexCoord2f(1, 1); glTexCoord2f(1, 1);
glVertex2i(800, 600); glVertex2i(Width(), Height());
glTexCoord2f(0, 1); glTexCoord2f(0, 1);
glVertex2i(0, 600); glVertex2i(0, Height());
glEnd(); glEnd();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -125,25 +127,28 @@ void Engine::DrawMenu()
glVertex2i(0, 300); glVertex2i(0, 300);
glEnd(); glEnd();
MenuStartTexture.Bind(); MenuStartTexture.Bind();
glTranslated(80, -225, 0); glTranslated(80, -225, 0);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, 0); glTexCoord2f(0, 0);
glVertex2i(0, 100); glVertex2i(0, 100);
glTexCoord2f(1, 0); glTexCoord2f(1, 0);
glVertex2i(sButton, 100); glVertex2i(sButton , 100);
glTexCoord2f(1, 1); glTexCoord2f(1, 1);
glVertex2i(sButton, 200); glVertex2i(sButton, 200);
glTexCoord2f(0, 1); glTexCoord2f(0, 1);
glVertex2i(0, 200); glVertex2i(0, 200);
glEnd(); glEnd();
/*MenuResumeTexture.Bind(); /*MenuResumeTexture.Bind();
glTranslated(0, -100, 0); glTranslated(0, -100, 0);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, 0); glTexCoord2f(0, 0);
glVertex2i(0, 125); glVertex2i(0, 125);
glTexCoord2f(1, 0); //glTexCoord2f(1, 0);
glVertex2i(sButton, 125); glVertex2i(sButton, 125);
glTexCoord2f(1, 1); glTexCoord2f(1, 1);
glVertex2i(sButton, 200); glVertex2i(sButton, 200);
@@ -270,6 +275,45 @@ void Engine::DrawMenu()
ShowCursor(); ShowCursor();
} }
void Engine::DrawPause()
{
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();
PauseBGTexture.Bind();
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2f(0, 0);
glVertex2i(0, 0);
glTexCoord2f(1, 0);
glVertex2i(800, 0);
glTexCoord2f(1, 1);
glVertex2i(800, 600);
glTexCoord2f(0, 1);
glVertex2i(0, 600);
glEnd();
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
ShowCursor();
}
void Engine::Init() { void Engine::Init() {
@@ -378,14 +422,19 @@ void Engine::LoadResource() {
LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false); LoadTexture(m_textureGun, TEXTURE_PATH "gun01.png", false);
LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false); LoadTexture(m_texturePovGun, TEXTURE_PATH "GUN.png", false);
LoadTexture(m_textureSoloMultiMenu, TEXTURE_PATH "single_multi.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(m_textureTitle, TEXTURE_PATH "title.png", false);
LoadTexture(MenuTitleTexture, MENU_ITEM_PATH "test.png"); LoadTexture(MenuTitleTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
LoadTexture(MenuBGTexture, MENU_ITEM_PATH "test.png"); LoadTexture(MenuBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
LoadTexture(PauseBGTexture, TEXTURE_PATH "BrouillonbackgroundMenu.png");
LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png"); LoadTexture(SplachScreenTexture, TEXTURE_PATH "sc2.png");
LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png"); LoadTexture(MenuQuitTexture, MENU_ITEM_PATH "BasicQuit.png");
LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png"); LoadTexture(MenuOptionsTexture, MENU_ITEM_PATH "test.png");
LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png"); LoadTexture(MenuStartTexture, MENU_ITEM_PATH "BasicPlay.png");
TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png"); TextureAtlas::TextureIndex texDirtIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal3.png");
TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png"); TextureAtlas::TextureIndex texIceIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "metal2.png");
TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png"); TextureAtlas::TextureIndex texGrassIndex = m_textureAtlas.AddTexture(TEXTURE_PATH "grass.png");
@@ -461,16 +510,13 @@ void Engine::ProcessNotificationQueue() {
//float fPosY = Height() - (Height() * 0.05) * scaleY; //float fPosY = Height() - (Height() * 0.05) * scaleY;
m_textureFont.Bind(); m_textureFont.Bind();
float xOffset = Width() * 0.66f;
auto [scaleX, scaleY] = GetScale(); float yOffset = Height() * 0.83f;
float xOffset = (Width() / 1.5f) * scaleX;
float yOffset = (Height() / 1.2f) * scaleY;
for (auto it = notifications.begin(); it != notifications.end(); ) { for (auto it = notifications.begin(); it != notifications.end(); ) {
float timeSinceDisplay = m_time - it->displayStartTime; float timeSinceDisplay = m_time - it->displayStartTime;
float y = yOffset - (20.0f * scaleX * (it - notifications.begin())); float y = yOffset - (20.0f * (it - notifications.begin()));
glDisable(GL_STENCIL_TEST); glDisable(GL_STENCIL_TEST);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
@@ -543,14 +589,13 @@ void Engine::DisplayPovGun() {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
float scaleX = (Width()) / BASE_WIDTH; float baseXOffsetPercentage = 0.4958;
float scaleY = (Height()) / BASE_HEIGHT; float baseWidthPercentage = 0.4688;
float baseXOffset = 0.4958 * BASE_WIDTH; float baseHeightPercentage = 0.5787;
float baseWidth = 0.4688 * BASE_WIDTH;
float baseHeight = 0.5787 * BASE_HEIGHT; float xTranslation = baseXOffsetPercentage * Width();
float xTranslation = baseXOffset * scaleX; float quadWidth = baseWidthPercentage * Width();
float quadWidth = baseWidth * scaleX; float quadHeight = baseHeightPercentage * Height();
float quadHeight = baseHeight * scaleY;
m_texturePovGun.Bind(); m_texturePovGun.Bind();
glLoadIdentity(); glLoadIdentity();
@@ -575,7 +620,6 @@ void Engine::DisplayPovGun() {
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPopMatrix(); glPopMatrix();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopMatrix(); glPopMatrix();
} }
@@ -588,37 +632,44 @@ void Engine::DisplayHud(int timer) {
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
glLoadIdentity(); glLoadIdentity();
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
auto [scaleX, scaleY] = GetScale();
float fBackPosX = (Width() / 25.0f) * scaleX; float itemBackgroundWidthProportion = 0.25f;
float fBackPosY = (Height() - (Height() * 0.815) * scaleY); float itemBackgroundHeightProportion = 0.175f;
float fBackWidth = (Width() / 4.0f) * scaleX; float itemBackgroundWidth = Width() * itemBackgroundWidthProportion;
float fBackHeight = (Height() / 5.5f) * scaleY; float itemBackgroundHeight = Height() * itemBackgroundHeightProportion;
float itemBackgroundXOffset = Width() * 0.05f;
float itemBackgroundYOffset = Height() * 0.6f;
float itemBackgroundXPos = itemBackgroundXOffset;
float itemBackgroundYPos = Height() - itemBackgroundHeight - itemBackgroundYOffset;
// Selected item background
glColor4f(1.0f, 1.0f, 1.0f, 0.2f); glColor4f(1.0f, 1.0f, 1.0f, 0.2f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(fBackPosX, fBackPosY); glVertex2f(itemBackgroundXPos, itemBackgroundYPos);
glVertex2f(fBackPosX + fBackWidth, fBackPosY); glVertex2f(itemBackgroundXPos + itemBackgroundWidth, itemBackgroundYPos);
glVertex2f(fBackPosX + fBackWidth, fBackPosY + fBackHeight); glVertex2f(itemBackgroundXPos + itemBackgroundWidth, itemBackgroundYPos + itemBackgroundHeight);
glVertex2f(fBackPosX, fBackPosY + fBackHeight); glVertex2f(itemBackgroundXPos, itemBackgroundYPos + itemBackgroundHeight);
glEnd(); glEnd();
// HP Bar // HP Bar
float fBarWidth = (Width() / 4.0f) * scaleX;
float fBarHeight = (Height() / 25.0f) * scaleY;
float fPosX = (Width() / 25.0f) * scaleX;
float fBarPosY = (Height() - (Height() * 0.775) * scaleY);
float playerHp = m_player.GetHP(); float playerHp = m_player.GetHP();
float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f; float facteurOmbrage = m_displayInfo ? 0.5f : 1.0f;
float hpBarWidthProportion = 0.25f;
float hpBarHeightProportion = 0.045f;
float hpBarWidth = Width() * hpBarWidthProportion;
float hpBarHeight = Height() * hpBarHeightProportion;
float hpBarXOffset = Width() * 0.05f;
float hpBarYOffset = Height() * 0.7f;
float hpBarYPos = Height() - hpBarHeight - hpBarYOffset;
// HP Bar Background // HP Bar Background
glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage); glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(fPosX, fBarPosY - fBarHeight); glVertex2f(itemBackgroundXPos, hpBarYPos - hpBarHeight);
glVertex2f(fPosX + fBarWidth, fBarPosY - fBarHeight); glVertex2f(itemBackgroundXPos + itemBackgroundWidth, hpBarYPos - hpBarHeight);
glVertex2f(fPosX + fBarWidth, fBarPosY); glVertex2f(itemBackgroundXPos + itemBackgroundWidth, hpBarYPos);
glVertex2f(fPosX, fBarPosY); glVertex2f(itemBackgroundXPos, hpBarYPos);
glEnd(); glEnd();
//TODO: Associer avec mechanique de vie du joueur //TODO: Associer avec mechanique de vie du joueur
@@ -626,10 +677,10 @@ void Engine::DisplayHud(int timer) {
// Barre HP // Barre HP
glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage); glColor3f(0.0f * facteurOmbrage, 1.0f * facteurOmbrage, 0.0f * facteurOmbrage);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2f(fPosX, fBarPosY - fBarHeight); glVertex2f(itemBackgroundXPos, hpBarYPos - hpBarHeight);
glVertex2f(fPosX + fBarWidth * playerHp, fBarPosY - fBarHeight); glVertex2f(itemBackgroundXPos + itemBackgroundWidth * playerHp, hpBarYPos - hpBarHeight);
glVertex2f(fPosX + fBarWidth * playerHp, fBarPosY); glVertex2f(itemBackgroundXPos + itemBackgroundWidth * playerHp, hpBarYPos);
glVertex2f(fPosX, fBarPosY); glVertex2f(itemBackgroundXPos, hpBarYPos);
glEnd(); glEnd();
// Equip Bar // Equip Bar
@@ -637,22 +688,23 @@ void Engine::DisplayHud(int timer) {
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage); glColor3f(1.0f * facteurOmbrage, 1.0f * facteurOmbrage, 1.0f * facteurOmbrage);
float fEquipWidth = (Width() * 0.175f) * scaleX; float equipWidthProportion = 0.8f;
float fEquipHeight = (fEquipWidth / 2.5) * scaleY; float equipHeightProportion = 0.7f;
float fEquipPosY = (Height() - (Height() * 0.765) * scaleY); float equipWidth = itemBackgroundWidth * equipWidthProportion;
float equipHeight = itemBackgroundHeight * equipHeightProportion;
float equipXOffset = itemBackgroundXPos + (itemBackgroundWidth - equipWidth) * 0.1f;
float equipYOffset = itemBackgroundYPos + (itemBackgroundHeight - equipHeight) * 0.75f;
glTranslatef(fPosX, fEquipPosY, 0); glTranslatef(equipXOffset, equipYOffset, 0);
m_textureGun.Bind(); m_textureGun.Bind();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2i(0, 0); glTexCoord2f(0, 0); glVertex2f(0, 0);
glTexCoord2f(1, 0); glVertex2i(fEquipWidth, 0); glTexCoord2f(1, 0); glVertex2f(equipWidth, 0);
glTexCoord2f(1, 1); glVertex2i(fEquipWidth, fEquipHeight); glTexCoord2f(1, 1); glVertex2f(equipWidth, equipHeight);
glTexCoord2f(0, 1); glVertex2i(0, fEquipHeight); glTexCoord2f(0, 1); glVertex2f(0, equipHeight);
glEnd(); glEnd();
//glDisable(GL_BLEND);
// Username // Username
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE);
@@ -660,30 +712,37 @@ void Engine::DisplayHud(int timer) {
m_textureFont.Bind(); m_textureFont.Bind();
std::ostringstream ss; std::ostringstream ss;
float fUsernamePosY = fBarPosY - (fBarHeight * 2) * scaleY; float fUsernamePosY = hpBarYPos - (hpBarHeight * 2);
ss.str(""); ss.str("");
ss << m_player.GetUsername(); ss << m_player.GetUsername();
PrintText(fPosX, fUsernamePosY, ss.str(), 1.5f); PrintText(itemBackgroundXPos, fUsernamePosY, ss.str(), 1.5f);
ss.str(""); ss.str("");
ss << m_player.GetHP() * 100 << "%"; ss << m_player.GetHP() * 100 << "%";
PrintText(fPosX * 6.25, fUsernamePosY, ss.str(), 1.5f); PrintText(itemBackgroundXPos * 5.25f, fUsernamePosY, ss.str(), 1.5f);
float countdownXOffset = Width() * 0.2f;
float countdownYOffset = Height() * 0.1f;
float countdownXPos = Width() - countdownXOffset;
float countdownYPos = Height() - countdownYOffset;
// Countdown // Countdown
ss.str(""); ss.str("");
ss << "Time: " << (int)(timer / 60) << ":" << std::setw(2) << std::setfill('0') << timer % 60; ss << "Time: " << (int)(timer / 60) << ":" << std::setw(2) << std::setfill('0') << timer % 60;
PrintText(Width() - (Width() * 0.2f) * scaleX, Height() - (Height() * 0.1) * scaleY, ss.str(), 2.0f); PrintText(countdownXPos, countdownYPos, ss.str(), 2.0f);
} }
void Engine::DisplayInfo(float elapsedTime, BlockType bloc) { void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
m_textureFont.Bind(); m_textureFont.Bind();
std::ostringstream ss; std::ostringstream ss;
auto [scaleX, scaleY] = GetScale(); float marginX = Width() * 0.01;
float marginY = Height() * 0.05;
float fPosX = marginX;
float fPosY = Height() - marginY;
float fPosX = (Width() / 100.0f) * scaleX;
float fPosY = Height() - (Height() * 0.05) * scaleY;
float charSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600); float charSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600);
ss << " Fps : " << GetFps(elapsedTime); ss << " Fps : " << GetFps(elapsedTime);
@@ -701,7 +760,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
ss.str(""); ss.str("");
fPosY -= charSize; fPosY -= charSize;
float fPosYJump = ((Height() - (Height() * 0.9f)) * scaleY); float fPosYJump = Height() * 0.09;
fPosY = fPosYJump; fPosY = fPosYJump;
fPosY -= charSize; fPosY -= charSize;
@@ -729,6 +788,9 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
} }
void Engine::DisplaySingleOrMultiplayerMenu() { void Engine::DisplaySingleOrMultiplayerMenu() {
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendEquation(GL_FUNC_ADD); glBlendEquation(GL_FUNC_ADD);
@@ -745,64 +807,92 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushMatrix(); glPushMatrix();
auto [scaleX, scaleY] = GetScale(); // Background
float fBackPosX = 0.0f;
float fBackPosY = 0.0f;
float fBackWidth = Width();
float fBackHeight = Height();
m_textureSoloMultiMenu.Bind(); m_textureSoloMultiMenu.Bind();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fBackPosX, fBackPosY); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fBackWidth, fBackPosY); glTexCoord2f(1.0f, 0.0f); glVertex2f(Width(), 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fBackWidth, fBackHeight); glTexCoord2f(1.0f, 1.0f); glVertex2f(Width(), Height());
glTexCoord2f(0.0f, 1.0f); glVertex2f(fBackPosX, fBackHeight); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, Height());
glEnd(); glEnd();
float centerX = (Width() / 2.0f); // Title
float centerY = (Height() / 2.0f); float titleWidthProportion = 0.4f;
float titleWidth = (centerX * 1.85f) * scaleX; float titleHeightProportion = 0.4f;
float titleHeight = (centerY * 1.85f) * scaleY; 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());
// Solo game indicator
m_textureTitle.Bind(); m_textureTitle.Bind();
glColor4f(1.0f, 0.5f, 0.0f, 1.0f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(centerX, centerY); glTexCoord2f(0.0f, 0.0f); glVertex2f(m_titleX, m_titleY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(titleWidth, centerY); glTexCoord2f(1.0f, 0.0f); glVertex2f(m_titleX + titleWidth, m_titleY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(titleWidth, titleHeight); glTexCoord2f(1.0f, 1.0f); glVertex2f(m_titleX + titleWidth, m_titleY + titleHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(centerX, titleHeight); glTexCoord2f(0.0f, 1.0f); glVertex2f(m_titleX, m_titleY + titleHeight);
glEnd(); glEnd();
glBindTexture(GL_TEXTURE_2D, 0); glBindTexture(GL_TEXTURE_2D, 0);
// Solo game indicator // Single Player and Multiplayer button background quads
float fPosX = (centerX * 1.1f) * scaleX; float buttonWidthProportion = 0.4f;
float fPosXWidth = (centerX * 1.75f) * scaleX; float buttonHeightProportion = 0.075f;
float soloPosY = (centerY * 0.75f) * scaleY; float buttonWidth = buttonWidthProportion * Width();
float soloHeight = (centerY * 0.9f) * scaleY; 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); glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, soloPosY); glTexCoord2f(0.0f, 0.0f); glVertex2f(buttonPosX, buttonSinglePosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, soloPosY); glTexCoord2f(1.0f, 0.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, soloHeight); glTexCoord2f(1.0f, 1.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY + buttonHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, soloHeight); glTexCoord2f(0.0f, 1.0f); glVertex2f(buttonPosX, buttonSinglePosY + buttonHeight);
glEnd(); glEnd();
// Multiplayer game indicator // Single Player text
float multiPosY = (centerY * 0.5f) * scaleY; m_textureSoloText.Bind();
float multiHeight = (centerY * 0.65f) * scaleY; glColor4f(0.75f, 0.05f, 0.0f, 1.0f);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex2f(fPosX, multiPosY); glTexCoord2f(0.0f, 0.0f); glVertex2f(buttonPosX, buttonSinglePosY);
glTexCoord2f(1.0f, 0.0f); glVertex2f(fPosXWidth, multiPosY); glTexCoord2f(1.0f, 0.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY);
glTexCoord2f(1.0f, 1.0f); glVertex2f(fPosXWidth, multiHeight); glTexCoord2f(1.0f, 1.0f); glVertex2f(buttonPosX + buttonWidth, buttonSinglePosY + buttonHeight);
glTexCoord2f(0.0f, 1.0f); glVertex2f(fPosX, multiHeight); 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(); glEnd();
// TODO: Add SOLO / MULTIPLAYER text with font
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); 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); glEnable(GL_STENCIL_TEST);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
@@ -811,6 +901,8 @@ void Engine::DisplaySingleOrMultiplayerMenu() {
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopMatrix(); glPopMatrix();
ShowCursor();
} }
void Engine::DrawHud(float elapsedTime, BlockType bloc) { void Engine::DrawHud(float elapsedTime, BlockType bloc) {
@@ -869,10 +961,13 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
} }
void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) { void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) {
auto [scaleX, scaleY] = GetScale(); float windowWidth = static_cast<float>(Width());
float scale = std::min(scaleX, scaleY); float windowHeight = static_cast<float>(Height());
float baseCharSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600); float posX = x * windowWidth;
float posY = y * windowHeight;
float baseCharSize = 20 + (24 - 20) * (windowWidth - 1600) / (1920 - 1600);
float charSize = baseCharSize * charSizeMultiplier; float charSize = baseCharSize * charSizeMultiplier;
glLoadIdentity(); glLoadIdentity();
@@ -885,21 +980,15 @@ void Engine::PrintText(float x, float y, const std::string& t, float charSizeMul
glBegin(GL_QUADS); glBegin(GL_QUADS);
glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0); glTexCoord2f(left, 1.f - top - .0625f); glVertex2f(0, 0);
glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(charSize * scale, 0); glTexCoord2f(left + .0625f, 1.f - top - .0625f); glVertex2f(charSize, 0);
glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(charSize * scale, charSize * scale); glTexCoord2f(left + .0625f, 1.f - top); glVertex2f(charSize, charSize);
glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize * scale); glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize);
glEnd(); glEnd();
glTranslated(0.5555f * charSize * scale, 0, 0); glTranslated(0.5555f * charSize, 0, 0);
} }
} }
std::pair<float, float> Engine::GetScale() const {
float widthRatio = static_cast<float>(Width()) / BASE_WIDTH;
float heightRatio = static_cast<float>(Height()) / BASE_HEIGHT;
return { widthRatio, heightRatio };
}
int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; } int Engine::GetFps(float elapsedTime) const { return 1 / elapsedTime; }
int Engine::GetCountdown(float elapsedTime) { int Engine::GetCountdown(float elapsedTime) {
@@ -919,8 +1008,9 @@ void Engine::Render(float elapsedTime) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
m_time_SplashScreen += elapsedTime; m_time_SplashScreen += elapsedTime;
if(m_time_SplashScreen < 2) if (m_time_SplashScreen < 2) {
DrawSplachScreen(); DrawSplachScreen();
}
else if (m_gamestate == GameState::PLAY) else if (m_gamestate == GameState::PLAY)
{ {
HideCursor(); HideCursor();
@@ -1076,7 +1166,16 @@ void Engine::Render(float elapsedTime) {
} }
else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS) else if (m_gamestate == GameState::MAIN_MENU || m_gamestate == GameState::OPTIONS)
{ {
DrawMenu(); if (!m_soloMultiChoiceMade) {
DisplaySingleOrMultiplayerMenu();
}
else {
DrawMenu();
}
}
else if (m_gamestate == GameState::PAUSE)
{
DrawPause();
} }
else if (m_gamestate == GameState::QUIT) else if (m_gamestate == GameState::QUIT)
Stop(); Stop();
@@ -1105,7 +1204,14 @@ void Engine::KeyPressEvent(unsigned char key) {
} }
break; break;
case 36: // ESC - Quitter case 36: // ESC - Quitter
m_gamestate = GameState::MAIN_MENU; if (m_gamestate == GameState::PLAY)
{
m_gamestate = GameState::PAUSE;
}
else if (m_gamestate == GameState::PAUSE)
{
m_gamestate = GameState::PLAY;
}
//Stop(); //Stop();
break; break;
case 57: // Space - Sauter case 57: // Space - Sauter
@@ -1272,6 +1378,37 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 300 && m_mousemy <= 400)) if ((m_mousemx >= 305 && m_mousemx <= 450) && (m_mousemy >= 300 && m_mousemy <= 400))
m_gamestate = GameState::QUIT; m_gamestate = GameState::QUIT;
} }
else if (m_gamestate == GameState::OPTIONS)
{
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;
float adjustedMouseY = Height() - m_mousemy;
// 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;
}
// 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;
}
}
} }
void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) { void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {

View File

@@ -26,6 +26,7 @@ public:
Engine(); Engine();
virtual ~Engine(); virtual ~Engine();
virtual void DrawMenu(); virtual void DrawMenu();
virtual void DrawPause();
virtual void DrawSplachScreen(); virtual void DrawSplachScreen();
virtual void Init(); virtual void Init();
virtual void DeInit(); virtual void DeInit();
@@ -39,8 +40,6 @@ public:
virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y); virtual void MouseReleaseEvent(const MOUSE_BUTTON &button, int x, int y);
private: private:
std::pair<float, float> GetScale() const;
int GetFps(float elapsedTime) const; int GetFps(float elapsedTime) const;
int GetCountdown(float elapsedTime); int GetCountdown(float elapsedTime);
@@ -74,6 +73,8 @@ private:
Texture m_texturePovGun; Texture m_texturePovGun;
Texture m_textureSkybox; Texture m_textureSkybox;
Texture m_textureSoloMultiMenu; Texture m_textureSoloMultiMenu;
Texture m_textureSoloText;
Texture m_textureMultiText;
Texture m_textureTitle; Texture m_textureTitle;
Skybox m_skybox; Skybox m_skybox;
@@ -90,18 +91,21 @@ private:
std::map<uint64_t, Player*> m_players; std::map<uint64_t, Player*> m_players;
//Menu //Menu
enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY }; enum class GameState: uint8_t { MAIN_MENU, OPTIONS, QUIT, NEWG, PLAY, PAUSE };
GameState m_gamestate = GameState::MAIN_MENU; GameState m_gamestate = GameState::MAIN_MENU;
Texture MenuTitleTexture; Texture MenuTitleTexture;
Texture MenuBGTexture; Texture MenuBGTexture;
Texture MenuStartTexture; Texture MenuStartTexture;
Texture MenuQuitTexture; Texture MenuQuitTexture;
Texture MenuOptionsTexture; Texture MenuOptionsTexture;
Texture PauseBGTexture;
Texture SplachScreenTexture; Texture SplachScreenTexture;
float m_scale; float m_scale;
float m_time = 0; float m_time = 0;
float m_time_SplashScreen = 0; float m_time_SplashScreen = 0;
float m_titleX = 0;
float m_titleY = 0;
float m_Width = 0; float m_Width = 0;
float m_Height = 0; float m_Height = 0;
@@ -118,7 +122,7 @@ private:
bool m_displayHud = true; bool m_displayHud = true;
bool m_displayInfo = false; bool m_displayInfo = false;
bool m_resetcountdown = false; bool m_resetcountdown = false;
bool m_soloMultiChoiceMade = true; bool m_soloMultiChoiceMade = false;
bool m_stopcountdown = false; bool m_stopcountdown = false;
bool m_keyK = false; bool m_keyK = false;

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@@ -9,7 +9,7 @@ Mesh::~Mesh() {
void Mesh::FlushMeshToVBO() { void Mesh::FlushMeshToVBO() {
m_vertexBuffer.SetMeshData(m_vd, m_vcount); m_vertexBuffer.SetMeshData(m_vd, m_vcount);
m_vcount = 0; m_vcount = 0;
delete[] m_vd; //delete[] m_vd;
} }
void Mesh::FlushVBO() { void Mesh::FlushVBO() {