XJEL2645 (18/19) / Mbed 2 deprecated 2645_Mygame

Dependencies:   mbed Gamepad N5110

Revision:
15:4123abb17291
Parent:
11:543c62bed764
diff -r e1f7b4be1cf2 -r 4123abb17291 snake/snake.cpp
--- a/snake/snake.cpp	Mon Apr 22 07:22:56 2019 +0000
+++ b/snake/snake.cpp	Mon Apr 22 09:59:39 2019 +0000
@@ -19,13 +19,13 @@
         _x[i] = 0;
         _y[i] = 0;
     }
-    _x[0] = WIDTH/2 -  _size/2;
-    _y[0] = HEIGHT/2 - _size/2;
+    _x[0] = WIDTH/2 -  _size;
+    _y[0] = HEIGHT/2 - _size;
 
-    _x[1] = _x[0] -size;
+    _x[1] = _x[0] - _size;
     _y[1] = _y[0];
     
-    _x[2] = _x[0] -2*size;
+    _x[2] = _x[0] -2*_size;
     _y[2] = _y[0];
      
     ball( _length);
@@ -67,14 +67,14 @@
         }
         
     // draw ball in screen buffer.
-        lcd.drawCircle(ball_x,ball_y,1,FILL_BLACK);
+        lcd.drawRect(ball_x,ball_y,2,2,FILL_BLACK);
 }
 
 void snake::ball(int length)
 {
     srand(time(NULL));
-    ball_x = 3 + rand() % (WIDTH - 6); // randomise initial position of ball. 
-    ball_y = 3 + rand() % (HEIGHT - 6);
+    ball_x = (3 + rand() % (37))*2; // randomise initial position of ball. 
+    ball_y = (3 + rand() % (19))*2;
     int check = 0;
     do{
       check = 0;
@@ -84,15 +84,15 @@
           }
        }
         //srand(time(NULL));
-        ball_x = 3 + rand() % (WIDTH - 6); // randomise initial position of ball. 
-        ball_y = 3 + rand() % (HEIGHT - 6);
+        ball_x = (3 + rand() % (37))*2; // randomise initial position of ball. 
+        ball_y = (3 + rand() % (19))*2;
      } while(check == 1);
 }
 
 void snake::check_eat(Gamepad &pad)
 {
     //
-    if (ball_x + _size >=  _x[0] && ball_x - _size <=  _x[0] && ball_y + _size >=  _y[0] && ball_y - _size <=  _y[0]) {
+    if (ball_x ==  _x[0] && ball_y == _y[0]) {
         _length++;
         _score++;
         ball(_length);