diff --git a/README.md b/README.md index f84a33f..173bbda 100644 --- a/README.md +++ b/README.md @@ -3,5 +3,4 @@ I wanted a project to learn C and the SDL framework in, and settled upon this ga ### TODO: - make a better input system (one that doesn't crash the game) -- make the bouncer collisions more reliable - make beeping sound effects diff --git a/src/level.c b/src/level.c index 7fb0f0f..b75768f 100644 --- a/src/level.c +++ b/src/level.c @@ -91,10 +91,11 @@ void level_update(Level* level, bool* keys) { // check bouncer collisions if ((ball->pos.x + ball->size) > bouncer->pos.x && ball->pos.x < (bouncer->pos.x + bouncer->width) && (ball->pos.y + ball->size) > bouncer->pos.y && ball->pos.y < (bouncer->pos.y + BOUNCER_HEIGHT)) { - float x = ball->pos.x - bouncer->pos.x + (ball->size / 2); - unsigned max = bouncer->width; - float angle = (x - (0.5F * max)) / max * PI; + float x = ball->pos.x - bouncer->pos.x + (ball->size / 2); // get the X axis relative to the bouncer + unsigned max = bouncer->width + 2; // get the maxiumum of this X axis (add 2 to make it feel more accurate) + float angle = (x - (max / 2.0F)) / max * PI; // calculate the angle in radians where the bouncer X axis falls on -(pi/2) to pi/2 + // change the ball direction ball->direction.x = SDL_sinf(angle) * BALL_SPEED; ball->direction.y = -SDL_cosf(angle) * BALL_SPEED; }