Dependencies:   mbed

Revision:
7:35465b3bf586
Parent:
6:312b7ae0c0f2
Child:
8:10eb578dd754
--- a/Ball/Ball.cpp	Sun May 17 19:12:52 2020 +0000
+++ b/Ball/Ball.cpp	Mon May 18 14:28:05 2020 +0000
@@ -11,61 +11,67 @@
 }
 
 
-void Ball::init()
+void Ball::init(int x,int y)
 {
     int ball[2][2] = {
     {1,1},
     {1,1},
     };
-    ball_x_pos = 21;
-    ball_y_pos = 0;
+    ball_x_pos = x;
+    ball_y_pos = y;
+
 }
 
 
 void Ball::draw(N5110 &lcd)
 {
-    int x = ball_x_pos;
-    int y = ball_y_pos;
-    lcd.drawSprite(x,y,2,2,(int *)ball);
+    lcd.drawSprite(ball_x_pos,ball_y_pos,2,2,(int *)ball);
 }
 
 void Ball::update(Direction d)
 {
-    if (d == N && ball_y_pos < 83){
-        ball_y_pos ++;
-        };
+    
+    if(d != CENTRE){
+        
+    if (d == S && ball_y_pos < 46){
+        ball_y_pos++;
+        }
     
-    if (d == S && ball_y_pos > 1){
-        ball_y_pos --;
-        };
+    if (d == N && ball_y_pos > 1){
+        ball_y_pos--;
+        }
         
-    if (d == E && ball_x_pos < 46){
-        ball_x_pos ++;
-        };
+    if (d == E && ball_x_pos < 83){
+        ball_x_pos++;
+        }
     
     if (d == W && ball_x_pos > 0){
-        ball_x_pos --;
+        ball_x_pos--;
+        }
+        
+    if (d == SE && ball_y_pos < 46 && ball_x_pos < 83){
+        ball_x_pos++;
+        ball_y_pos++;
+        }
+        
+    if (d == NE && ball_y_pos > 1 && ball_x_pos < 83){
+        ball_x_pos++;
+        ball_y_pos--;
         };
         
-    if (d == NE && ball_y_pos < 46 && ball_x_pos < 83){
-        ball_x_pos ++;
-        ball_y_pos ++;
-        };
-        
-    if (d == SE && ball_y_pos > 1 && ball_x_pos < 83){
-        ball_x_pos ++;
-        ball_y_pos --;
-        };
+    if (d == NW && ball_x_pos > 0 && ball_y_pos > 1){
+        ball_x_pos--;
+        ball_y_pos--;
+        }
         
-    if (d == SW && ball_x_pos > 0 && ball_y_pos > 1){
-        ball_x_pos --;
-        ball_y_pos --;
-        };
+    if (d == SW && ball_x_pos > 0 && ball_y_pos < 46){
+        ball_x_pos--;
+        ball_y_pos++;
+        }
         
-    if (d == NW && ball_x_pos > 0 && ball_y_pos < 46){
-        ball_x_pos --;
-        ball_y_pos ++;
-        }; 
+        }
+        
+
     
 }