class for bullet in Car_race game
Bullet.cpp
- Committer:
- fy14aaz
- Date:
- 2017-04-16
- Revision:
- 7:b852cf8f4f36
- Parent:
- 6:581257752de1
- Child:
- 8:89a98a3d7233
File content as of revision 7:b852cf8f4f36:
#include "Bullet.h" Bullet::Bullet() { } Bullet::~Bullet() { } void Bullet::init(Vector2D _CarHead) { _bullet_x = _CarHead.x; _bullet_y = _CarHead.y + 2; // printf("x=%d y=%d \n",_bullet_x,_bullet_y); } void Bullet::draw(N5110 &lcd) { // 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(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); // printf("x=%d y=%d \n",_bullet_x,_bullet_y); if(_bulletDirection==1) { _bullet_x = _bullet_x; _bullet_y = _bullet_y - 3; } // printf("x=%d y=%d \n",_bullet_x,_bullet_y); else if(_bulletDirection==2) { _bullet_x = _bullet_x - 3; _bullet_y = _bullet_y - 3; } else if(_bulletDirection==3) { _bullet_x = _bullet_x + 3; _bullet_y = _bullet_y - 3; } // 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)) { 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); }