James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Revision:
1:e18615d46071
Parent:
0:7d4d2023ed9c
Child:
2:b3ca50f2e85d
diff -r 7d4d2023ed9c -r e18615d46071 PongEngine/PongEngine.cpp
--- a/PongEngine/PongEngine.cpp	Tue Apr 16 18:58:18 2019 +0000
+++ b/PongEngine/PongEngine.cpp	Wed Apr 17 21:19:16 2019 +0000
@@ -18,13 +18,11 @@
     _ball_size = ball_size;
     _speed = speed;
 
-    // x position on screen - WIDTH is defined in N5110.h
-    _p1x = GAP;
-    _p2x = WIDTH - GAP - _paddle_width;
+    // y position on screen - WIDTH is defined in N5110.h
+    _p1y = HEIGHT - GAP;
 
     // puts paddles and ball in middle
-    _p1.init(_p1x,_paddle_height,_paddle_width);
-    _p2.init(_p2x,_paddle_height,_paddle_width);
+    _p1.init(_p1y,_paddle_height,_paddle_width);
     _ball.init(_ball_size,_speed);
 }
 
@@ -43,7 +41,6 @@
     print_scores(lcd);
     // paddles
     _p1.draw(lcd);
-    _p2.draw(lcd);
     // ball
     _ball.draw(lcd);
 }
@@ -54,7 +51,6 @@
     // important to update paddles and ball before checking collisions so can
     // correct for it before updating the display
     _p1.update(_d,_mag);
-    _p2.update(_d,_mag);
     _ball.update();
 
     check_wall_collision(pad);
@@ -106,31 +102,14 @@
 
     // see if ball has hit the paddle by checking for overlaps
     if (
-        (ball_pos.y >= p1_pos.y) && //top
-        (ball_pos.y <= p1_pos.y + _paddle_height) && //bottom
-        (ball_pos.x >= _p1x) && //left
-        (ball_pos.x <= _p1x + _paddle_width)  //right
+        (ball_pos.y >= p1_pos.x) && //left
+        (ball_pos.y <= p1_pos.x + _paddle_width) && //right
+        (ball_pos.x >= _p1y) && //bottom
+        (ball_pos.x <= _p1y + _paddle_height)  //top
     ) {
         // if it has, fix position and reflect x velocity
-        ball_pos.x = _p1x + _paddle_width;
-        ball_velocity.x = -ball_velocity.x;
-        // audio feedback
-        pad.tone(1000.0,0.1);
-    }
-
-    // check p2 next
-    Vector2D p2_pos = _p2.get_pos();
-
-    // see if ball has hit the paddle by checking for overlaps
-    if (
-        (ball_pos.y >= p2_pos.y) && //top
-        (ball_pos.y <= p2_pos.y + _paddle_height) && //bottom
-        (ball_pos.x + _ball_size >= _p2x) && //left
-        (ball_pos.x + _ball_size <= _p2x + _paddle_width)  //right
-    ) {
-        // if it has, fix position and reflect x velocity
-        ball_pos.x = _p2x - _ball_size;
-        ball_velocity.x = -ball_velocity.x;
+        ball_pos.y = _p1y + _paddle_height;
+        ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
     }
@@ -158,13 +137,9 @@
 {
     // get scores from paddles
     int p1_score = _p1.get_score();
-    int p2_score = _p2.get_score();
 
     // print to LCD i
     char buffer1[14];
     sprintf(buffer1,"%2d",p1_score);
     lcd.printString(buffer1,WIDTH/2 - 20,1);  // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
-    char buffer2[14];
-    sprintf(buffer2,"%2d",p2_score);
-    lcd.printString(buffer2,WIDTH/2 + 4,1);
 }
\ No newline at end of file