diff options
-rw-r--r-- | src/game.c | 30 | ||||
-rw-r--r-- | src/sfx.c | 9 | ||||
-rw-r--r-- | src/sfx.h | 2 |
3 files changed, 24 insertions, 17 deletions
@@ -422,7 +422,7 @@ static void infect_entity(game_t *game, entity_t *entity, const char *name) { /* convert entity into inanimate virus (off the viruses array) */ (void) virus_node_new(&(stage_conf_t){ .stage = entity->any.node, .replace = 1, .name = name, .active = 1, .alpha = 1.f }, &game->sars->projection_x, &entity->any.model_x); - sfx_play(&sfx.baby_infected); + sfx_play(&sfx.baby_infected, 1.f); entity->any.type = ENTITY_TYPE_VIRUS; entity->virus.corpse = 1; @@ -435,7 +435,7 @@ static void infect_entity(game_t *game, entity_t *entity, const char *name) static void hat_baby(game_t *game, baby_t *baby, mask_t *mask) { (void) baby_hatted_node_new(&(stage_conf_t){ .stage = baby->entity.node, .replace = 1, .name = "baby-hatted", .active = 1, .alpha = 1.f }, &game->sars->projection_x, &baby->entity.model_x); - sfx_play(&sfx.baby_hatted); + sfx_play(&sfx.baby_hatted, 1.f); stage_set_active(mask->entity.node, 0); } @@ -454,7 +454,7 @@ static void maga_adult(game_t *game, adult_t *adult, maga_t *maga) * memory ensured maga was always off initially. */ game->is_maga = 1; - sfx_play(&sfx.adult_maga); + sfx_play(&sfx.adult_maga, 1.f); stage_set_active(maga->entity.node, 0); } @@ -464,13 +464,13 @@ static void mask_adult(game_t *game, adult_t *adult, mask_t *mask) if (game->is_maga) { /* MAGA discards masks */ stage_set_active(mask->entity.node, 0); - return sfx_play(&sfx.adult_maga); + return sfx_play(&sfx.adult_maga, 1.f); } (void) adult_masked_node_new(&(stage_conf_t){ .stage = adult->entity.node, .replace = 1, .name = "adult-masked", .active = 1, .alpha = 1.f }, &game->sars->projection_x, &adult->entity.model_x); adult->masked += GAME_MASK_PROTECTION; - sfx_play(&sfx.adult_mine); + sfx_play(&sfx.adult_mine, 1.f); stage_set_active(mask->entity.node, 0); } @@ -481,9 +481,9 @@ static int expose_adult(game_t *game, adult_t *adult, virus_t *virus) if (adult->masked) { if (!--adult->masked) { (void) adult_node_new(&(stage_conf_t){ .stage = adult->entity.node, .replace = 1, .name = "adult-unmasked", .active = 1, .alpha = 1.f }, &game->sars->projection_x, &adult->entity.model_x); - sfx_play(&sfx.adult_unmasked); + sfx_play(&sfx.adult_unmasked, 1.f); } else - sfx_play(&sfx.adult_maskhit); + sfx_play(&sfx.adult_maskhit, 1.f); (void) flash_entity(game, &adult->entity, 4); reset_virus(virus); @@ -492,11 +492,11 @@ static int expose_adult(game_t *game, adult_t *adult, virus_t *virus) /* convert adult into inanimate virus (off the viruses array) */ (void) virus_node_new(&(stage_conf_t){ .stage = adult->entity.node, .replace = 1, .name = "adult-virus", .active = 1, .alpha = 1.f }, &game->sars->projection_x, &adult->entity.model_x); - sfx_play(&sfx.adult_infected); + sfx_play(&sfx.adult_infected, 1.f); if (adult->holding) { (void) virus_node_new(&(stage_conf_t){ .stage = adult->holding->entity.node, .replace = 1, .name = "baby-virus", .active = 1, .alpha = 1.f }, &game->sars->projection_x, &adult->holding->entity.model_x); - sfx_play(&sfx.baby_infected); + sfx_play(&sfx.baby_infected, 1.f); } game->state = GAME_STATE_OVER; @@ -510,7 +510,7 @@ static void pickup_baby(game_t *game, adult_t *adult, baby_t *baby) if (adult->holding) return; - sfx_play(&sfx.baby_held); + sfx_play(&sfx.baby_held, 1.f); adult->holding = baby; adult->holding->entity.position = adult->entity.position; entity_update_x(game, &adult->holding->entity); @@ -523,7 +523,7 @@ static void more_teepee(game_t *game, teepee_t *teepee) if (game->adult->holding) { /* disallow picking up teepee if holding something, flash what's held and the teepee we missed */ if (flash_entity(game, &teepee->entity, 5)) - sfx_play(&sfx.adult_armsfull); + sfx_play(&sfx.adult_armsfull, 1.f); (void) flash_entity(game, &game->adult->holding->entity, 5); return; @@ -558,7 +558,7 @@ static void more_teepee(game_t *game, teepee_t *teepee) } (*teepee->bonus_release) = BONUS_NODE_RELEASE_MS; (*teepee->bonus_release_position) = teepee->entity.position; - sfx_play(&sfx.adult_mine); + sfx_play(&sfx.adult_mine, 1.f); stage_set_active(teepee->entity.node, 0); } @@ -990,12 +990,12 @@ static ix2_search_status_t adult_search(void *cb_context, ix2_object_t *ix2_obje case ENTITY_TYPE_TV: game->adult->captivated = 1; - sfx_play(&sfx.adult_captivated); + sfx_play(&sfx.adult_captivated, 1.f); /* shifted because rand() tends to have more activity in the upper bits, * but this could be more careful about avoiding repetition by randomizing * a 0-9 list every time it stepped through said list. TODO */ - sfx_play(&sfx.tv_talk[(rand() >> 8) % NELEMS(sfx.tv_talk)]); + sfx_play(&sfx.tv_talk[(rand() >> 8) % NELEMS(sfx.tv_talk)], 1.f); return IX2_SEARCH_STOP_HIT; @@ -1057,7 +1057,7 @@ static void game_move_adult(game_t *game, v2f_t *dir) game->adult->entity.position.y < -1.05f) { /* rescued baby */ - sfx_play(&sfx.baby_rescued); + sfx_play(&sfx.baby_rescued, 1.f); /* make the rescued baby available for respawn reuse */ game->adult->holding->entity.flashes_remaining = 0; @@ -63,10 +63,16 @@ void sfx_init(void) } -void sfx_play(sfx_sound_t *sound) +/* play sfx, volume 0-1 */ +void sfx_play(sfx_sound_t *sound, float volume) { assert(sound); + if (volume > 1.f) + volume = 1.f; + else if (volume < 0.f) + volume = 0.f; + if (sound->chunk) { int channel; @@ -74,6 +80,7 @@ void sfx_play(sfx_sound_t *sound) if (channel < 0) channel = Mix_GroupOldest(sound->voice); + Mix_Volume(channel, MIX_MAX_VOLUME * volume); Mix_PlayChannel(channel, sound->chunk, 0); } } @@ -48,6 +48,6 @@ typedef struct sfx_t { extern sfx_t sfx; void sfx_init(void); -void sfx_play(sfx_sound_t *sound); +void sfx_play(sfx_sound_t *sound, float volume); #endif |