Push mouse sensitivity

This commit is contained in:
mduval76
2023-12-13 17:15:58 -05:00
parent 6c68114fbb
commit 6ba316aa2d
5 changed files with 58 additions and 30 deletions

View File

@@ -229,6 +229,8 @@ void Engine::LoadResource() {
m_boostinfo[BTYPE_INVINCIBLE] = new BoostInfo(BTYPE_INVINCIBLE, "Inv", u, v, s, 1);
m_animeAtlas.TextureIndexToCoord(0, u, v, s, s);
m_sensitivity = m_player.GetSensitivity();
m_options.SetMouseSensitivity(m_sensitivity);
std::cout << " Loading and compiling shaders ..." << std::endl;
if (!m_shader01.Load(SHADER_PATH "shader01.vert", SHADER_PATH "shader01.frag", true)) {
@@ -1623,8 +1625,8 @@ void Engine::DisplayGameplayMenu(float centerX, float centerY) {
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);
DrawSlider(centerX, centerY, m_sensitivity, minBar, maxBar, sensibleBottom, sensibleTop);
DisplayBarPercentValue(centerX, centerY, percentPosX, sensibleBottom, minBar, maxBar, m_sensitivity);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
}
@@ -1644,7 +1646,14 @@ void Engine::DisplayBarPercentValue(float centerX, float centerY, float posX, fl
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
float percentage = (value / (maxVal - minVal)) * 100;
if (value < 0.1f) {
value = 0.1f;
}
else if (value > 1.0f) {
value = 1.0f;
}
float percentage = value * 100;
if (percentage < 0.0f) {
percentage = 0.0f;
@@ -1665,19 +1674,23 @@ void Engine::DisplayBarPercentValue(float centerX, float centerY, float posX, fl
}
void Engine::DrawSlider(float centerX, float centerY, float value, float minVal, float maxVal, float bottomSideValue, float topSideValue) {
if (value < 0.0f) {
value = 0.0f;
float barLength = maxVal - minVal;
if (value < 0.1f) {
value = 0.1f;
}
else if (value > (maxVal - minVal)) {
value = (maxVal - minVal);
else if (value > 1.0f) {
value = 1.0f;
}
if (value >= 0.0f && value <= (maxVal - minVal)) {
float scaledLength = minVal + value * barLength;
if (value >= 0.0f && value <= 1.0f) {
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(1, 0); glVertex2i(scaledLength, bottomSideValue);
glTexCoord2f(1, 1); glVertex2i(scaledLength, topSideValue);
glTexCoord2f(0, 1); glVertex2i(minVal, topSideValue);
glEnd();
}
@@ -2095,11 +2108,10 @@ void Engine::HandlePlayerInput(float elapsedTime) {
PrintText(Width() * 0.6f, Height() * 0.4f, ss.str(), 2.0f);
}
void Engine::MouseMoveEvent(int x, int y) {
if (m_gamestate == GameState::PLAY) {
m_player.TurnLeftRight(x - (Width() / 2));
m_player.TurnTopBottom(y - (Height() / 2));
m_player.TurnLeftRight(x - (Width() / 2), m_sensitivity);
m_player.TurnTopBottom(y - (Height() / 2), m_sensitivity);
// Centrer la souris seulement si elle n'est pas d<>j<EFBFBD> centr<74>e
// Il est n<>cessaire de faire la v<>rification pour <20>viter de tomber
@@ -2117,18 +2129,21 @@ void Engine::MouseMoveEvent(int x, int y) {
float centerY = Height() * 0.5f;
float leftBar = centerX - Width() * 0.15f;
float rightBar = centerX + Width() * 0.3f;
float barLength = rightBar - leftBar;
float normalizedPosition = (x - leftBar) / barLength;
if (m_selectedOption == 0 && m_selectedOptAudioMainBar) {
m_volPrincipal = x - leftBar;
m_volPrincipal = normalizedPosition;
}
else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) {
m_volMusique = x - leftBar;
m_volMusique = normalizedPosition;
}
else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) {
m_volEffets = x - leftBar;
m_volEffets = normalizedPosition;
}
else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) {
m_volSensible = x - leftBar;
m_sensitivity = normalizedPosition;
}
}
}
@@ -2237,6 +2252,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
// Audio
float leftBar = centerX - Width() * 0.15f;
float rightBar = centerX + Width() * 0.3f;
float barLength = rightBar - leftBar;
float topBarPrincipal = centerY - Height() * 0.165f;
float bottomBarPrincipal = centerY - Height() * 0.2f;
@@ -2247,6 +2263,8 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
float topBarEffets = centerY + Height() * 0.085f;
float bottomBarEffets = centerY + Height() * 0.05f;
float normalizedPosition = (x - leftBar) / barLength;
if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
m_volPrincipal = x - leftBar;
m_selectedOptAudioMainBar = true;
@@ -2291,7 +2309,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
// Gameplay
if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
m_volSensible = x - leftBar;
m_sensitivity = normalizedPosition;
m_selectedGameplaySensitivityBar = true;
}
}

View File

@@ -180,7 +180,7 @@ private:
float m_volPrincipal = 0.0f;
float m_volMusique = 0.0f;
float m_volEffets = 0.0f;
float m_volSensible = 0.0f;
float m_sensitivity;
int m_selectedOption = 0;

View File

@@ -9,7 +9,7 @@ Settings::Settings(Audio& audio)
m_fullscreen(false),
m_brightness(0.5f),
m_contrast(0.5f),
m_mouseSensitivity(0.5f) {
m_mouseSensitivity(0.0f) {
ApplyResolution(m_resolution);
}