Skip to content

Commit

Permalink
Update jump sound
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccabas committed Aug 10, 2023
1 parent bc16fba commit d339427
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Mario.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ Mario::Mario()
Height = 64;
Velocity = 0.7;
sprite.setOrigin(Width / 2.f, Height / 2.f);



jumpBuffer.loadFromFile(JUMP_SOUND);
jumpSound.setBuffer(jumpBuffer);
}


Expand All @@ -42,8 +47,10 @@ void Mario::update(int mapWidth)
else
velocity.x = 0;

if (Keyboard::isKeyPressed(Keyboard::Key::Up) && canJump)
if (Keyboard::isKeyPressed(Keyboard::Key::Up) && canJump) {
keyRel = true;
jumpSound.play();
}


if (keyRel && this->top() > 0 && canJump)
Expand Down
5 changes: 5 additions & 0 deletions Mario.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#define WINDOW_WIDTH 1024
#define WINDOW_HEIGHT 512

#define JUMP_SOUND "assets/JUMP.wav"

using namespace sf;

class Mario : public Entity
Expand All @@ -30,6 +32,9 @@ class Mario : public Entity
float flCurrentTime = 0;
float dt;

SoundBuffer jumpBuffer;
Sound jumpSound;

bool keyRel = false;

public:
Expand Down
2 changes: 2 additions & 0 deletions Mario.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
<ClInclude Include="Spikey.h" />
<ClInclude Include="tileMap.h" />
<ClInclude Include="Turtle.h" />
<ClInclude Include="Sound.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="Bonus.cpp" />
Expand All @@ -159,6 +160,7 @@
<ClCompile Include="Spikey.cpp" />
<ClCompile Include="tileMap.cpp" />
<ClCompile Include="Turtle.cpp" />
<ClCompile Include="Sound.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
6 changes: 6 additions & 0 deletions Mario.vcxproj.filters.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<ItemGroup>
<ClInclude Include="tileMap.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Sound.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Mario.h">
<Filter>Header Files</Filter>
Expand Down Expand Up @@ -65,6 +68,9 @@
<ClCompile Include="tileMap.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Sound.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Mario.cpp">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down

0 comments on commit d339427

Please sign in to comment.