From f08b0d5b75304bdb2d997fcafe9596a55ef781d0 Mon Sep 17 00:00:00 2001 From: Joe Date: Sun, 10 Dec 2017 20:39:34 +0000 Subject: [PATCH] Added some comments and changed X velocity post paddle-collision to be proportional to the relative position of the ball and paddle --- breakout/breakout.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/breakout/breakout.c b/breakout/breakout.c index 0bc1736..baff5f7 100644 --- a/breakout/breakout.c +++ b/breakout/breakout.c @@ -234,24 +234,25 @@ int main(void) { } void updateBall(double *ballX, double *ballY, double *ballVX, double *ballVY, double paddleX, int paddleWidth, int winWidth, int winHeight) { - double ballNX = *ballX + *ballVX; + double ballNX = *ballX + *ballVX; // Calculates the position of the ball on the next step double ballNY = *ballY + *ballVY; double paddleRX = paddleX - (double)(winWidth / 2); double paddleRY = 20 - (double)(winHeight / 2); - if (ballNX > paddleRX && ballNY paddleRX && ballNY winWidth / 2 || ballNX < (-1.0*winWidth/2)) { + if (ballNX > winWidth / 2 || ballNX < (-1.0*winWidth/2)) { // Collision with walls *ballVX *= -1.0; } - if (ballNY > winHeight / 2) { + if (ballNY > winHeight / 2) { // Collision with ceiling *ballVY *= -1.0; } - if (ballNY < (-1.0*winHeight/2)) { + if (ballNY < (-1.0*winHeight/2)) { // Collision with floor *ballX = 0; *ballY = 0; *ballVX = -0.1;