From 96b2380036e3475bd6118fd6a6c664f9012465a7 Mon Sep 17 00:00:00 2001 From: Joe Adams Date: Wed, 13 Dec 2017 15:27:55 +0000 Subject: [PATCH] Changed colours to neutral, added check to updateBall() to prevent ball 'colliding' with the area beneath the paddle when not in contact with the paddle --- breakout/breakout.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/breakout/breakout.c b/breakout/breakout.c index 9db56b5..a887791 100644 --- a/breakout/breakout.c +++ b/breakout/breakout.c @@ -175,7 +175,7 @@ int main(void) { Uint32 tickrate=SDL_GetTicks()-timer; timer=SDL_GetTicks(); int fps=1000/(tickrate+1); - printf("Time to draw: %u, fps: %i \r", tickrate, fps); fflush(stdout); + //printf("Time to draw: %u, fps: %i \r", tickrate, fps); fflush(stdout); /* * ---------------- @@ -243,10 +243,14 @@ int main(void) { paddleCol.r = 1.0; paddleCol.g = 1.0; paddleCol.b = 1.0; paddleCol.a = 1.0; colour bgcol1; colour bgcol2; - bgcol1.r = 0.0824; /*21*/ bgcol2.r = 0.7216; /*184*/ - bgcol1.g = 0.0901; /*23*/ bgcol2.g = 0.2471; /*63*/ - bgcol1.b = 0.4431; /*113*/ bgcol2.b = 0.6078; /*155*/ - bgcol1.a = 1.0000; /*255*/ bgcol2.a = 1.0000; /*255*/ + //bgcol1.r = 0.0824; /*21*/ bgcol2.r = 0.7216; /*184*/ + //bgcol1.g = 0.0901; /*23*/ bgcol2.g = 0.2471; /*63*/ + //bgcol1.b = 0.4431; /*113*/ bgcol2.b = 0.6078; /*155*/ + //bgcol1.a = 1.0000; /*255*/ bgcol2.a = 1.0000; /*255*/ + bgcol1.r = 0.1500; bgcol2.r = 0.3500; + bgcol1.g = 0.1500; bgcol2.g = 0.3500; + bgcol1.b = 0.1500; bgcol2.b = 0.3500; + bgcol1.a = 1.0000; bgcol2.a = 1.0000; drawPaddle(&thePaddle, winWidth, winHeight, &paddleCol); drawBall(&theBall, &paddleCol); @@ -286,11 +290,11 @@ void updateBall(Uint32 tickrate, ball *theBall, paddle *thePaddle, int winWidth, double paddleRX = thePaddle->x - (double)(winWidth / 2); double paddleRY = 20 - (double)(winHeight / 2); - if (ballNX > paddleRX && ballNYwidth) { // ...and to the left of the right side of the paddle (i.e. about to go inside inside the paddle) - theBall->vY *= -1.0; - theBall->vX = ((ballNX - paddleRX - (double)(thePaddle->width/2))/((double)thePaddle->width/2))*0.5; // Sets X velocity to be proportional to the relative position of the ball and the paddle on collision - } + if (ballNX > paddleRX && ballNYwidth && // ...and to the left of the right side of the paddle (i.e. about to go inside inside the paddle) + ballNY > (paddleRY-thePaddle->height)) { // ...and above the bottom of the paddle + theBall->vY *= -1.0; + theBall->vX = ((ballNX - paddleRX - (double)(thePaddle->width/2))/((double)thePaddle->width/2))*0.5; // Sets X velocity to be proportional to the relative position of the ball and the paddle on collision } if (ballNX > winWidth / 2 || ballNX < (-1.0*winWidth/2)) { // Collision with walls