diff --git a/src/Main/Game.cpp b/src/Main/Game.cpp index c967953..cc52393 100644 --- a/src/Main/Game.cpp +++ b/src/Main/Game.cpp @@ -12,6 +12,10 @@ #include "../System/Debug.h" #include "../Sprite/Sprite.h" #include "../Texture/Texture.h" +#include "../UI/Button.h" +#include "../UI/Menu.h" +#include "../Sound/Music.h" +#include "../Sound/SoundEffect.h" #include "../Level/Level.h" #include "Game.h" @@ -28,6 +32,8 @@ Game::Game(void) { _titleScreen = new TitleScreen(); _inTitleScreen = true; + + _inGameMenuShown = false; _running = true; } @@ -68,7 +74,7 @@ void Game::Shutdown(void) { delete _NPC; delete _player; delete _level; - delete _titleScreen; + delete _inGameMenu; } void Game::ProcessEvents(float dt) { @@ -114,9 +120,29 @@ void Game::UpdateTitle(float dt) { } void Game::UpdateGame(float dt) { - _player->Update(dt); - _NPC->Update(dt); - _level->Update(dt); + if(KeyDown(SDLK_ESCAPE)) { + _inGameMenuShown = !_inGameMenuShown; + } + if(_inGameMenuShown) { + _inGameMenu->SetXY(windowWidth / 2, windowHeight / 2); + _inGameMenu->Update(); + + switch(_inGameMenu->GetTriggeredButton()) { + case 0: + SoundEffect::SetVolume(-1, 0); + Music::SetVolume(0); + break; + + case 1: + SoundEffect::SetVolume(-1, 100); + Music::SetVolume(100); + break; + } + } else { + _player->Update(dt); + _NPC->Update(dt); + _level->Update(dt); + } } void Game::RenderTitle(void) { @@ -160,6 +186,15 @@ void Game::RenderGame(void) { _player->GetX() - 5, _player->GetY() - _testFont->GetLineSkip() - 2, "Miss D"); + + if(_inGameMenuShown) { + glLoadIdentity(); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_ALPHA_TEST); + + _inGameMenu->Render(); + } } void Game::NewGame(void) { @@ -172,7 +207,21 @@ void Game::NewGame(void) { _testFont->Load("../Data/Font/Fairydust.ttf", 16); _testFont->SetColor(0.0f, 1.0f, 1.0f, 1.0f); + Button* muteSoundsButton = new Button(); + muteSoundsButton->SetFont(_testFont); + muteSoundsButton->SetText("Mute Sounds"); + + Button* unmuteSoundsButton = new Button(); + unmuteSoundsButton->SetFont(_testFont); + unmuteSoundsButton->SetText("Unmute Sounds"); + + _inGameMenu = new Menu(); + _inGameMenu->AddButton(muteSoundsButton); + _inGameMenu->AddButton(unmuteSoundsButton); + _inGameMenu->AlignButtons(Menu::ALIGN_VERTICALLY); + _inTitleScreen = false; + delete _titleScreen; } void Game::LoadGame(void) { @@ -180,4 +229,5 @@ void Game::LoadGame(void) { void Game::Quit(void) { SetRunning(false); + delete _titleScreen; } diff --git a/src/Main/Game.h b/src/Main/Game.h index ca4f984..7f99d05 100644 --- a/src/Main/Game.h +++ b/src/Main/Game.h @@ -8,6 +8,7 @@ class Sprite; class Level; class Button; class TitleScreen; +class Menu; class Game { public: @@ -44,5 +45,8 @@ private: TitleScreen* _titleScreen; bool _inTitleScreen; + Menu* _inGameMenu; + bool _inGameMenuShown; + bool _running; }; diff --git a/src/Main/main.cpp b/src/Main/main.cpp index 3a01324..32e85fc 100644 --- a/src/Main/main.cpp +++ b/src/Main/main.cpp @@ -102,7 +102,7 @@ int main(int argc, char** argv) { while(game.IsRunning()) { while(SDL_PollEvent(&event)) { - if((event.type == SDL_QUIT) || KeyStillDown(SDLK_ESCAPE)) { + if((event.type == SDL_QUIT)) { game.SetRunning(false); break; } diff --git a/src/Sound/Music.cpp b/src/Sound/Music.cpp index f62d0af..9dd2799 100644 --- a/src/Sound/Music.cpp +++ b/src/Sound/Music.cpp @@ -28,3 +28,7 @@ void Music::Play(Music* music, int loops) { void Music::Stop() { Mix_HaltMusic(); } + +void Music::SetVolume(int volume) { + Mix_VolumeMusic(volume); +} diff --git a/src/Sound/Music.h b/src/Sound/Music.h index 71f98d2..5df09e5 100644 --- a/src/Sound/Music.h +++ b/src/Sound/Music.h @@ -15,6 +15,7 @@ public: static void Play(Music* music, int loops); static void Stop(); + static void SetVolume(int volume); private: struct _Mix_Music* _music; diff --git a/src/Sound/SoundEffect.cpp b/src/Sound/SoundEffect.cpp index 32d443c..e72897b 100644 --- a/src/Sound/SoundEffect.cpp +++ b/src/Sound/SoundEffect.cpp @@ -30,4 +30,8 @@ void SoundEffect::Stop(int channel) { bool SoundEffect::IsPlaying(int channel) { return Mix_Playing(channel) == 1; -} \ No newline at end of file +} + +void SoundEffect::SetVolume(int channel, int volume) { + Mix_Volume(channel, volume); +} diff --git a/src/Sound/SoundEffect.h b/src/Sound/SoundEffect.h index b979940..c77b8ef 100644 --- a/src/Sound/SoundEffect.h +++ b/src/Sound/SoundEffect.h @@ -16,6 +16,7 @@ public: static void Play(SoundEffect* effect, int channel, int loops); static void Stop(int channel); static bool IsPlaying(int channel); + static void SetVolume(int channel, int volume); private: Mix_Chunk* _chunk;