ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_PROJECT_EL18KK

Dependencies:   mbed

Revision:
3:f86c1cf90d0d
Parent:
2:21973e665a32
Child:
4:08a0ff6668df
diff -r 21973e665a32 -r f86c1cf90d0d Ball/Ball.cpp
--- a/Ball/Ball.cpp	Sat Apr 25 21:56:30 2020 +0000
+++ b/Ball/Ball.cpp	Mon Apr 27 21:58:35 2020 +0000
@@ -51,29 +51,30 @@
         _ball_y = BALL_INIT_Y;
         lcd.drawSprite(_ball_x,_ball_y,11,15,(int *)ball);
     }
-void Ball::set_location(int x, int y,N5110 &lcd) {
+void Ball::setLocation(int x, int y,N5110 &lcd) {
         lcd.drawSprite(x,y,11,15,(int *)ball);
     }
-void Ball::play_shot_animation(int user_input_x, int user_input_y,N5110 &lcd) {
+void Ball::playShot(int user_input_x, int user_input_y,N5110 &lcd) {
         _user_input_x = user_input_x;
         _user_input_y = user_input_y;
-        int j = 0;
-        
-        while(_user_input_x != _ball_x || _user_input_y != _ball_y) {
-                for(int i = 0; i < 12; i++ ) {
-                if(_user_input_x < _ball_x ) { _ball_x --;}
-                else if(_user_input_x > _ball_x ) { _ball_x ++;}
+        int i = 0;
+        int kar = 0;
+        while(_user_input_x < _ball_x || _user_input_y < _ball_y) {
+                
+                if(_user_input_x < _ball_x ) { _ball_x -=2.5;}
+                else if(_user_input_x > _ball_x ) { _ball_x +=2.5;}
                 
-                if(_user_input_y < _ball_y ) { _ball_y --;}
-                else if(_user_input_y > _ball_y ) { _ball_y ++;}
-                lcd.drawSprite(_ball_x,_ball_y,11,15,(int *)ball[j]);
-                
+                if(_user_input_y < _ball_y ) { _ball_y -=2.5;}
+                else if(_user_input_y > _ball_y ) { _ball_y +=2.5;}
+                lcd.drawSprite(_ball_x,_ball_y,11,15,(int *)ball[kar]);
+                             
+                        if(i == 4) {kar = 0;}
+                        if(i == 6) {kar = 1;}
+                        if(i == 8) {kar = 2;}
+                printf("%d \n",i);       
+                i++;    
+                wait_ms(100);
                 
-                        if(i == 4) {j = 0;}
-                        if(i == 8) {j = 1;}
-                        if(i == 12) {j = 2;}
-                        break;
-                    }
-                wait_ms(50);
+                lcd.refresh();                
             }
     }
\ No newline at end of file