diff --git a/Bin/VC10/VC10.vcxproj b/Bin/VC10/VC10.vcxproj
index 6a11668..185b127 100644
--- a/Bin/VC10/VC10.vcxproj
+++ b/Bin/VC10/VC10.vcxproj
@@ -83,6 +83,7 @@
+
@@ -101,6 +102,7 @@
+
@@ -122,6 +124,7 @@
+
@@ -136,6 +139,7 @@
+
diff --git a/Bin/VC10/VC10.vcxproj.filters b/Bin/VC10/VC10.vcxproj.filters
index 1ec6377..2d8e9f1 100644
--- a/Bin/VC10/VC10.vcxproj.filters
+++ b/Bin/VC10/VC10.vcxproj.filters
@@ -153,6 +153,12 @@
Sound
+
+ Sound
+
+
+ Actor
+
@@ -242,5 +248,11 @@
Sound
+
+ Sound
+
+
+ Actor
+
\ No newline at end of file
diff --git a/Data/SFX/step_cloth1.wav b/Data/SFX/step_cloth1.wav
new file mode 100644
index 0000000..19ef6b4
Binary files /dev/null and b/Data/SFX/step_cloth1.wav differ
diff --git a/Data/SFX/step_cloth2.wav b/Data/SFX/step_cloth2.wav
new file mode 100644
index 0000000..f025623
Binary files /dev/null and b/Data/SFX/step_cloth2.wav differ
diff --git a/Data/SFX/step_cloth3.wav b/Data/SFX/step_cloth3.wav
new file mode 100644
index 0000000..2687fa9
Binary files /dev/null and b/Data/SFX/step_cloth3.wav differ
diff --git a/Data/SFX/step_cloth4.wav b/Data/SFX/step_cloth4.wav
new file mode 100644
index 0000000..16df1c7
Binary files /dev/null and b/Data/SFX/step_cloth4.wav differ
diff --git a/src/Actor/Player.cpp b/src/Actor/Player.cpp
index a95cca1..9e67ab8 100644
--- a/src/Actor/Player.cpp
+++ b/src/Actor/Player.cpp
@@ -1,4 +1,7 @@
+#include
+
#include "Player.h"
+#include "../Sound/SoundEffect.h"
Player::Player(void) {
PLAYER_SPEED = 15;
@@ -17,6 +20,12 @@ Player::Player(void) {
_environmentCollisionBound = new AABB();
_environmentCollisionBound->SetMin(_collisionBound->GetMin().x, _collisionBound->GetMax().y - 50.0f);
_environmentCollisionBound->SetMax(_collisionBound->GetMax().x, _collisionBound->GetMax().y);
+
+ _stepSFX[0] = sfxManager.Load("../Data/SFX/step_cloth1.wav");
+ _stepSFX[1] = sfxManager.Load("../Data/SFX/step_cloth2.wav");
+ _stepSFX[2] = sfxManager.Load("../Data/SFX/step_cloth3.wav");
+ _stepSFX[3] = sfxManager.Load("../Data/SFX/step_cloth4.wav");
+ _lastStepSFXPlayed = -1;
}
Player::~Player(void) {
@@ -68,8 +77,8 @@ bool Player::GetInBlueCollision(void) {
}
void Player::ProcessEvents(void) {
- x = _player->GetX();
- y = _player->GetY();
+ float oldX = x = _player->GetX();
+ float oldY = y = _player->GetY();
if(KeyStillDown(SDLK_w)) {
y -= PLAYER_SPEED;
_player->SetY(y);
@@ -86,6 +95,18 @@ void Player::ProcessEvents(void) {
x += PLAYER_SPEED;
_player->SetX(x);
}
+ if(x != oldX || y != oldY) {
+ if(!SoundEffect::IsPlaying(1)) {
+ int sfxIndex;
+ do {
+ sfxIndex = rand() % 4;
+ } while(sfxIndex == _lastStepSFXPlayed);
+
+ SoundEffect::Play(_stepSFX[sfxIndex], 1, 0);
+
+ _lastStepSFXPlayed = sfxIndex;
+ }
+ }
}
int Player::GetWidth(void) { return _player->GetWidth(); }
diff --git a/src/Actor/Player.h b/src/Actor/Player.h
index 52c3847..e24088d 100644
--- a/src/Actor/Player.h
+++ b/src/Actor/Player.h
@@ -6,6 +6,7 @@
#include "../IO/Input.h"
class Sprite;
+class SoundEffect;
// We will derive from an Actor class at some point.
class Player {
@@ -66,4 +67,7 @@ private:
AABB* _collisionBound;
AABB* _environmentCollisionBound;
+
+ SoundEffect* _stepSFX[4];
+ int _lastStepSFXPlayed;
};
diff --git a/src/Sound/SoundEffect.cpp b/src/Sound/SoundEffect.cpp
new file mode 100644
index 0000000..7647ddd
--- /dev/null
+++ b/src/Sound/SoundEffect.cpp
@@ -0,0 +1,33 @@
+#include
+
+#include "SoundEffect.h"
+
+ResourceManager sfxManager;
+
+SoundEffect::SoundEffect() {
+ _chunk = NULL;
+}
+
+SoundEffect::~SoundEffect() {
+ if(_chunk) {
+ Mix_FreeChunk(_chunk);
+ _chunk = NULL;
+ }
+}
+
+bool SoundEffect::Load(const std::string& filename) {
+ _chunk = Mix_LoadWAV(filename.c_str());
+ return _chunk != NULL;
+}
+
+void SoundEffect::Play(SoundEffect* effect, int channel, int loops) {
+ Mix_PlayChannel(channel, effect->_chunk, loops);
+}
+
+void SoundEffect::Stop(int channel) {
+ Mix_HaltChannel(channel);
+}
+
+bool SoundEffect::IsPlaying(int channel) {
+ return Mix_Playing(channel);
+}
\ No newline at end of file
diff --git a/src/Sound/SoundEffect.h b/src/Sound/SoundEffect.h
new file mode 100644
index 0000000..b979940
--- /dev/null
+++ b/src/Sound/SoundEffect.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "../System/ResourceManager.h"
+
+struct Mix_Chunk;
+
+class SoundEffect : public Resource {
+ template friend class ResourceManager;
+
+public:
+ SoundEffect();
+ ~SoundEffect();
+
+ bool Load(const std::string& filename);
+
+ static void Play(SoundEffect* effect, int channel, int loops);
+ static void Stop(int channel);
+ static bool IsPlaying(int channel);
+
+private:
+ Mix_Chunk* _chunk;
+};
+
+extern ResourceManager sfxManager;