Push placement text notification queue
This commit is contained in:
parent
db0a39f64a
commit
df5b7960b2
@ -5,8 +5,6 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <queue>
|
#include <queue>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Define a structure to represent notifications
|
// Define a structure to represent notifications
|
||||||
struct Notification {
|
struct Notification {
|
||||||
std::string message;
|
std::string message;
|
||||||
@ -97,6 +95,7 @@ void Engine::LoadResource() {
|
|||||||
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
LoadTexture(m_textureFont, TEXTURE_PATH "font.bmp", true);
|
||||||
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_textureStartMenu, TEXTURE_PATH "startmenu.png", false);
|
||||||
|
|
||||||
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");
|
||||||
@ -147,7 +146,6 @@ void Engine::KillNotification(Player killer, Player killed) {
|
|||||||
DisplayNotification(message);
|
DisplayNotification(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Engine::DisplayNotification(std::string message) {
|
void Engine::DisplayNotification(std::string message) {
|
||||||
|
|
||||||
if (message.length() > 45) {
|
if (message.length() > 45) {
|
||||||
@ -157,23 +155,27 @@ void Engine::DisplayNotification(std::string message) {
|
|||||||
Notification newNotification;
|
Notification newNotification;
|
||||||
newNotification.message = message;
|
newNotification.message = message;
|
||||||
newNotification.displayStartTime = m_time;
|
newNotification.displayStartTime = m_time;
|
||||||
|
|
||||||
notifications.push_back(newNotification);
|
notifications.push_back(newNotification);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a method to process the notification queue
|
// Add a method to process the notification queue
|
||||||
void Engine::ProcessNotificationQueue() {
|
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();
|
m_textureFont.Bind();
|
||||||
|
|
||||||
auto [scaleX, scaleY] = GetScale();
|
auto [scaleX, scaleY] = GetScale();
|
||||||
|
|
||||||
unsigned int xOffset = static_cast<unsigned int>((BASE_WIDTH - BASE_WIDTH * 0.26f) * scaleX);
|
float xOffset = (Width() / 1.5f) * scaleX;
|
||||||
unsigned int yOffset = static_cast<unsigned int>((BASE_HEIGHT - (BASE_HEIGHT / 2.2f)) * scaleY);
|
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;
|
||||||
|
|
||||||
unsigned int y = yOffset - static_cast<unsigned int>(20.0f * scaleX * (it - notifications.begin()));
|
float y = yOffset - (20.0f * scaleX * (it - notifications.begin()));
|
||||||
|
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
@ -212,21 +214,20 @@ void Engine::ProcessNotificationQueue() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Engine::DisplayCrosshair() {
|
void Engine::DisplayCrosshair() {
|
||||||
m_textureCrosshair.Bind();
|
m_textureCrosshair.Bind();
|
||||||
static const int crossSize = 32;
|
static const int crossSize = 32;
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
|
glTranslated(Width() / 2 - crossSize / 2, Height() / 2 - crossSize / 2, 0);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2f(0, 0);
|
glTexCoord2f(0, 0);
|
||||||
glVertex2i(0, 0);
|
glVertex2i(0, 0);
|
||||||
glTexCoord2f(1, 0);
|
glTexCoord2f(1, 0);
|
||||||
glVertex2i(crossSize, 0);
|
glVertex2i(crossSize, 0);
|
||||||
glTexCoord2f(1, 1);
|
glTexCoord2f(1, 1);
|
||||||
glVertex2i(crossSize, crossSize);
|
glVertex2i(crossSize, crossSize);
|
||||||
glTexCoord2f(0, 1);
|
glTexCoord2f(0, 1);
|
||||||
glVertex2i(0, crossSize);
|
glVertex2i(0, crossSize);
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,8 +248,8 @@ void Engine::DisplayPovGun() {
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
float scaleX = static_cast<float>(Width()) / BASE_WIDTH;
|
float scaleX = (Width()) / BASE_WIDTH;
|
||||||
float scaleY = static_cast<float>(Height()) / BASE_HEIGHT;
|
float scaleY = (Height()) / BASE_HEIGHT;
|
||||||
float baseXOffset = 0.4958 * BASE_WIDTH;
|
float baseXOffset = 0.4958 * BASE_WIDTH;
|
||||||
float baseWidth = 0.4688 * BASE_WIDTH;
|
float baseWidth = 0.4688 * BASE_WIDTH;
|
||||||
float baseHeight = 0.5787 * BASE_HEIGHT;
|
float baseHeight = 0.5787 * BASE_HEIGHT;
|
||||||
@ -310,6 +311,33 @@ void Engine::DisplayHud(int timer) {
|
|||||||
glEnd();
|
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
|
// HP Bar
|
||||||
float fBarWidth = (Width() / 4.0f) * scaleX;
|
float fBarWidth = (Width() / 4.0f) * scaleX;
|
||||||
float fBarHeight = (Height() / 25.0f) * scaleY;
|
float fBarHeight = (Height() / 25.0f) * scaleY;
|
||||||
@ -388,7 +416,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
|||||||
float fPosX = (Width() / 100.0f) * scaleX;
|
float fPosX = (Width() / 100.0f) * scaleX;
|
||||||
float fPosY = Height() - (Height() * 0.05) * scaleY;
|
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);
|
||||||
PrintText(fPosX, fPosY, ss.str());
|
PrintText(fPosX, fPosY, ss.str());
|
||||||
ss.str("");
|
ss.str("");
|
||||||
@ -404,7 +432,7 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
|||||||
ss.str("");
|
ss.str("");
|
||||||
fPosY -= charSize;
|
fPosY -= charSize;
|
||||||
|
|
||||||
float fPosYJump = static_cast<unsigned int>((Height() - (Height() * 0.9f)) * scaleY);
|
float fPosYJump = ((Height() - (Height() * 0.9f)) * scaleY);
|
||||||
fPosY = fPosYJump;
|
fPosY = fPosYJump;
|
||||||
fPosY -= charSize;
|
fPosY -= charSize;
|
||||||
|
|
||||||
@ -431,6 +459,50 @@ void Engine::DisplayInfo(float elapsedTime, BlockType bloc) {
|
|||||||
PrintText(fPosX, fPosYJump, ss.str());
|
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) {
|
void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
||||||
// Setter le blend function, tout ce qui sera noir sera transparent
|
// Setter le blend function, tout ce qui sera noir sera transparent
|
||||||
glDisable(GL_STENCIL_TEST);
|
glDisable(GL_STENCIL_TEST);
|
||||||
@ -455,7 +527,7 @@ void Engine::DrawHud(float elapsedTime, BlockType bloc) {
|
|||||||
m_keyK = false;
|
m_keyK = false;
|
||||||
}
|
}
|
||||||
if (m_keyL) {
|
if (m_keyL) {
|
||||||
|
|
||||||
KillNotification(m_player, m_player);
|
KillNotification(m_player, m_player);
|
||||||
m_keyL = false;
|
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) {
|
void Engine::PrintText(float x, float y, const std::string& t, float charSizeMultiplier) {
|
||||||
auto [scaleX, scaleY] = GetScale();
|
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 baseCharSize = 20 + (24 - 20) * (Width() - 1600) / (1920 - 1600);
|
||||||
float charSize = baseCharSize * charSizeMultiplier;
|
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);
|
glTexCoord2f(left, 1.f - top); glVertex2f(0, charSize * scale);
|
||||||
glEnd();
|
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)
|
if (m_countdown < m_time)
|
||||||
Stop();
|
Stop();
|
||||||
if(!m_stopcountdown)
|
if (!m_stopcountdown)
|
||||||
m_time += elapsedTime;
|
m_time += elapsedTime;
|
||||||
return m_countdown - (int)m_time;
|
return m_countdown - (int)m_time;
|
||||||
}
|
}
|
||||||
@ -626,10 +698,10 @@ void Engine::Render(float elapsedTime) {
|
|||||||
|
|
||||||
if (m_isSkybox) m_skybox.Render(skybox);
|
if (m_isSkybox) m_skybox.Render(skybox);
|
||||||
|
|
||||||
ProcessNotificationQueue();
|
|
||||||
DrawHud(elapsedTime, bloc);
|
DrawHud(elapsedTime, bloc);
|
||||||
DisplayPovGun();
|
DisplayPovGun();
|
||||||
|
ProcessNotificationQueue();
|
||||||
|
|
||||||
static bool fell = false;
|
static bool fell = false;
|
||||||
if (m_player.GetPosition().y < 1.7f && !fell) {
|
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);
|
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
|
case 17: // R - Ignorer
|
||||||
break;
|
break;
|
||||||
case 19: // T - Ignorer
|
case 19: // T - Ignorer
|
||||||
break;
|
break;
|
||||||
case 24: // Y - Ignorer
|
case 24: // Y - Ignorer
|
||||||
break;
|
break;
|
||||||
case 255: // Fn - Ignorer
|
case 255: // Fn - Ignorer
|
||||||
|
@ -52,6 +52,7 @@ private:
|
|||||||
void DisplayCurrentItem();
|
void DisplayCurrentItem();
|
||||||
void DisplayHud(int timer);
|
void DisplayHud(int timer);
|
||||||
void DisplayInfo(float elapsedTime, BlockType bloc);
|
void DisplayInfo(float elapsedTime, BlockType bloc);
|
||||||
|
void DisplaySingleOrMultiplayerMenu();
|
||||||
void DrawHud(float elapsedTime, BlockType bloc);
|
void DrawHud(float elapsedTime, BlockType bloc);
|
||||||
void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);
|
void PrintText(float x, float y, const std::string& t, float charSizeMultiplier = 1.0f);
|
||||||
|
|
||||||
@ -63,11 +64,12 @@ private:
|
|||||||
World m_world = World();
|
World m_world = World();
|
||||||
WorldRenderer m_wrenderer = WorldRenderer();
|
WorldRenderer m_wrenderer = WorldRenderer();
|
||||||
|
|
||||||
Texture m_textureSkybox;
|
|
||||||
Texture m_textureFont;
|
|
||||||
Texture m_textureCrosshair;
|
Texture m_textureCrosshair;
|
||||||
|
Texture m_textureFont;
|
||||||
Texture m_textureGun;
|
Texture m_textureGun;
|
||||||
Texture m_texturePovGun;
|
Texture m_texturePovGun;
|
||||||
|
Texture m_textureSkybox;
|
||||||
|
Texture m_textureStartMenu;
|
||||||
|
|
||||||
Skybox m_skybox;
|
Skybox m_skybox;
|
||||||
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
Audio m_audio = Audio(AUDIO_PATH "start.wav");
|
||||||
|
BIN
SQCSim2021/media/textures/StartMenu.png
Normal file
BIN
SQCSim2021/media/textures/StartMenu.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 MiB |
BIN
SQCSim2021/media/textures/Titre.png
Normal file
BIN
SQCSim2021/media/textures/Titre.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
Loading…
x
Reference in New Issue
Block a user