class for bullet in Car_race game
Diff: Bullet.cpp
- Revision:
- 8:89a98a3d7233
- Parent:
- 7:b852cf8f4f36
- Child:
- 9:4ea00d3a8ce0
diff -r b852cf8f4f36 -r 89a98a3d7233 Bullet.cpp --- a/Bullet.cpp Sun Apr 16 19:04:08 2017 +0000 +++ b/Bullet.cpp Mon Apr 17 20:45:25 2017 +0000 @@ -27,17 +27,18 @@ // lcd.setPixel(_bullet_x+1,_bullet_y+2,false); // lcd.setPixel(_bullet_x+1,_bullet_y+3,false); - + // printf("x=%d y=%d \n",_bullet_x,_bullet_y); lcd.drawRect(_bullet_x,_bullet_y,2,2,FILL_BLACK); - + // printf("Crashes 0 \n"); } void Bullet::update(N5110 &lcd,int _bulletDirection) { - 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); + // 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); + clearBullet(lcd); // printf("x=%d y=%d \n",_bullet_x,_bullet_y); if(_bulletDirection==1) { _bullet_x = _bullet_x; @@ -56,7 +57,7 @@ } // the following piece of code to get around the problem of the game getting stuck when the value of _bullet_x = 1 - if ((_bullet_x == 0)) { + if ((_bullet_x == -2)) { clearBullet(lcd); _bullet_x = _bullet_x - 1; _bullet_y = _bullet_y - 1; @@ -69,4 +70,26 @@ 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); +} + +void Bullet::destroyObstacles(N5110 &lcd) +{ + printf("they are x=%d y=%d \n",_bullet_x,_bullet_y); + if ((lcd.getPixel(_bullet_x,_bullet_y)) || // this is for bullet itself + (lcd.getPixel(_bullet_x,_bullet_y+1)) || // this is for bullet itself + (lcd.getPixel(_bullet_x+1,_bullet_y)) || // this is for bullet itself + (lcd.getPixel(_bullet_x+1,_bullet_y+1)) || // this is for bullet itself + (lcd.getPixel(_bullet_x,_bullet_y-1)) || // up + (lcd.getPixel(_bullet_x+1,_bullet_y-1)) || // up + (lcd.getPixel(_bullet_x,_bullet_y+2)) || // down + (lcd.getPixel(_bullet_x+1,_bullet_y+2))) { // down + + for (int i=1; i<83; i+=1) { + for (int j=_bullet_y-4; j<_bullet_y+5; j+=1) { + lcd.setPixel(i,j,false); + } + } + _bullet_x = -10; + _bullet_y = -10; + } } \ No newline at end of file