ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18zc_

Dependencies:   mbed

Revision:
9:a8420b353bb0
Parent:
8:5f0190b282f7
Child:
15:7ca2d1b2bd0e
--- a/Touch/Touch.cpp	Fri May 29 03:12:14 2020 +0000
+++ b/Touch/Touch.cpp	Fri May 29 03:27:27 2020 +0000
@@ -103,30 +103,24 @@
     Vector2D bullet_velocity = _bullet.get_velocity();
     Vector2D p1_pos = _board.get_pos();
     if (
-        (bullet_pos.x >= p1_pos.x) && //top
-        (bullet_pos.x <= p1_pos.x + _Board_length) && //bottom
-        (bullet_pos.y+_bullet_size >=p1_pos.y) //left
-          //right
+        (bullet_pos.x >= p1_pos.x) &&                   //left
+        (bullet_pos.x <= p1_pos.x + _Board_length) &&   //right
+        (bullet_pos.y+_bullet_size >=p1_pos.y)&&        //down
+        (bullet_pos.y-_Board_width<=p1_pos.y)           //up
     ){
         
         // if it has, fix position and reflect x velocity
-      //  bullet_pos.y = _boardy - _bullet_size;
-        bullet_velocity.y = -bullet_velocity.y;
-        // audio feedback
-        pad.tone(1000.0,0.1);
+        bullet_velocity.y = -bullet_velocity.y;     //fix position and reflect y velocity
+        pad.tone(1000.0,0.1);         // audio effect as reminder
         
     }
     if((bullet_pos.y >= 0)&&(bullet_pos.y <= 24))
         {
-           // Y= bullet_pos.y ;
-          //  X= bullet_pos.x;
-           // lcd.clearPixel(X,_Y-1);
             bullet_pos.y = bullet_pos.y + _Board_width;
             bullet_velocity.y = -bullet_velocity.y;
-          //  lcd.clearPixel(_x,_y-1);
+
         }
-    // lcd.clearPixel(X,Y-1);*/
-    // write new attributes
+    // write new datas
     _bullet.set_velocity(bullet_velocity);
     _bullet.set_pos(bullet_pos);
 }
@@ -134,10 +128,6 @@
 void Touch::drop(Gamepad &pad)
 {
     Vector2D bullet_pos = _bullet.get_pos();
-    
-    
-
-    // P1 has scored
     if (bullet_pos.y + _bullet_size> 47) {
         _board.add_score();
         _bullet.init(_board_x,_bullet_size,_speed,_Board_length);
@@ -162,5 +152,5 @@
     // 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
+    lcd.printString(buffer1,WIDTH/2 - 20,1); 
 }
\ No newline at end of file