Merge branch 'SQC_MenuMusic'
This commit is contained in:
commit
ae247a58a8
@ -8,20 +8,28 @@ Audio::Audio() {
|
||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||
}
|
||||
|
||||
Audio::Audio(const char * music) {
|
||||
Audio::Audio(const char * music, const char* menumusic) {
|
||||
m_engine = irrklang::createIrrKlangDevice();
|
||||
m_engine->setDopplerEffectParameters(1);
|
||||
m_engine->setRolloffFactor(2);
|
||||
m_engine->setDefault3DSoundMinDistance(.1);
|
||||
m_engine->setDefault3DSoundMaxDistance(1000);
|
||||
m_music = m_engine->play2D(music, true, true, true, irrklang::ESM_STREAMING);
|
||||
m_menumusic = m_engine->play2D(menumusic, true, true, true, irrklang::ESM_STREAMING);
|
||||
m_music->setVolume(.5);
|
||||
m_menumusic->setVolume(.5);
|
||||
}
|
||||
|
||||
Audio::~Audio() {
|
||||
if (m_music) m_music->drop();
|
||||
if (m_menumusic) m_menumusic->drop();
|
||||
if (m_engine) m_engine->drop();
|
||||
}
|
||||
|
||||
void Audio::playSound(const char* sound) {
|
||||
m_engine->play2D(sound);
|
||||
}
|
||||
|
||||
void Audio::Update3DAudio(Vector3f pos, Vector3f dir, Vector3f vel) {
|
||||
m_engine->setListenerPosition(irrklang::vec3df(pos.x, pos.y, pos.z),
|
||||
irrklang::vec3df(dir.x, dir.y, dir.z),
|
||||
@ -45,7 +53,41 @@ void Audio::Render3DAudioObj(irrklang::ISound* sound, Vector3f& pos, Vector3f& v
|
||||
// m_music = m_engine->play2D(music, false, false, false, irrklang::ESM_STREAMING);
|
||||
//}
|
||||
|
||||
void Audio::ToggleMusicState() { m_music->setIsPaused(!m_music->getIsPaused()); }
|
||||
void Audio::ToggleMusicState(GameState state) {
|
||||
if (m_music_on) {
|
||||
switch (state) {
|
||||
case PLAY:
|
||||
m_music->setIsPaused(false);
|
||||
m_menumusic->setIsPaused(true);
|
||||
break;
|
||||
case PAUSE:
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(true);
|
||||
break;
|
||||
default:
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(true);
|
||||
}
|
||||
}
|
||||
|
||||
void Audio::SetMusic(bool ison, GameState state) {
|
||||
m_music_on = state;
|
||||
if (!state) {
|
||||
m_music->setIsPaused(true);
|
||||
m_menumusic->setIsPaused(true);
|
||||
}
|
||||
else ToggleMusicState(state);
|
||||
}
|
||||
|
||||
bool Audio::GetMusic() {
|
||||
return m_music_on;
|
||||
}
|
||||
|
||||
void Audio::PauseEngine() { m_engine->setAllSoundsPaused(); }
|
||||
|
||||
|
@ -15,10 +15,12 @@
|
||||
class Audio {
|
||||
private:
|
||||
irrklang::ISound* m_music;
|
||||
irrklang::ISound* m_menumusic;
|
||||
bool m_music_on = true;
|
||||
|
||||
public:
|
||||
Audio();
|
||||
Audio(const char* music);
|
||||
Audio(const char* music, const char* menumusic);
|
||||
~Audio();
|
||||
irrklang::ISoundEngine* m_engine;
|
||||
|
||||
@ -30,7 +32,12 @@ public:
|
||||
|
||||
//void PlaySong(const char* music);
|
||||
|
||||
void ToggleMusicState();
|
||||
void ToggleMusicState(GameState state);
|
||||
|
||||
void playSound(const char* sound);
|
||||
|
||||
void SetMusic(bool ison, GameState state);
|
||||
bool GetMusic();
|
||||
|
||||
void PauseEngine();
|
||||
|
||||
|
@ -32,22 +32,27 @@ void Engine::Init() {
|
||||
glDisable(GL_FRAMEBUFFER_SRGB);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glEnable(GL_STENCIL_TEST);
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_BLEND);
|
||||
glEnable(GL_CULL_FACE);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
glEnable(GL_MULTISAMPLE_ARB);
|
||||
glEnable(GL_POINT_SMOOTH);
|
||||
glEnable(GL_LINE_SMOOTH);
|
||||
glEnable(GL_POLYGON_SMOOTH);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
|
||||
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);
|
||||
glBlendEquation(GL_FUNC_SUBTRACT);
|
||||
|
||||
m_audio.ToggleMusicState(m_gamestate);
|
||||
|
||||
if (m_istarted)
|
||||
return;
|
||||
else m_istarted = true;
|
||||
@ -55,7 +60,6 @@ void Engine::Init() {
|
||||
// Objet de skybox avec sa propre texture et son propre shader!
|
||||
m_skybox.Init(0.2f);
|
||||
// Objet de musique!
|
||||
//m_menuaudio.ToggleMusicState();
|
||||
|
||||
// Array pour les balles.
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) {
|
||||
@ -1268,8 +1272,7 @@ void Engine::Render(float elapsedTime) {
|
||||
if (StartMultiplayerGame()) {
|
||||
std::cout << "Starting multiplayer game reached" << std::endl;
|
||||
m_gamestate = GameState::PLAY;
|
||||
//m_menuaudio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState(m_gamestate);
|
||||
m_startTime = std::chrono::high_resolution_clock::now();
|
||||
}
|
||||
else {
|
||||
@ -1403,7 +1406,9 @@ void Engine::Render(float elapsedTime) {
|
||||
|
||||
m_world.Update(m_bullets, m_player.GetPosition(), m_blockinfo);
|
||||
m_renderer.UpdateMesh(&m_world, m_player.GetPosition(), m_blockinfo);
|
||||
glDisable(GL_BLEND);
|
||||
m_renderer.RenderWorld(&m_world, m_renderCount, m_player.GetPosition(), m_player.GetDirection(), all, m_shader01, m_textureAtlas);
|
||||
glEnable(GL_BLEND);
|
||||
|
||||
if (m_isSkybox) m_skybox.Render(skybox);
|
||||
|
||||
@ -1710,16 +1715,13 @@ void Engine::KeyPressEvent(unsigned char key) {
|
||||
}
|
||||
break;
|
||||
case 36: // ESC - Quitter
|
||||
if (m_networkgame)
|
||||
Stop();
|
||||
if (m_gamestate == GameState::PLAY) {
|
||||
m_gamestate = GameState::PAUSE;
|
||||
}
|
||||
else if (m_gamestate == GameState::PAUSE) {
|
||||
m_gamestate = GameState::PLAY;
|
||||
}
|
||||
//m_menuaudio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState(m_gamestate);
|
||||
break;
|
||||
case 57: // Space - Sauter
|
||||
if (!m_keySpace) {
|
||||
@ -1809,7 +1811,7 @@ void Engine::KeyReleaseEvent(unsigned char key) {
|
||||
m_keyL = false;
|
||||
break;
|
||||
case 12: // M - Toggle music
|
||||
//m_audio.ToggleMusicState();
|
||||
m_audio.SetMusic(!m_audio.GetMusic(), m_gamestate);
|
||||
break;
|
||||
case 15:
|
||||
for (int x = 0; x < MAX_BULLETS; ++x) // Ajouter une balle dans l'array (aussi connu sous le nom de "faire pow pow").
|
||||
@ -2174,15 +2176,17 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
float bottomThird = centerY + Height() * 0.198f;
|
||||
|
||||
if (x > leftButton && x < rightButton && y > bottomFirst && y < topFirst) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
if (m_selectedPlayOptions) {
|
||||
m_gamestate = GameState::PLAY;
|
||||
m_audio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState(m_gamestate);
|
||||
}
|
||||
else {
|
||||
m_selectedPlayOptions = true;
|
||||
}
|
||||
}
|
||||
else if (x > leftButton && x < rightButton && y > bottomSecond && y < topSecond) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
if (m_selectedPlayOptions) {
|
||||
m_gamestate = GameState::LOBBY;
|
||||
m_settingUsername = true;
|
||||
@ -2192,6 +2196,7 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
}
|
||||
}
|
||||
else if (x > leftButton && x < rightButton && y > bottomThird && y < topThird) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
if (m_selectedPlayOptions) {
|
||||
m_selectedPlayOptions = false;
|
||||
}
|
||||
@ -2222,15 +2227,19 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
float bottomBack = centerY + Height() * 0.2f;
|
||||
|
||||
if (x > leftAudio && x < rightAudio && y > bottomAudio && y < topAudio) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_selectedOption = 0; // Volume
|
||||
}
|
||||
else if (x > leftGraph && x < rightGraph && y > bottomGraph && y < topGraph) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_selectedOption = 1; // Graphics
|
||||
}
|
||||
else if (x > leftGameplay && x < rightGameplay && y > bottomGameplay && y < topGameplay) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_selectedOption = 2; // Gameplay
|
||||
}
|
||||
else if (x > leftBack && x < rightBack && y > bottomBack && y < topBack) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_gamestate = GameState::MAIN_MENU;
|
||||
}
|
||||
|
||||
@ -2248,14 +2257,17 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
float bottomBarEffets = centerY + Height() * 0.05f;
|
||||
|
||||
if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_volPrincipal = x - leftBar;
|
||||
m_selectedOptAudioMainBar = true;
|
||||
}
|
||||
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarMusique && y < topBarMusique) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_volMusique = x - leftBar;
|
||||
m_selectedOptAudioMusicBar = true;
|
||||
}
|
||||
else if (m_selectedOption == 0 && x > leftBar && x < rightBar && y > bottomBarEffets && y < topBarEffets) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_volEffets = x - leftBar;
|
||||
m_selectedOptAudioSfxBar = true;
|
||||
}
|
||||
@ -2277,20 +2289,25 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
float bottomChkUHD = centerY;
|
||||
|
||||
if (m_selectedOption == 1 && leftChk && x < rightChk && y > bottomChkHD && y < topChkHD) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_resolution = HD;
|
||||
}
|
||||
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkFHD && y < topChkFHD) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_resolution = FHD;
|
||||
}
|
||||
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkQHD && y < topChkQHD) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_resolution = QHD;
|
||||
}
|
||||
else if (m_selectedOption == 1 && x > leftChk && x < rightChk && y > bottomChkUHD && y < topChkUHD) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_resolution = UHD;
|
||||
}
|
||||
|
||||
// Gameplay
|
||||
if (m_selectedOption == 2 && x > leftBar && x < rightBar && y > bottomBarPrincipal && y < topBarPrincipal) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_volSensible = x - leftBar;
|
||||
m_selectedGameplaySensitivityBar = true;
|
||||
}
|
||||
@ -2307,12 +2324,15 @@ void Engine::MousePressEvent(const MOUSE_BUTTON& button, int x, int y) {
|
||||
float bottomMainMenu = centerY - Height() * 0.4415f;
|
||||
|
||||
if (x > leftResume && x < rightResume && y > bottomResume && y < topResume) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_gamestate = GameState::PLAY;
|
||||
m_audio.ToggleMusicState();
|
||||
m_audio.ToggleMusicState(m_gamestate);
|
||||
}
|
||||
else if (x > leftMainMenu && x < rightMainMenu && y > bottomMainMenu && y < topMainMenu) {
|
||||
m_audio.playSound(AUDIO_PATH "snap.wav");
|
||||
m_gamestate = GameState::MAIN_MENU;
|
||||
m_selectedPlayOptions = false;
|
||||
m_audio.ToggleMusicState(m_gamestate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,7 @@ private:
|
||||
char SimulateKeyboard(unsigned char key);
|
||||
void HandlePlayerInput(float elapsedTime);
|
||||
|
||||
//udio m_menuaudio = Audio(AUDIO_PATH "menumusic.wav");
|
||||
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
|
||||
Audio m_audio = Audio(AUDIO_PATH "music01.wav", AUDIO_PATH "menumusic01.mp3");
|
||||
irrklang::ISound* m_powpow, * m_scream;
|
||||
irrklang::ISound* m_whoosh[MAX_BULLETS];
|
||||
|
||||
|
BIN
SQCSim2021/media/audio/menumusic01.mp3
Normal file
BIN
SQCSim2021/media/audio/menumusic01.mp3
Normal file
Binary file not shown.
BIN
SQCSim2021/media/audio/snap.wav
Normal file
BIN
SQCSim2021/media/audio/snap.wav
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user