class for bullet in Car_race game
Diff: Bullet.cpp
- Revision:
- 5:fd945bf405dc
- Parent:
- 4:a32443aee8f8
- Child:
- 6:581257752de1
--- a/Bullet.cpp Tue Apr 11 22:37:46 2017 +0000 +++ b/Bullet.cpp Thu Apr 13 22:16:14 2017 +0000 @@ -20,12 +20,38 @@ void Bullet::draw(N5110 &lcd) { - lcd.drawRect(_bullet_x,_bullet_x,2,2,FILL_BLACK); + // printf("x=%d y=%d \n",_bullet_x,_bullet_y); + + // lcd.setPixel(_bullet_x,_bullet_y+2,false); + // lcd.setPixel(_bullet_x,_bullet_y+3,false); + // lcd.setPixel(_bullet_x+1,_bullet_y+2,false); + // lcd.setPixel(_bullet_x+1,_bullet_y+3,false); + + + lcd.drawRect(_bullet_x,_bullet_y,2,2,FILL_BLACK); + } -void Bullet::update() -{ +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); + + if(_bulletDirection==1) { _bullet_x = _bullet_x; - _bullet_y = _bullet_y - 5; - printf("x=%d y=%d \n",_bullet_x,_bullet_y); + _bullet_y = _bullet_y - 3; + } + // printf("x=%d y=%d \n",_bullet_x,_bullet_y); + + if(_bulletDirection==2) { + _bullet_x = _bullet_x - 3; + _bullet_y = _bullet_y - 3; + } + + if(_bulletDirection==3) { + _bullet_x = _bullet_x + 3; + _bullet_y = _bullet_y - 3; + } } \ No newline at end of file