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

This commit is contained in:
Joe Adams 2017-12-13 15:27:55 +00:00
parent 862973e4c2
commit 96b2380036

View File

@ -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,12 +290,12 @@ 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 && ballNY<paddleRY) { // If to the right or below the top left corner of paddle
if (ballNX < paddleRX + (double)thePaddle->width) { // ...and to the left of the right side of the paddle (i.e. about to go inside inside the paddle)
if (ballNX > paddleRX && ballNY<paddleRY && // If to the right and below the top left corner of paddle
ballNX < paddleRX + (double)thePaddle->width && // ...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
theBall->vX *= -1.0;