Push mainvolume et musicvolume sliders fonctionnels. Bug sfx

This commit is contained in:
mduval76 2023-12-14 00:08:07 -05:00
parent 67270a0b21
commit 383a19cbd2
5 changed files with 71 additions and 23 deletions

View File

@ -5,7 +5,7 @@ Player::Player(const Vector3f& position, float rotX, float rotY) : m_position(po
m_velocity = Vector3f(0, 0, 0);
m_airborne = true;
m_hp = 1.0f;
m_sensitivity = 0.1f;
m_sensitivity = 0.5f;
m_username = "Zelda Bee-Bop56";
}

View File

@ -18,6 +18,9 @@ Audio::Audio(const char * music, const char* menumusic) {
m_menumusic = m_engine->play2D(menumusic, true, true, true, irrklang::ESM_STREAMING);
m_music->setVolume(.5);
m_menumusic->setVolume(.5);
m_mainvolume = 0.5f;
m_engine->setSoundVolume(m_mainvolume);
m_sfxvolume = 0.5f;
}
Audio::~Audio() {
@ -99,3 +102,19 @@ void Audio::SetMusicVolume(float volume) {
m_music->setVolume(volume);
m_menumusic->setVolume(volume);
}
float Audio::GetMainVolume() const {
return m_engine->getSoundVolume();
}
void Audio::SetMainVolume(float volume) {
m_engine->setSoundVolume(volume);
}
float Audio::GetSfxVolume() const {
return m_sfxvolume;
}
void Audio::SetSfxVolume(float volume) {
m_sfxvolume = volume;
}

View File

@ -16,6 +16,8 @@ class Audio {
private:
irrklang::ISound* m_music;
irrklang::ISound* m_menumusic;
float m_mainvolume;
float m_sfxvolume;
bool m_music_on = true;
public:
@ -26,6 +28,7 @@ public:
void Update3DAudio(Vector3f pos, Vector3f dir, Vector3f speed);
irrklang::ISound* Create3DAudioObj(irrklang::ISound* sound, const char* name, Vector3f pos, Vector3f vel, bool is_looped, float volume);
void Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& vel, float volume);
@ -41,8 +44,14 @@ public:
void PauseEngine();
float GetMainVolume() const;
void SetMainVolume(float volume);
float GetMusicVolume() const;
void SetMusicVolume(float volume);
float GetSfxVolume() const;
void SetSfxVolume(float volume);
};
#endif // AUDIO_H__

View File

@ -45,7 +45,6 @@ void Engine::Init() {
gluPerspective(45.0f, (float)Width() / (float)Height(), 0.1f, VIEW_DISTANCE);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glDisable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -241,17 +240,21 @@ void Engine::LoadResource() {
}
// Settings
m_mainvolume = m_audio.GetMainVolume();
m_options.SetMainVolume(m_mainvolume);
m_musicvolume = m_audio.GetMusicVolume();
m_options.SetMusicVolume(m_musicvolume);
m_sfxvolume = m_audio.GetSfxVolume();
m_options.SetSfxVolume(m_sfxvolume);
m_sensitivity = m_player.GetSensitivity();
m_options.SetMouseSensitivity(m_sensitivity);
}
void Engine::UnloadResource() {}
void Engine::InstantDamage() {
m_player.InflictDamage(0.10f);
m_damage = false;
@ -1333,11 +1336,11 @@ void Engine::Render(float elapsedTime) {
if (leftright)
vstep = Vector3f(m_player.GetPosition().x + m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z + m_player.GetDirection().x);
else vstep = Vector3f(m_player.GetPosition().x - m_player.GetDirection().z, m_player.GetPosition().y - 1.7f, m_player.GetPosition().z - m_player.GetDirection().x);
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false, .8f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, m_player.GetVelocity(), false, m_sfxvolume);
leftright = !leftright;
break;
case Player::Sound::FALL:
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false, 1.f);
m_audio.Create3DAudioObj(step, AUDIO_PATH "hit.wav", m_player.GetPosition(), m_player.GetVelocity(), false, m_sfxvolume);
break;
default: break;
}
@ -1366,7 +1369,7 @@ void Engine::Render(float elapsedTime) {
m_bullets[0] = new Bullet(m_player.GetPOV() + m_player.GetDirection(), m_player.GetDirection());
}
bulletTime = BULLET_TIME;
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, .5f);
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", m_player.GetPOV(), m_player.GetDirection() * 10, false, m_sfxvolume);
if (m_flash) { // Coupe le rendering et affiche un frame blanc, pour simuler un flash.
glClearColor(.8f, .8f, .8f, 1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
@ -1420,7 +1423,7 @@ void Engine::Render(float elapsedTime) {
}
static bool died = false;
if ((m_player.GetPosition().y < -1.7f || m_player.AmIDead()) && !died) {
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f);
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, m_sfxvolume);
died = true;
}
if (m_player.GetPosition().y < -21.f || died) {
@ -1541,7 +1544,7 @@ void Engine::Render(float elapsedTime) {
RemotePlayer* rt = static_cast<RemotePlayer*>(m_players[out.id]);
rt->Feed(out);
if (rt->AmIDead()) {
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, 1.f);
m_audio.Create3DAudioObj(m_scream, AUDIO_PATH "scream.wav", m_player.GetPOV(), m_player.GetVelocity(), false, m_sfxvolume);
}
}
break;
@ -1571,7 +1574,7 @@ void Engine::Render(float elapsedTime) {
m_bullets[0] = bult;
break;
}
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir, false, 1.f);
m_audio.Create3DAudioObj(m_powpow, AUDIO_PATH "pow.wav", bull.pos, bull.dir, false, m_sfxvolume);
}
else SystemNotification("Bullet is kraput.");
break;
@ -2146,6 +2149,7 @@ void Engine::MouseMoveEvent(int x, int y) {
if (m_selectedOption == 0 && m_selectedOptAudioMainBar) {
m_mainvolume = normalizedPosition;
m_audio.SetMainVolume(m_mainvolume);
}
else if (m_selectedOption == 0 && m_selectedOptAudioMusicBar) {
m_musicvolume = normalizedPosition;
@ -2153,6 +2157,7 @@ void Engine::MouseMoveEvent(int x, int y) {
}
else if (m_selectedOption == 0 && m_selectedOptAudioSfxBar) {
m_sfxvolume = normalizedPosition;
m_audio.SetSfxVolume(m_sfxvolume);
}
else if (m_selectedOption == 2 && m_selectedGameplaySensitivityBar) {
m_sensitivity = normalizedPosition;
@ -2286,8 +2291,9 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_mainvolume = normalizedPosition;
m_selectedOptAudioMainBar = true;
m_mainvolume = normalizedPosition;
m_audio.SetMainVolume(m_mainvolume);
}
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarMusique && y < topBarMusique) {
m_audio.playSound(AUDIO_PATH "snap.wav");
@ -2297,8 +2303,9 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
}
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarEffets && y < topBarEffets) {
m_audio.playSound(AUDIO_PATH "snap.wav");
m_sfxvolume = normalizedPosition;
m_selectedOptAudioSfxBar = true;
m_sfxvolume = normalizedPosition;
m_audio.SetSfxVolume(m_sfxvolume);
}
// Resolution
@ -2340,6 +2347,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
else if (normalizedPosition > 1.0f) {
normalizedPosition = 1.0f;
}
// Gameplay
if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
m_audio.playSound(AUDIO_PATH "snap.wav");
@ -2388,21 +2396,33 @@ void Engine::MouseReleaseEvent(const MOUSE_BUTTON& button, int x, int y) {
switch (button) {
case MOUSE_BUTTON_LEFT:
if (m_selectedOptAudioMusicBar) {
if (m_selectedOption == 0) {
if (normalizedPosition < 0.0f) {
normalizedPosition = 0.0f;
}
m_musicvolume = normalizedPosition;
m_audio.SetMusicVolume(m_musicvolume);
}
if (m_selectedGameplaySensitivityBar) {
if (normalizedPosition < 0.1f) {
normalizedPosition = 0.1f;
if (m_selectedOptAudioMainBar) {
m_mainvolume = normalizedPosition;
m_audio.SetMainVolume(m_mainvolume);
}
else if (m_selectedOptAudioMusicBar) {
m_musicvolume = normalizedPosition;
m_audio.SetMusicVolume(m_musicvolume);
}
else if (m_selectedOptAudioSfxBar) {
m_sfxvolume = normalizedPosition;
m_audio.SetSfxVolume(m_sfxvolume);
}
}
else {
if (m_selectedGameplaySensitivityBar) {
if (normalizedPosition < 0.1f) {
normalizedPosition = 0.1f;
}
m_sensitivity = normalizedPosition;
m_player.SetSensitivity(m_sensitivity);
m_sensitivity = normalizedPosition;
m_player.SetSensitivity(m_sensitivity);
}
}
m_mouseL = false;
m_block = false;

View File

@ -176,9 +176,9 @@ private:
int m_nbReductionChunk = 4;
int m_timerReductionChunk = 30;
float m_mainvolume = 0.0f;
float m_mainvolume;
float m_musicvolume;
float m_sfxvolume = 0.0f;
float m_sfxvolume;
float m_sensitivity;
int m_selectedOption = 0;