Don't let paddles go out of range
authorJames Bunton <jamesbunton@fastmail.fm>
Sat, 23 Jun 2007 11:57:43 +0000 (21:57 +1000)
committerJames Bunton <jamesbunton@fastmail.fm>
Sat, 23 Jun 2007 11:57:43 +0000 (21:57 +1000)
pong.c

diff --git a/pong.c b/pong.c
index 6f2ec4c..af2dce8 100644 (file)
--- a/pong.c
+++ b/pong.c
@@ -53,6 +53,14 @@ static void run(void) {
        // Move the paddles
        paddle1 += p1move * PADDLESPEED;
        paddle2 += p2move * PADDLESPEED;
+       if(paddle1 < -HEIGHT)
+               paddle1 = -HEIGHT;
+       if(paddle1 > HEIGHT)
+               paddle1 = HEIGHT;
+       if(paddle2 < -HEIGHT)
+               paddle2 = -HEIGHT;
+       if(paddle2 > HEIGHT)
+               paddle2 = HEIGHT;
 
        // Check for collisions with paddles
        if(ballVecX < 0 && ballX <= -HEIGHT + -ballVecX * 1.5) {