Skip to content

Commit

Permalink
Added task completion sound
Browse files Browse the repository at this point in the history
  • Loading branch information
TanishTuteja committed Apr 18, 2022
1 parent cb1abfd commit c953d48
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 9 additions & 4 deletions Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Player ::Player(LTexture &myTexture, LTexture &yuluTexture, LGame &game, int pla
mCollisionMusic = Mix_LoadWAV("resources/collision.wav");
mMovementMusic = Mix_LoadWAV("resources/collision.wav");
mGrassMusic = Mix_LoadWAV("resources/grass_sound.wav");
mTaskCompleteMusic = Mix_LoadWAV("resources/taskComplete.wav");
mBox.w = playerWidth;
mBox.h = playerHeight;
taskAnimation = NULL;
Expand Down Expand Up @@ -208,15 +209,15 @@ void Player::move()
music = music % 30;
if (music == 0)
{
Mix_PlayChannel(-1, mGrassMusic, 0);
// Mix_PlayChannel(-1, mGrassMusic, 0);
}
}
else
{
music = music % 5;
if (music == 0)
{
Mix_PlayChannel(-1, mMovementMusic, 0);
// Mix_PlayChannel(-1, mMovementMusic, 0);
}
}
}
Expand Down Expand Up @@ -308,8 +309,10 @@ int Player::render(SDL_Renderer *renderer, SDL_Rect &camera)
}
else
{
if( hasYulu())yuluTexture.render(renderer, mBox.x - camera.x, mBox.y - camera.y, &playerImages[dimension + offset]);
else mTexture.render(renderer, mBox.x - camera.x, mBox.y - camera.y, &playerImages[dimension + offset]);
if (hasYulu())
yuluTexture.render(renderer, mBox.x - camera.x, mBox.y - camera.y, &playerImages[dimension + offset]);
else
mTexture.render(renderer, mBox.x - camera.x, mBox.y - camera.y, &playerImages[dimension + offset]);
}
mframes = (mframes + 1) % (numOfAnimationImages * animationSpeed);
if (isBusy())
Expand All @@ -323,6 +326,7 @@ void Player::cleanUp()
Mix_FreeChunk(mCollisionMusic);
Mix_FreeChunk(mMovementMusic);
Mix_FreeChunk(mGrassMusic);
Mix_FreeChunk(mTaskCompleteMusic);
}

void Player::setVelocity(int vel)
Expand Down Expand Up @@ -546,6 +550,7 @@ void Player::updateStateParameters(playerStateUpdate s)
{
setPoints(getPoints() + s.pointsIfTask);
mGame.replaceTask(lastTileType);
Mix_PlayChannel(-1, mTaskCompleteMusic, 0);
}
}

Expand Down
5 changes: 3 additions & 2 deletions Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Player : public Renderable
public:
// Initializes the variables

Player(LTexture &myTexture, LTexture &yuluTexture , LGame &game, int playerHeight, int playerWidth, int right, int left, int top, int bottom);
Player(LTexture &myTexture, LTexture &yuluTexture, LGame &game, int playerHeight, int playerWidth, int right, int left, int top, int bottom);

// Takes key presses and adjusts the dot's velocity
void handleEvent(SDL_Event &e);
Expand Down Expand Up @@ -88,7 +88,7 @@ class Player : public Renderable
LGame &mGame;
SDL_Rect mBox;
LTexture &mTexture;
LTexture &yuluTexture ;
LTexture &yuluTexture;
Animation *taskAnimation;
bool hasTaskAnimation;
// bool touchesWall(std::vector<Tile> tiles);
Expand Down Expand Up @@ -118,6 +118,7 @@ class Player : public Renderable
Mix_Chunk *mCollisionMusic;
Mix_Chunk *mMovementMusic;
Mix_Chunk *mGrassMusic;
Mix_Chunk *mTaskCompleteMusic;
};

#endif

0 comments on commit c953d48

Please sign in to comment.