[Add] In-game menu for disabling sounds.
This commit is contained in:
parent
ae5152e7e4
commit
2621a79fd1
@ -12,6 +12,10 @@
|
|||||||
#include "../System/Debug.h"
|
#include "../System/Debug.h"
|
||||||
#include "../Sprite/Sprite.h"
|
#include "../Sprite/Sprite.h"
|
||||||
#include "../Texture/Texture.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 "../Level/Level.h"
|
||||||
#include "Game.h"
|
#include "Game.h"
|
||||||
@ -29,6 +33,8 @@ Game::Game(void) {
|
|||||||
_titleScreen = new TitleScreen();
|
_titleScreen = new TitleScreen();
|
||||||
_inTitleScreen = true;
|
_inTitleScreen = true;
|
||||||
|
|
||||||
|
_inGameMenuShown = false;
|
||||||
|
|
||||||
_running = true;
|
_running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +74,7 @@ void Game::Shutdown(void) {
|
|||||||
delete _NPC;
|
delete _NPC;
|
||||||
delete _player;
|
delete _player;
|
||||||
delete _level;
|
delete _level;
|
||||||
delete _titleScreen;
|
delete _inGameMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::ProcessEvents(float dt) {
|
void Game::ProcessEvents(float dt) {
|
||||||
@ -114,10 +120,30 @@ void Game::UpdateTitle(float dt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Game::UpdateGame(float dt) {
|
void Game::UpdateGame(float 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);
|
_player->Update(dt);
|
||||||
_NPC->Update(dt);
|
_NPC->Update(dt);
|
||||||
_level->Update(dt);
|
_level->Update(dt);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Game::RenderTitle(void) {
|
void Game::RenderTitle(void) {
|
||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
@ -160,6 +186,15 @@ void Game::RenderGame(void) {
|
|||||||
_player->GetX() - 5,
|
_player->GetX() - 5,
|
||||||
_player->GetY() - _testFont->GetLineSkip() - 2,
|
_player->GetY() - _testFont->GetLineSkip() - 2,
|
||||||
"Miss D");
|
"Miss D");
|
||||||
|
|
||||||
|
if(_inGameMenuShown) {
|
||||||
|
glLoadIdentity();
|
||||||
|
|
||||||
|
glDisable(GL_DEPTH_TEST);
|
||||||
|
glDisable(GL_ALPHA_TEST);
|
||||||
|
|
||||||
|
_inGameMenu->Render();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::NewGame(void) {
|
void Game::NewGame(void) {
|
||||||
@ -172,7 +207,21 @@ void Game::NewGame(void) {
|
|||||||
_testFont->Load("../Data/Font/Fairydust.ttf", 16);
|
_testFont->Load("../Data/Font/Fairydust.ttf", 16);
|
||||||
_testFont->SetColor(0.0f, 1.0f, 1.0f, 1.0f);
|
_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;
|
_inTitleScreen = false;
|
||||||
|
delete _titleScreen;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::LoadGame(void) {
|
void Game::LoadGame(void) {
|
||||||
@ -180,4 +229,5 @@ void Game::LoadGame(void) {
|
|||||||
|
|
||||||
void Game::Quit(void) {
|
void Game::Quit(void) {
|
||||||
SetRunning(false);
|
SetRunning(false);
|
||||||
|
delete _titleScreen;
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ class Sprite;
|
|||||||
class Level;
|
class Level;
|
||||||
class Button;
|
class Button;
|
||||||
class TitleScreen;
|
class TitleScreen;
|
||||||
|
class Menu;
|
||||||
|
|
||||||
class Game {
|
class Game {
|
||||||
public:
|
public:
|
||||||
@ -44,5 +45,8 @@ private:
|
|||||||
TitleScreen* _titleScreen;
|
TitleScreen* _titleScreen;
|
||||||
bool _inTitleScreen;
|
bool _inTitleScreen;
|
||||||
|
|
||||||
|
Menu* _inGameMenu;
|
||||||
|
bool _inGameMenuShown;
|
||||||
|
|
||||||
bool _running;
|
bool _running;
|
||||||
};
|
};
|
||||||
|
@ -102,7 +102,7 @@ int main(int argc, char** argv) {
|
|||||||
while(game.IsRunning()) {
|
while(game.IsRunning()) {
|
||||||
|
|
||||||
while(SDL_PollEvent(&event)) {
|
while(SDL_PollEvent(&event)) {
|
||||||
if((event.type == SDL_QUIT) || KeyStillDown(SDLK_ESCAPE)) {
|
if((event.type == SDL_QUIT)) {
|
||||||
game.SetRunning(false);
|
game.SetRunning(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -28,3 +28,7 @@ void Music::Play(Music* music, int loops) {
|
|||||||
void Music::Stop() {
|
void Music::Stop() {
|
||||||
Mix_HaltMusic();
|
Mix_HaltMusic();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Music::SetVolume(int volume) {
|
||||||
|
Mix_VolumeMusic(volume);
|
||||||
|
}
|
||||||
|
@ -15,6 +15,7 @@ public:
|
|||||||
|
|
||||||
static void Play(Music* music, int loops);
|
static void Play(Music* music, int loops);
|
||||||
static void Stop();
|
static void Stop();
|
||||||
|
static void SetVolume(int volume);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct _Mix_Music* _music;
|
struct _Mix_Music* _music;
|
||||||
|
@ -31,3 +31,7 @@ void SoundEffect::Stop(int channel) {
|
|||||||
bool SoundEffect::IsPlaying(int channel) {
|
bool SoundEffect::IsPlaying(int channel) {
|
||||||
return Mix_Playing(channel) == 1;
|
return Mix_Playing(channel) == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SoundEffect::SetVolume(int channel, int volume) {
|
||||||
|
Mix_Volume(channel, volume);
|
||||||
|
}
|
||||||
|
@ -16,6 +16,7 @@ public:
|
|||||||
static void Play(SoundEffect* effect, int channel, int loops);
|
static void Play(SoundEffect* effect, int channel, int loops);
|
||||||
static void Stop(int channel);
|
static void Stop(int channel);
|
||||||
static bool IsPlaying(int channel);
|
static bool IsPlaying(int channel);
|
||||||
|
static void SetVolume(int channel, int volume);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mix_Chunk* _chunk;
|
Mix_Chunk* _chunk;
|
||||||
|
Loading…
Reference in New Issue
Block a user