class for bullet in Car_race game

Revision:
6:581257752de1
Parent:
5:fd945bf405dc
Child:
7:b852cf8f4f36
diff -r fd945bf405dc -r 581257752de1 Bullet.cpp
--- a/Bullet.cpp	Thu Apr 13 22:16:14 2017 +0000
+++ b/Bullet.cpp	Sat Apr 15 18:18:39 2017 +0000
@@ -45,13 +45,28 @@
     }
      // printf("x=%d y=%d \n",_bullet_x,_bullet_y);
      
-     if(_bulletDirection==2) {
+    else if(_bulletDirection==2) {
     _bullet_x = _bullet_x - 3;
     _bullet_y = _bullet_y - 3; 
     }
     
-    if(_bulletDirection==3) {
+    else if(_bulletDirection==3) {
     _bullet_x = _bullet_x + 3;
     _bullet_y = _bullet_y - 3; 
     }
+    
+    // the problem is apparently due to the ball being darw with coordinates 1,1 and particularly X=1
+    if ((_bullet_x == 1)) {
+       clearBullet(lcd);
+       _bullet_x = _bullet_x - 1;
+       _bullet_y = _bullet_y - 1; 
+    }
+}
+
+void Bullet::clearBullet(N5110 &lcd)
+{ 
+    lcd.setPixel(_bullet_x,_bullet_y,false);
+    lcd.setPixel(_bullet_x,_bullet_y+1,false);
+    lcd.setPixel(_bullet_x+1,_bullet_y,false);
+    lcd.setPixel(_bullet_x+1,_bullet_y+1,false);
 }
\ No newline at end of file