Skip to content

Commit

Permalink
Added sfx to picking up bonus, fixed sfx overflow method
Browse files Browse the repository at this point in the history
  • Loading branch information
t3m1X committed Jun 4, 2017
1 parent dfbddc0 commit 302e92b
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 12 deletions.
33 changes: 25 additions & 8 deletions ModuleAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,26 @@ Mix_Chunk * const ModuleAudio::LoadSFX(const char * path)
{
Mix_Chunk* ret = nullptr;

if (last_sfx == MAX_MUSIC) {
int current_sfx = 0;
for (; current_sfx < MAX_SFX; ++current_sfx)
{
if (sfxs[current_sfx] == nullptr)
break;
}
if (current_sfx == MAX_SFX) {
LOG("Overflow error: Overwriting sfx");
last_sfx = 0;
current_sfx = last_sfx;
Mix_FreeChunk(sfxs[last_sfx]);
}

sfxs[last_sfx] = Mix_LoadWAV(path);
sfxs[current_sfx] = Mix_LoadWAV(path);
last_sfx = current_sfx;

if (sfxs[last_sfx] == NULL) {
LOG("MixLoadWav: Failed to load wav from path \"%s\": %s\n", path, Mix_GetError());
}
else
ret = sfxs[last_sfx++];
ret = sfxs[last_sfx];

return ret;
}
Expand All @@ -95,18 +103,27 @@ Mix_Music * const ModuleAudio::LoadMusic(const char * path)
{
Mix_Music* ret = nullptr;

if (last_music == MAX_MUSIC) {
int current_music = 0;
for (; current_music < MAX_SFX; ++current_music)
{
if (musics[current_music] == nullptr)
break;
}

if (current_music == MAX_MUSIC) {
LOG("Overflow error: Overwriting music");
last_music = 0;
Mix_FreeMusic(musics[last_music]);
current_music = last_music;
}

musics[last_music] = Mix_LoadMUS(path);
musics[current_music] = Mix_LoadMUS(path);
last_music = current_music;

if (!musics[last_music]) {
LOG("Mix_LoadMUS: Could not load \"%s\": %s\n", path, Mix_GetError());
}
else
ret = musics[last_music++];
ret = musics[last_music];

return ret;
}
Expand Down
16 changes: 13 additions & 3 deletions ModuleParticles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ ModuleParticles::~ModuleParticles()
bool ModuleParticles::Start()
{
LOG("Loading particles");

destroy_b_air = App->audio->LoadSFX("sfx/destroy_b_air.wav");
graphics = App->textures->Load("revamp_spritesheets/particles_spritesheet.png");

autoattack.anim.SetUp(0, 0, 5, 14, 4, 4, "0,1,2,3");
Expand All @@ -39,7 +41,7 @@ bool ModuleParticles::Start()
explosion.anim.speed = 0.19f;
explosion.life = 700;
explosion.speed = { 0, 0};
explosion.fx = App->audio->LoadSFX("sfx/destroy_b_air.wav");
explosion.fx = destroy_b_air;


enemyshot.anim.SetUp(20, 0, 8, 8, 4, 4, "0,1,2,3");
Expand All @@ -59,7 +61,7 @@ bool ModuleParticles::Start()
big_explosion.anim.speed = 0.2f;
big_explosion.life = 700;
big_explosion.speed = { 0,0 };
big_explosion.fx = App->audio->LoadSFX("sfx/destroy_b_tank.wav");
big_explosion.fx = destroy_b_air;

laserattack.anim.SetUp(91, 126, 3, 30, 3, 3, "0,1,2");
laserattack.anim.loop = true;
Expand All @@ -71,7 +73,7 @@ bool ModuleParticles::Start()
light_explosion.anim.loop = false;
light_explosion.anim.speed = 0.2f;
light_explosion.life = 600;
light_explosion.fx = App->audio->LoadSFX("sfx/destroy_b_air.wav");
light_explosion.fx = destroy_b_air;

turret_crater.anim.SetUp(199, 157, 54, 48, 3, 3, "0,1,2");
turret_crater.anim.loop = true;
Expand Down Expand Up @@ -158,6 +160,14 @@ bool ModuleParticles::CleanUp()
player1_pieces.anim.CleanUp();
player2_pieces.anim.CleanUp();
missile.anim.CleanUp();

App->audio->FreeSFX(player2_explosion.fx);
App->audio->FreeSFX(player1_explosion.fx);
App->audio->FreeSFX(bombexplosion.fx);
App->audio->FreeSFX(bombshot.fx);
App->audio->FreeSFX(laserattack.fx);
App->audio->FreeSFX(autoattack.fx);
App->audio->FreeSFX(destroy_b_air);

for (uint i = 0; i < MAX_ACTIVE_PARTICLES; ++i)
{
Expand Down
2 changes: 2 additions & 0 deletions ModuleParticles.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class ModuleParticles : public Module
Particle player2_explosion;
Particle player1_pieces;
Particle player2_pieces;

Mix_Chunk* destroy_b_air;
};

#endif // __MODULEPARTICLES_H__
37 changes: 36 additions & 1 deletion ModulePlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ bool ModulePlayer::Start() {
you_lose = App->textures->Load("revamp_spritesheets/lose_screen.png");
game_over_mus = App->audio->LoadMusic("music/name_regist.ogg");

bonus_sfx = App->audio->LoadSFX("sfx/powerup.wav");
max_bonus_sfx = App->audio->LoadSFX("sfx/powerup_max.wav");

you_lose_an.SetUp(0, 0, 239, 151, 3, 5, "0,1,2,3,4");
you_lose_an.speed = 0.05f;

Expand Down Expand Up @@ -711,6 +714,24 @@ bool ModulePlayer::CleanUp() {
players[i].animations[j].CleanUp();
}

if (game_over_mus != nullptr) {
App->audio->FreeMusic(game_over_mus);
game_over_mus = nullptr;
}
if (next_round_mus != nullptr) {
App->audio->FreeMusic(next_round_mus);
next_round_mus = nullptr;
}

if (bonus_sfx != nullptr) {
App->audio->FreeSFX(bonus_sfx);
bonus_sfx = nullptr;
}
if (max_bonus_sfx != nullptr) {
App->audio->FreeSFX(max_bonus_sfx);
max_bonus_sfx = nullptr;
}

App->textures->Unload(player);
App->textures->Unload(you_lose);
App->textures->Unload(you_win);
Expand Down Expand Up @@ -795,12 +816,26 @@ void ModulePlayer::AddBonus(BONUS_TYPE type, Collider* col) {
if (players[player].amount_bonus < 3)
++players[player].amount_bonus;
}
if (players[player].amount_bonus == 3)
App->audio->PlaySFX(max_bonus_sfx);
else
App->audio->PlaySFX(bonus_sfx);
}
else if (type == BOMB_BONUS && players[player].bombs < 7)
{
players[player].bombs++;
if (players[player].bombs == 7)
App->audio->PlaySFX(max_bonus_sfx);
else
App->audio->PlaySFX(bonus_sfx);
}

else if (type == MISSILE_BONUS)
else if (type == MISSILE_BONUS) {
App->audio->PlaySFX(bonus_sfx);
players[player].missiles++;
}
else if (type == MEDAL_BONUS)
App->audio->PlaySFX(bonus_sfx);
}

void ModulePlayer::TriggerVictory()
Expand Down
3 changes: 3 additions & 0 deletions ModulePlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class ModulePlayer : public Module {
TTF_Font* font;
TTF_Font* loops;

Mix_Chunk* bonus_sfx = nullptr;
Mix_Chunk* max_bonus_sfx = nullptr;

player_struct players[2];
};

Expand Down

0 comments on commit 302e92b

Please sign in to comment.