From d3a8306f4fee8e6a4e11166d60f4c569121f80fa Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Tue, 4 Aug 2009 19:01:14 +0200 Subject: [PATCH] Sound volume + panning moved into rendering function --- game.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/game.c b/game.c index 06941f5..8be0157 100644 --- a/game.c +++ b/game.c @@ -252,8 +252,6 @@ bool step( GameState* s) { /* bounce from the ground */ if (fabsf(s->ball.move_z) > 0.3) { s->sound_events ^= SOUND_EVENT_GROUND; - sample_volume_group(SOUND_GROUND_FIRST, SOUND_GROUND_LAST, fmaxf(0.0, fminf(1.0, fabsf(s->ball.move_z)/2))); - pan_sample_group(SOUND_GROUND_FIRST, SOUND_GROUND_LAST, fmaxf(0.0, fminf(1.0, (s->ball.x)/WIDTH))); s->ball.move_z *= -s->ball.restitution; } else { s->ball.move_z = 0; @@ -372,10 +370,7 @@ bool step( GameState* s) { s->ball.ground_hit = false; s->ball.inhibit_gravity = false; s->ball.last_hit_by = p; - if (p==1) { - pan_sample_group(SOUND_RACKET_FIRST, SOUND_RACKET_LAST, 0.3); - } else { - pan_sample_group(SOUND_RACKET_FIRST, SOUND_RACKET_LAST, 0.7); + if (p==2) { s->ball.move_x *= -1; } } @@ -436,6 +431,10 @@ void render(const GameState* s, RenderState* r) { /* The bits in sound_events flip when the sound should play */ if ((sounds = (r->sound_events ^ s->sound_events)) != 0) { if (sounds & SOUND_EVENT_GROUND) { + sample_volume_group(SOUND_GROUND_FIRST, SOUND_GROUND_LAST, + fmaxf(0.0, fminf(1.0, fabsf(s->ball.move_z)/2))); + pan_sample_group(SOUND_GROUND_FIRST, SOUND_GROUND_LAST, + fmaxf(0.0, fminf(1.0, (s->ball.x)/WIDTH))); play_sample(SOUND_GROUND); } if (sounds & SOUND_EVENT_OUT) { @@ -445,6 +444,11 @@ void render(const GameState* s, RenderState* r) { play_sample(SOUND_APPLAUSE); } if (sounds & SOUND_EVENT_RACKET) { + if (((s->ball.x)/WIDTH) < 0.5) { + pan_sample_group(SOUND_RACKET_FIRST, SOUND_RACKET_LAST, 0.3); + } else { + pan_sample_group(SOUND_RACKET_FIRST, SOUND_RACKET_LAST, 0.7); + } play_sample(SOUND_RACKET); } r->sound_events = s->sound_events; -- 2.11.4.GIT