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:
parent
862973e4c2
commit
96b2380036
@ -175,7 +175,7 @@ int main(void) {
|
|||||||
Uint32 tickrate=SDL_GetTicks()-timer;
|
Uint32 tickrate=SDL_GetTicks()-timer;
|
||||||
timer=SDL_GetTicks();
|
timer=SDL_GetTicks();
|
||||||
int fps=1000/(tickrate+1);
|
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;
|
paddleCol.r = 1.0; paddleCol.g = 1.0; paddleCol.b = 1.0; paddleCol.a = 1.0;
|
||||||
|
|
||||||
colour bgcol1; colour bgcol2;
|
colour bgcol1; colour bgcol2;
|
||||||
bgcol1.r = 0.0824; /*21*/ bgcol2.r = 0.7216; /*184*/
|
//bgcol1.r = 0.0824; /*21*/ bgcol2.r = 0.7216; /*184*/
|
||||||
bgcol1.g = 0.0901; /*23*/ bgcol2.g = 0.2471; /*63*/
|
//bgcol1.g = 0.0901; /*23*/ bgcol2.g = 0.2471; /*63*/
|
||||||
bgcol1.b = 0.4431; /*113*/ bgcol2.b = 0.6078; /*155*/
|
//bgcol1.b = 0.4431; /*113*/ bgcol2.b = 0.6078; /*155*/
|
||||||
bgcol1.a = 1.0000; /*255*/ bgcol2.a = 1.0000; /*255*/
|
//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);
|
drawPaddle(&thePaddle, winWidth, winHeight, &paddleCol);
|
||||||
drawBall(&theBall, &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 paddleRX = thePaddle->x - (double)(winWidth / 2);
|
||||||
double paddleRY = 20 - (double)(winHeight / 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 && ballNY<paddleRY && // If to the right and 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)
|
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)
|
||||||
theBall->vY *= -1.0;
|
ballNY > (paddleRY-thePaddle->height)) { // ...and above the bottom of the paddle
|
||||||
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
|
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
|
if (ballNX > winWidth / 2 || ballNX < (-1.0*winWidth/2)) { // Collision with walls
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user