From 3b9661cf9b195bd07144528dd6bde0ed6017f074 Mon Sep 17 00:00:00 2001 From: Quinn <99677023+thepigeongenerator@users.noreply.github.com> Date: Fri, 16 Aug 2024 18:42:03 +0200 Subject: [PATCH] made paddle bouncing more reliable --- src/level.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/level.c b/src/level.c index 96b685b..627fcf0 100644 --- a/src/level.c +++ b/src/level.c @@ -96,9 +96,9 @@ static void update_ball(Level* level, Ball* ball, Bouncer* bouncer) { // 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); // 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 + float x = ball->pos.x - bouncer->pos.x + (ball->size / 2) + 2; // get the X axis relative to the bouncer (add 2, see below) + unsigned max = bouncer->width + 4; // get the maxiumum of this X axis (add 4 to make it feel more accurate) + float angle = (x - (max / 2.0F)) / max * (PI / 1.5F); // calculate the angle in radians where the bouncer X axis falls on -60° to 60° // change the ball direction ball->direction.x = SDL_sinf(angle) * BALL_SPEED;