Skip to content

Commit cfd2e71

Browse files
committed
Implemented Audio
1 parent ae8a1b3 commit cfd2e71

15 files changed

+100
-70
lines changed

Blockodu.vcxproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,14 @@
5858
<ConformanceMode>true</ConformanceMode>
5959
<AdditionalIncludeDirectories>$(SolutionDir)\libraries\SFML-2.5.1\include\;$(SolutionDir)\include\;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
6060
<MultiProcessorCompilation>true</MultiProcessorCompilation>
61+
<LanguageStandard>stdcpp14</LanguageStandard>
62+
<LanguageStandard_C>Default</LanguageStandard_C>
6163
</ClCompile>
6264
<Link>
6365
<SubSystem>Console</SubSystem>
6466
<GenerateDebugInformation>true</GenerateDebugInformation>
6567
<AdditionalLibraryDirectories>$(SolutionDir)\libraries\SFML-2.5.1\lib\;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
66-
<AdditionalDependencies>winmm.lib;sfml-system-s-d.lib;opengl32.lib;gdi32.lib;sfml-window-s-d.lib;freetype.lib;sfml-graphics-s-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
68+
<AdditionalDependencies>winmm.lib;sfml-system-s-d.lib;ws2_32.lib;sfml-network-s-d.lib;openal32.lib;flac.lib;vorbisenc.lib;vorbisfile.lib;vorbis.lib;ogg.lib;sfml-audio-s-d.lib;opengl32.lib;gdi32.lib;sfml-window-s-d.lib;freetype.lib;sfml-graphics-s-d.lib;%(AdditionalDependencies)</AdditionalDependencies>
6769
</Link>
6870
</ItemDefinitionGroup>
6971
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
@@ -78,6 +80,8 @@
7880
<MultiProcessorCompilation>true</MultiProcessorCompilation>
7981
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
8082
<FloatingPointModel>Fast</FloatingPointModel>
83+
<LanguageStandard>stdcpp14</LanguageStandard>
84+
<LanguageStandard_C>Default</LanguageStandard_C>
8185
</ClCompile>
8286
<Link>
8387
<SubSystem>Console</SubSystem>
@@ -89,6 +93,7 @@
8993
</Link>
9094
</ItemDefinitionGroup>
9195
<ItemGroup>
96+
<ClCompile Include="include\audio.cpp" />
9297
<ClCompile Include="src\block.cpp" />
9398
<ClCompile Include="src\game.cpp" />
9499
<ClCompile Include="src\main.cpp" />
@@ -108,6 +113,7 @@
108113
<ClInclude Include="include\impl.h" />
109114
<ClInclude Include="include\pickupBoard.h" />
110115
<ClInclude Include="include\score.h" />
116+
<ClInclude Include="include\audio.h" />
111117
<ClInclude Include="include\spacing.h" />
112118
<ClInclude Include="include\table.h" />
113119
<ClInclude Include="include\utilities.h" />

Blockodu.vcxproj.filters

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
<ClCompile Include="src\score.cpp">
3737
<Filter>Source Files</Filter>
3838
</ClCompile>
39+
<ClCompile Include="include\audio.cpp">
40+
<Filter>Source Files</Filter>
41+
</ClCompile>
3942
</ItemGroup>
4043
<ItemGroup>
4144
<None Include=".gitignore" />
@@ -69,5 +72,8 @@
6972
<ClInclude Include="include\score.h">
7073
<Filter>Header Files</Filter>
7174
</ClInclude>
75+
<ClInclude Include="include\audio.h">
76+
<Filter>Header Files</Filter>
77+
</ClInclude>
7278
</ItemGroup>
7379
</Project>

include/audio.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
2+
#include "audio.h"
3+
4+
#include <SFML/Audio/SoundBuffer.hpp>
5+
#include <SFML/Audio/Sound.hpp>
6+
7+
bool Audio::initialized = false;
8+
sf::SoundBuffer Audio::goodPlacement, Audio::badPlacement, Audio::completetion;
9+
sf::Sound Audio::playingSound;
10+
11+
void Audio::initialize() {
12+
goodPlacement.loadFromFile("resources/goodPlacement.ogg");
13+
badPlacement.loadFromFile("resources/badPlacement.ogg");
14+
completetion.loadFromFile("resources/completetion.ogg");
15+
16+
initialized = true;
17+
}
18+
19+
void Audio::play(effect theEffect) {
20+
if (!initialized)
21+
return;
22+
23+
switch (theEffect) {
24+
case effect::BadPlacement:
25+
playingSound.setBuffer(badPlacement);
26+
break;
27+
case effect::GoodPlacement:
28+
playingSound.setBuffer(goodPlacement);
29+
break;
30+
case effect::Completetion:
31+
playingSound.setBuffer(completetion);
32+
break;
33+
}
34+
35+
playingSound.play();
36+
}

include/audio.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#pragma once
2+
3+
#include <SFML/Audio/SoundBuffer.hpp>
4+
#include <SFML/Audio/Sound.hpp>
5+
6+
class Audio
7+
{
8+
private:
9+
static bool initialized;
10+
static sf::SoundBuffer goodPlacement, badPlacement, completetion;
11+
static sf::Sound playingSound;
12+
13+
public:
14+
enum class effect { GoodPlacement, BadPlacement, Completetion };
15+
16+
static void initialize();
17+
18+
static void play(effect theEffect);
19+
};

include/block.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#pragma once
22

3-
#include <vector>
4-
53
#include "impl.h"
64

5+
#include <vector>
6+
77
class Block : Drawable
88
{
99
private:

include/game.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
#include <SFML/Window/Event.hpp>
3-
#include <SFML/Graphics/RenderWindow.hpp>
4-
52
#include "table.h"
63
#include "pickupBoard.h"
74
#include "score.h"
85

6+
#include <SFML/Window/Event.hpp>
7+
#include <SFML/Graphics/RenderWindow.hpp>
8+
99
class Game
1010
{
1111
private:
@@ -18,5 +18,7 @@ class Game
1818
void pollEvent(sf::RenderWindow& window, sf::Event& theEvent);
1919

2020
public:
21+
Game();
22+
2123
void start();
2224
};

include/table.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Table : Drawable
1818

1919
sf::Vector2i mousePositionToCellPosition(const sf::Vector2f& mousePosition);
2020

21-
void verifyCompletetion();
21+
bool checkCompletetion();
2222

2323
public:
2424
Table(Score& theScore);

resources/badPlacement.ogg

5.38 KB
Binary file not shown.

resources/completetion.ogg

12.7 KB
Binary file not shown.

resources/goodPlacement.ogg

5.15 KB
Binary file not shown.

src/block.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

22
#include "block.h"
3-
4-
#include <SFML/Graphics/RectangleShape.hpp>
5-
63
#include "spacing.h"
74
#include "colors.h"
85
#include "utilities.h"
96

7+
#include <SFML/Graphics/RectangleShape.hpp>
8+
109
const sf::Vector2u Block::getStructureSize() {
1110
return this->structureSize;
1211
}

src/game.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11

22
#include "game.h"
3-
43
#include "spacing.h"
4+
#include "audio.h"
55

66
#include <SFML/Graphics/RenderWindow.hpp>
77

8+
Game::Game() {
9+
Audio::initialize();
10+
}
11+
812
void Game::draw(sf::RenderWindow& window) {
913
theScore.draw(window);
1014

src/pickupBoard.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
#include "pickupBoard.h"
3-
43
#include "colors.h"
4+
#include "audio.h"
55

66
#include <SFML/Graphics/VertexArray.hpp>
77
#include <SFML/Window/Event.hpp>
@@ -128,6 +128,8 @@ void PickupBoard::pollEvent(sf::RenderWindow& window, sf::Event& theEvent)
128128

129129
pickedUpPreviewCoords = { -1, -1 };
130130
}
131+
else
132+
Audio::play(Audio::effect::BadPlacement);
131133

132134
pickedUpIndex = -1;
133135
}

src/score.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
#include "score.h"
3-
43
#include "spacing.h"
54
#include "colors.h"
65
#include "utilities.h"

src/table.cpp

Lines changed: 14 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11

22
#include "table.h"
3+
#include "colors.h"
4+
#include "spacing.h"
5+
#include "audio.h"
36

47
#include <SFML/Graphics/RectangleShape.hpp>
58
#include <SFML/Graphics/Rect.hpp>
69

7-
#include "colors.h"
8-
#include "spacing.h"
9-
1010
Table::Table(Score& theScore) : theScore(theScore)
1111
{
1212

@@ -28,7 +28,7 @@ sf::Vector2i Table::mousePositionToCellPosition(const sf::Vector2f& mousePositio
2828
return { -1, -1 };
2929
}
3030

31-
void Table::verifyCompletetion() {
31+
bool Table::checkCompletetion() {
3232
std::vector<sf::Vector2u> completedBoxes;
3333
std::vector<unsigned> completedHorizontalLines;
3434
std::vector<unsigned> completedVerticalLines;
@@ -102,6 +102,14 @@ void Table::verifyCompletetion() {
102102

103103
theScore.addCompletionLine();
104104
}
105+
106+
if (!completedBoxes.empty() || !completedVerticalLines.empty() || !completedHorizontalLines.empty())
107+
{
108+
Audio::play(Audio::effect::Completetion);
109+
return true;
110+
}
111+
112+
return false;
105113
}
106114

107115
void Table::applyBlock(Block& theBlock, const sf::Vector2i& tableCellCoords)
@@ -117,7 +125,8 @@ void Table::applyBlock(Block& theBlock, const sf::Vector2i& tableCellCoords)
117125
}
118126
}
119127

120-
verifyCompletetion();
128+
if (!checkCompletetion())
129+
Audio::play(Audio::effect::GoodPlacement);
121130
}
122131

123132
sf::Vector2i Table::previewBlock(Block& theHoldingBlock, const sf::Vector2f& mousePosition)
@@ -265,55 +274,3 @@ void Table::draw(sf::RenderWindow& window)
265274

266275
//DRAW GRID END
267276
}
268-
269-
/*
270-
//blocks
271-
for (unsigned i = 0; i < 3; i++) {
272-
for (unsigned j = 0; j < 3; j++) {
273-
bool isBlockFull = true;
274-
for (unsigned m = 0; m < 3; m++) {
275-
for (unsigned n = 0; n < 3; n++) {
276-
if (cellTable[i * 3 + m][j * 3 + n] == cell::empty)
277-
isBlockFull = false;
278-
}
279-
}
280-
281-
if (isBlockFull) {
282-
for (unsigned m = 0; m < 3; m++) {
283-
for (unsigned n = 0; n < 3; n++)
284-
cellTable[i * 3 + m][j * 3 + n] = cell::empty;
285-
}
286-
287-
theScore.addCompletionSquare();
288-
}
289-
}
290-
}
291-
292-
//lines
293-
for (unsigned i = 0; i < 9; i++) {
294-
for (unsigned j = 0; j < 9; j++) {
295-
bool isVerticalLineFull = true, isHorizontalLineFull = true;
296-
for (unsigned m = 0; m < 9; m++) {
297-
if (cellTable[i][m] == cell::empty)
298-
isHorizontalLineFull = false;
299-
300-
if (cellTable[m][j] == cell::empty)
301-
isVerticalLineFull = false;
302-
}
303-
304-
if (isVerticalLineFull) {
305-
for (unsigned m = 0; m < 9; m++)
306-
cellTable[m][j] = cell::empty;
307-
308-
theScore.addCompletionLine();
309-
}
310-
311-
if (isHorizontalLineFull) {
312-
for (unsigned m = 0; m < 9; m++)
313-
cellTable[i][m] = cell::empty;
314-
315-
theScore.addCompletionLine();
316-
}
317-
}
318-
}
319-
*/

0 commit comments

Comments
 (0)