James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Revision:
13:418a71b24b37
Parent:
12:f714a9e8c55b
Child:
14:38560375d420
--- a/PongEngine/PongEngine.cpp	Mon Apr 22 21:45:18 2019 +0000
+++ b/PongEngine/PongEngine.cpp	Tue Apr 23 07:42:44 2019 +0000
@@ -19,6 +19,7 @@
     _paddle_height = paddle_height;
     _ball_size = ball_size;
     _speed = speed;
+    _number_left = 18;
 
     // y position on screen - WIDTH is defined in N5110.h
     _p1y = HEIGHT - GAP;
@@ -296,7 +297,7 @@
         (ball_pos.y <= _brick11_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick11_pos.y;
+        ball_pos.y = _brick11_pos.y + HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -305,6 +306,7 @@
         _brick11_pos.x = -100;
         _brick11_pos.y = -100;
         _brick11.set_pos(_brick11_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick12_pos = _brick12.get_pos();
@@ -317,7 +319,7 @@
         (ball_pos.y <= _brick12_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick12_pos.y;
+        ball_pos.y = _brick12_pos.y + HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -326,6 +328,7 @@
         _brick12_pos.x = -100;
         _brick12_pos.y = -100;
         _brick12.set_pos(_brick12_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick13_pos = _brick13.get_pos();
@@ -338,7 +341,7 @@
         (ball_pos.y <= _brick13_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick13_pos.y;
+        ball_pos.y = _brick13_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -347,6 +350,7 @@
         _brick13_pos.x = -100;
         _brick13_pos.y = -100;
         _brick13.set_pos(_brick13_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick14_pos = _brick14.get_pos();
@@ -359,7 +363,7 @@
         (ball_pos.y <= _brick14_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick14_pos.y;
+        ball_pos.y = _brick14_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -368,6 +372,7 @@
         _brick14_pos.x = -100;
         _brick14_pos.y = -100;
         _brick14.set_pos(_brick14_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick15_pos = _brick15.get_pos();
@@ -380,7 +385,7 @@
         (ball_pos.y <= _brick15_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick15_pos.y;
+        ball_pos.y = _brick15_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -389,6 +394,7 @@
         _brick15_pos.x = -100;
         _brick15_pos.y = -100;
         _brick15.set_pos(_brick15_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick16_pos = _brick16.get_pos();
@@ -401,7 +407,7 @@
         (ball_pos.y <= _brick16_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick16_pos.y;
+        ball_pos.y = _brick16_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -410,6 +416,7 @@
         _brick16_pos.x = -100;
         _brick16_pos.y = -100;
         _brick16.set_pos(_brick16_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick21_pos = _brick21.get_pos();
@@ -422,7 +429,7 @@
         (ball_pos.y <= _brick21_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick21_pos.y;
+        ball_pos.y = _brick21_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -431,6 +438,7 @@
         _brick21_pos.x = -100;
         _brick21_pos.y = -100;
         _brick21.set_pos(_brick21_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick22_pos = _brick22.get_pos();
@@ -443,7 +451,7 @@
         (ball_pos.y <= _brick22_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick22_pos.y;
+        ball_pos.y = _brick22_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -452,6 +460,7 @@
         _brick22_pos.x = -100;
         _brick22_pos.y = -100;
         _brick22.set_pos(_brick22_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick23_pos = _brick23.get_pos();
@@ -464,7 +473,7 @@
         (ball_pos.y <= _brick23_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick23_pos.y;
+        ball_pos.y = _brick23_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -473,6 +482,7 @@
         _brick23_pos.x = -100;
         _brick23_pos.y = -100;
         _brick23.set_pos(_brick23_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick24_pos = _brick24.get_pos();
@@ -485,7 +495,7 @@
         (ball_pos.y <= _brick24_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick24_pos.y;
+        ball_pos.y = _brick24_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -494,6 +504,7 @@
         _brick24_pos.x = -100;
         _brick24_pos.y = -100;
         _brick24.set_pos(_brick24_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick25_pos = _brick25.get_pos();
@@ -506,7 +517,7 @@
         (ball_pos.y <= _brick25_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick25_pos.y;
+        ball_pos.y = _brick25_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -515,6 +526,7 @@
         _brick25_pos.x = -100;
         _brick25_pos.y = -100;
         _brick25.set_pos(_brick25_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick26_pos = _brick26.get_pos();
@@ -527,7 +539,7 @@
         (ball_pos.y <= _brick26_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick26_pos.y;
+        ball_pos.y = _brick26_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -536,6 +548,7 @@
         _brick26_pos.x = -100;
         _brick26_pos.y = -100;
         _brick26.set_pos(_brick26_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick31_pos = _brick31.get_pos();
@@ -548,7 +561,7 @@
         (ball_pos.y <= _brick31_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick31_pos.y;
+        ball_pos.y = _brick31_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -557,6 +570,7 @@
         _brick31_pos.x = -100;
         _brick31_pos.y = -100;
         _brick31.set_pos(_brick31_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick32_pos = _brick32.get_pos();
@@ -569,7 +583,7 @@
         (ball_pos.y <= _brick32_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick32_pos.y;
+        ball_pos.y = _brick32_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -578,6 +592,7 @@
         _brick32_pos.x = -100;
         _brick32_pos.y = -100;
         _brick32.set_pos(_brick32_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick33_pos = _brick33.get_pos();
@@ -590,7 +605,7 @@
         (ball_pos.y <= _brick33_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick33_pos.y;
+        ball_pos.y = _brick33_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -599,6 +614,7 @@
         _brick33_pos.x = -100;
         _brick33_pos.y = -100;
         _brick33.set_pos(_brick33_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick34_pos = _brick34.get_pos();
@@ -611,7 +627,7 @@
         (ball_pos.y <= _brick34_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick34_pos.y;
+        ball_pos.y = _brick34_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -620,6 +636,7 @@
         _brick34_pos.x = -100;
         _brick34_pos.y = -100;
         _brick34.set_pos(_brick34_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick35_pos = _brick35.get_pos();
@@ -632,7 +649,7 @@
         (ball_pos.y <= _brick35_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick35_pos.y;
+        ball_pos.y = _brick35_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -641,6 +658,7 @@
         _brick35_pos.x = -100;
         _brick35_pos.y = -100;
         _brick35.set_pos(_brick35_pos);
+        one_less();
     }
     // check p1 first
     Vector2D _brick36_pos = _brick36.get_pos();
@@ -653,7 +671,7 @@
         (ball_pos.y <= _brick36_pos.y + HEIGHT_BRICK)  //top
     ) {    // edit this so that if it hits the middle, reflect, else change angle depending on how far off centre (add angle to ball)
         // if it has, fix position and reflect x velocity  
-        ball_pos.y = _brick36_pos.y;
+        ball_pos.y = _brick36_pos.y+ HEIGHT_BRICK;
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
@@ -662,6 +680,7 @@
         _brick36_pos.x = -100;
         _brick36_pos.y = -100;
         _brick36.set_pos(_brick36_pos);
+        one_less();
     }
 
     // write new attributes
@@ -714,4 +733,11 @@
     char buffer1[14];
     sprintf(buffer1,"%2d",p1_score);
     lcd.printString(buffer1,WIDTH/2 -8,4);  // font is 8 wide, so leave 4 pixel gape from middle assuming two digits
+}
+
+int PongEngine::get_num_left(){
+    return _number_left;
+}
+void PongEngine::one_less() {
+    _number_left -= 1;
 }
\ No newline at end of file