diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2023-11-02 16:06:04 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2023-11-02 16:15:40 -0700 |
commit | f95815ef0445647ab2ca0ca3e5b0a6f5bbcf118b (patch) | |
tree | 5fe18f7ec9a20a3bdd55f11d36634ee0d24dba1b | |
parent | 34a5de28f0b467ec3177da5b9516d06a69b07f58 (diff) |
game: play talk sfx when TV appears at spatial volume
Instead of only playing the talk sfx when adult gets glued to the
TV, always play it when the TV appears.
Also scale the volume with the inverse square of the distance
from the TV.
-rw-r--r-- | src/game.c | 25 |
1 files changed, 20 insertions, 5 deletions
@@ -400,6 +400,19 @@ static void reset_virus(virus_t *virus) } +/* return a 0-1 volume based on entity's distance from the adult */ +static float entity_volume(game_t *game, entity_any_t *entity) +{ + float volume; + v2f_t delta; + + delta = v2f_sub(&game->adult->entity.position, &entity->position); + volume = 1.f - ((1.f / 2.8284f) * v2f_length(&delta)); + + return (volume * volume); +} + + /* returns 1 if entity started flashing, 0 if already flashing */ static int flash_entity(game_t *game, entity_any_t *any, unsigned count) { @@ -817,6 +830,13 @@ static void update_entities(play_t *play, game_t *game) game->tv->entity.position.y = randf(); entity_update_x(game, &game->tv->entity); stage_set_active(game->tv->entity.node, 1); + + /* 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)], + entity_volume(game, &game->tv->entity)); } if (game->adult->captivated && randf() > (1.f - GAME_MAGA_CHANCE) && !stage_get_active(game->maga->entity.node)) { @@ -991,11 +1011,6 @@ 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, 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)], 1.f); return IX2_SEARCH_STOP_HIT; |