James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Revision:
12:f714a9e8c55b
Parent:
10:9f445faa892c
Child:
13:418a71b24b37
--- a/PongEngine/PongEngine.cpp	Mon Apr 22 20:32:52 2019 +0000
+++ b/PongEngine/PongEngine.cpp	Mon Apr 22 21:45:18 2019 +0000
@@ -300,15 +300,376 @@
         ball_velocity.y = -ball_velocity.y;
         // audio feedback
         pad.tone(1000.0,0.1);
+        _brick11.hit();
+        //delete _brick11;
+        _brick11_pos.x = -100;
+        _brick11_pos.y = -100;
+        _brick11.set_pos(_brick11_pos);
     }
+    // check p1 first
+    Vector2D _brick12_pos = _brick12.get_pos();
     
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick12_pos.x) && //left
+        (ball_pos.x <= _brick12_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick12_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick12.hit();
+        //delete _brick12;
+        _brick12_pos.x = -100;
+        _brick12_pos.y = -100;
+        _brick12.set_pos(_brick12_pos);
+    }
+    // check p1 first
+    Vector2D _brick13_pos = _brick13.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick13_pos.x) && //left
+        (ball_pos.x <= _brick13_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick13_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick13.hit();
+        //delete _brick13;
+        _brick13_pos.x = -100;
+        _brick13_pos.y = -100;
+        _brick13.set_pos(_brick13_pos);
+    }
+    // check p1 first
+    Vector2D _brick14_pos = _brick14.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick14_pos.x) && //left
+        (ball_pos.x <= _brick14_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick14_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick14.hit();
+        //delete _brick14;
+        _brick14_pos.x = -100;
+        _brick14_pos.y = -100;
+        _brick14.set_pos(_brick14_pos);
+    }
+    // check p1 first
+    Vector2D _brick15_pos = _brick15.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick15_pos.x) && //left
+        (ball_pos.x <= _brick15_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick15_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick15.hit();
+        //delete _brick15;
+        _brick15_pos.x = -100;
+        _brick15_pos.y = -100;
+        _brick15.set_pos(_brick15_pos);
+    }
+    // check p1 first
+    Vector2D _brick16_pos = _brick16.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick16_pos.x) && //left
+        (ball_pos.x <= _brick16_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick16_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick16.hit();
+        //delete _brick16;
+        _brick16_pos.x = -100;
+        _brick16_pos.y = -100;
+        _brick16.set_pos(_brick16_pos);
+    }
+    // check p1 first
+    Vector2D _brick21_pos = _brick21.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick21_pos.x) && //left
+        (ball_pos.x <= _brick21_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick21_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick21.hit();
+        //delete _brick21;
+        _brick21_pos.x = -100;
+        _brick21_pos.y = -100;
+        _brick21.set_pos(_brick21_pos);
+    }
+    // check p1 first
+    Vector2D _brick22_pos = _brick22.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick22_pos.x) && //left
+        (ball_pos.x <= _brick22_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick22_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick22.hit();
+        //delete _brick22;
+        _brick22_pos.x = -100;
+        _brick22_pos.y = -100;
+        _brick22.set_pos(_brick22_pos);
+    }
+    // check p1 first
+    Vector2D _brick23_pos = _brick23.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick23_pos.x) && //left
+        (ball_pos.x <= _brick23_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick23_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick23.hit();
+        //delete _brick23;
+        _brick23_pos.x = -100;
+        _brick23_pos.y = -100;
+        _brick23.set_pos(_brick23_pos);
+    }
+    // check p1 first
+    Vector2D _brick24_pos = _brick24.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick24_pos.x) && //left
+        (ball_pos.x <= _brick24_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick24_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick24.hit();
+        //delete _brick24;
+        _brick24_pos.x = -100;
+        _brick24_pos.y = -100;
+        _brick24.set_pos(_brick24_pos);
+    }
+    // check p1 first
+    Vector2D _brick25_pos = _brick25.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick25_pos.x) && //left
+        (ball_pos.x <= _brick25_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick25_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick25.hit();
+        //delete _brick25;
+        _brick25_pos.x = -100;
+        _brick25_pos.y = -100;
+        _brick25.set_pos(_brick25_pos);
+    }
+    // check p1 first
+    Vector2D _brick26_pos = _brick26.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick26_pos.x) && //left
+        (ball_pos.x <= _brick26_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick26_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick26.hit();
+        //delete _brick26;
+        _brick26_pos.x = -100;
+        _brick26_pos.y = -100;
+        _brick26.set_pos(_brick26_pos);
+    }
+    // check p1 first
+    Vector2D _brick31_pos = _brick31.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick31_pos.x) && //left
+        (ball_pos.x <= _brick31_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick31_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick31.hit();
+        //delete _brick31;
+        _brick31_pos.x = -100;
+        _brick31_pos.y = -100;
+        _brick31.set_pos(_brick31_pos);
+    }
+    // check p1 first
+    Vector2D _brick32_pos = _brick32.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick32_pos.x) && //left
+        (ball_pos.x <= _brick32_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick32_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick32.hit();
+        //delete _brick32;
+        _brick32_pos.x = -100;
+        _brick32_pos.y = -100;
+        _brick32.set_pos(_brick32_pos);
+    }
+    // check p1 first
+    Vector2D _brick33_pos = _brick33.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick33_pos.x) && //left
+        (ball_pos.x <= _brick33_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick33_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick33.hit();
+        //delete _brick33;
+        _brick33_pos.x = -100;
+        _brick33_pos.y = -100;
+        _brick33.set_pos(_brick33_pos);
+    }
+    // check p1 first
+    Vector2D _brick34_pos = _brick34.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick34_pos.x) && //left
+        (ball_pos.x <= _brick34_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick34_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick34.hit();
+        //delete _brick34;
+        _brick34_pos.x = -100;
+        _brick34_pos.y = -100;
+        _brick34.set_pos(_brick34_pos);
+    }
+    // check p1 first
+    Vector2D _brick35_pos = _brick35.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick35_pos.x) && //left
+        (ball_pos.x <= _brick35_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick35_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick35.hit();
+        //delete _brick35;
+        _brick35_pos.x = -100;
+        _brick35_pos.y = -100;
+        _brick35.set_pos(_brick35_pos);
+    }
+    // check p1 first
+    Vector2D _brick36_pos = _brick36.get_pos();
+    
+    // see if ball has hit the paddle by checking for overlaps
+    if (
+        (ball_pos.x >= _brick36_pos.x) && //left
+        (ball_pos.x <= _brick36_pos.x + WIDTH_BRICK) && //right
+        (ball_pos.y >= _brick36_pos.y) && //bottom
+        (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_velocity.y = -ball_velocity.y;
+        // audio feedback
+        pad.tone(1000.0,0.1);
+        _brick36.hit();
+        //delete _brick36;
+        _brick36_pos.x = -100;
+        _brick36_pos.y = -100;
+        _brick36.set_pos(_brick36_pos);
+    }
+
     // write new attributes
     _ball.set_velocity(ball_velocity);
     _ball.set_pos(ball_pos);
-    _brick11.hit();
 }
 
-void PongEngine::check_goal(Gamepad &pad)
+bool PongEngine::check_goal(Gamepad &pad)
 {
     Vector2D ball_pos = _ball.get_pos();
     // P1 has scored
@@ -318,7 +679,10 @@
         
         _ball.init(_ball_size,_speed);
         pad.tone(1500.0,0.5);
-        //flash_backlight(lcd);
+        return true;
+    }
+    else {
+        return false;
     }
 }