Skip to content

Commit 498ea41

Browse files
committed
Add logo-bounce.wav, mine-click.wav and toggle-seal-click.wav sounds.
Add volume control for sounds. Note: Have to figure out how to best play the logo bounce sound effect. The logo probably needs its own class.
1 parent 788d9f1 commit 498ea41

File tree

6 files changed

+13
-4
lines changed

6 files changed

+13
-4
lines changed

resources/sounds/logo-bounce.wav

74.9 KB
Binary file not shown.

resources/sounds/mine-click.wav

9.7 KB
Binary file not shown.
20.3 KB
Binary file not shown.

src/Game.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,14 @@ void Game::UnloadData()
379379
UnloadFont(mFont);
380380
}
381381

382-
void Game::PlaySoundFromMap(const std::string& name)
382+
void Game::PlaySoundFromMap(const std::string& name, float volume)
383383
{
384384
auto iter = mSoundMap.find(name);
385385
if (iter != mSoundMap.end())
386386
{
387-
PlaySound(mSoundMap[name]);
387+
Sound sound = mSoundMap[name];
388+
SetSoundVolume(sound, volume);
389+
PlaySound(sound);
388390
}
389391
else
390392
{

src/Game.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Game
4545
int GetScreenHeight() const { return mScreenHeight; }
4646
std::unordered_map<std::string, Sound>& GetSoundMap() { return mSoundMap; }
4747

48-
void PlaySoundFromMap(const std::string& name);
48+
void PlaySoundFromMap(const std::string& name, float volume = 1.0f);
4949

5050
// void AddFont(class Font* font);
5151
// void RemoveFont(class Font* font);

src/Grid.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,25 +97,31 @@ void Grid::ToggleSeal(Cell* cell)
9797
{
9898
cell->SetCellType(SEALED);
9999
mTotalSeals--;
100+
GetGame()->PlaySoundFromMap("toggle-seal-click.wav", 0.5f);
101+
100102
return;
101103
}
102104
else if (cell->GetCellType() == MINE && mTotalSeals > 0)
103105
{
104106
cell->SetCellType(MINE_SEALED);
105107
mTotalSeals--;
108+
GetGame()->PlaySoundFromMap("toggle-seal-click.wav", 0.5f);
106109
CheckForWin();
110+
107111
return;
108112
}
109113

110114
if (cell->GetCellType() == SEALED)
111115
{
112116
cell->SetCellType(UNEXPOSE);
113117
mTotalSeals++;
118+
GetGame()->PlaySoundFromMap("toggle-seal-click.wav", 0.5f);
114119
}
115120
else if (cell->GetCellType() == MINE_SEALED)
116121
{
117122
cell->SetCellType(MINE);
118123
mTotalSeals++;
124+
GetGame()->PlaySoundFromMap("toggle-seal-click.wav", 0.5f);
119125
}
120126
}
121127

@@ -212,10 +218,11 @@ void Grid::Expose(Cell *cell)
212218
{
213219
mine->SetCellType(MINE_EXPOSE);
214220
}
221+
GetGame()->PlaySoundFromMap("mine-click.wav");
215222
}
216223
else if (cell->GetCellType() == UNEXPOSE)
217224
{
218-
GetGame()->PlaySoundFromMap("cell-click.wav");
225+
GetGame()->PlaySoundFromMap("cell-click.wav", 2.f);
219226
// Check if its a normal cell
220227
std::vector<Cell*> adjacentCells;
221228
int numOfMines = GetAdjacentCells(cell, adjacentCells);

0 commit comments

Comments
 (0)