class for bullet in Car_race game
Bullet.cpp@7:b852cf8f4f36, 2017-04-16 (annotated)
- Committer:
- fy14aaz
- Date:
- Sun Apr 16 19:04:08 2017 +0000
- Revision:
- 7:b852cf8f4f36
- Parent:
- 6:581257752de1
- Child:
- 8:89a98a3d7233
The problem starts exactly after updating and when to draw the car, the exact line is commented on code. Still have not found out why though
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fy14aaz | 1:6bd0cbdf15f7 | 1 | #include "Bullet.h" |
fy14aaz | 1:6bd0cbdf15f7 | 2 | |
fy14aaz | 1:6bd0cbdf15f7 | 3 | Bullet::Bullet() |
fy14aaz | 1:6bd0cbdf15f7 | 4 | { |
fy14aaz | 1:6bd0cbdf15f7 | 5 | |
fy14aaz | 1:6bd0cbdf15f7 | 6 | } |
fy14aaz | 1:6bd0cbdf15f7 | 7 | |
fy14aaz | 1:6bd0cbdf15f7 | 8 | Bullet::~Bullet() |
fy14aaz | 1:6bd0cbdf15f7 | 9 | { |
fy14aaz | 1:6bd0cbdf15f7 | 10 | |
fy14aaz | 1:6bd0cbdf15f7 | 11 | } |
fy14aaz | 1:6bd0cbdf15f7 | 12 | |
fy14aaz | 4:a32443aee8f8 | 13 | void Bullet::init(Vector2D _CarHead) |
fy14aaz | 1:6bd0cbdf15f7 | 14 | { |
fy14aaz | 4:a32443aee8f8 | 15 | _bullet_x = _CarHead.x; |
fy14aaz | 4:a32443aee8f8 | 16 | _bullet_y = _CarHead.y + 2; |
fy14aaz | 4:a32443aee8f8 | 17 | |
fy14aaz | 7:b852cf8f4f36 | 18 | // printf("x=%d y=%d \n",_bullet_x,_bullet_y); |
fy14aaz | 1:6bd0cbdf15f7 | 19 | } |
fy14aaz | 1:6bd0cbdf15f7 | 20 | |
fy14aaz | 1:6bd0cbdf15f7 | 21 | void Bullet::draw(N5110 &lcd) |
fy14aaz | 1:6bd0cbdf15f7 | 22 | { |
fy14aaz | 5:fd945bf405dc | 23 | // printf("x=%d y=%d \n",_bullet_x,_bullet_y); |
fy14aaz | 5:fd945bf405dc | 24 | |
fy14aaz | 5:fd945bf405dc | 25 | // lcd.setPixel(_bullet_x,_bullet_y+2,false); |
fy14aaz | 5:fd945bf405dc | 26 | // lcd.setPixel(_bullet_x,_bullet_y+3,false); |
fy14aaz | 5:fd945bf405dc | 27 | // lcd.setPixel(_bullet_x+1,_bullet_y+2,false); |
fy14aaz | 5:fd945bf405dc | 28 | // lcd.setPixel(_bullet_x+1,_bullet_y+3,false); |
fy14aaz | 5:fd945bf405dc | 29 | |
fy14aaz | 5:fd945bf405dc | 30 | |
fy14aaz | 5:fd945bf405dc | 31 | lcd.drawRect(_bullet_x,_bullet_y,2,2,FILL_BLACK); |
fy14aaz | 5:fd945bf405dc | 32 | |
fy14aaz | 1:6bd0cbdf15f7 | 33 | } |
fy14aaz | 1:6bd0cbdf15f7 | 34 | |
fy14aaz | 5:fd945bf405dc | 35 | void Bullet::update(N5110 &lcd,int _bulletDirection) |
fy14aaz | 5:fd945bf405dc | 36 | { |
fy14aaz | 5:fd945bf405dc | 37 | lcd.setPixel(_bullet_x,_bullet_y,false); |
fy14aaz | 5:fd945bf405dc | 38 | lcd.setPixel(_bullet_x,_bullet_y+1,false); |
fy14aaz | 5:fd945bf405dc | 39 | lcd.setPixel(_bullet_x+1,_bullet_y,false); |
fy14aaz | 5:fd945bf405dc | 40 | lcd.setPixel(_bullet_x+1,_bullet_y+1,false); |
fy14aaz | 7:b852cf8f4f36 | 41 | // printf("x=%d y=%d \n",_bullet_x,_bullet_y); |
fy14aaz | 5:fd945bf405dc | 42 | if(_bulletDirection==1) { |
fy14aaz | 4:a32443aee8f8 | 43 | _bullet_x = _bullet_x; |
fy14aaz | 5:fd945bf405dc | 44 | _bullet_y = _bullet_y - 3; |
fy14aaz | 5:fd945bf405dc | 45 | } |
fy14aaz | 5:fd945bf405dc | 46 | // printf("x=%d y=%d \n",_bullet_x,_bullet_y); |
fy14aaz | 5:fd945bf405dc | 47 | |
fy14aaz | 6:581257752de1 | 48 | else if(_bulletDirection==2) { |
fy14aaz | 5:fd945bf405dc | 49 | _bullet_x = _bullet_x - 3; |
fy14aaz | 5:fd945bf405dc | 50 | _bullet_y = _bullet_y - 3; |
fy14aaz | 5:fd945bf405dc | 51 | } |
fy14aaz | 5:fd945bf405dc | 52 | |
fy14aaz | 6:581257752de1 | 53 | else if(_bulletDirection==3) { |
fy14aaz | 5:fd945bf405dc | 54 | _bullet_x = _bullet_x + 3; |
fy14aaz | 5:fd945bf405dc | 55 | _bullet_y = _bullet_y - 3; |
fy14aaz | 5:fd945bf405dc | 56 | } |
fy14aaz | 6:581257752de1 | 57 | |
fy14aaz | 7:b852cf8f4f36 | 58 | // the following piece of code to get around the problem of the game getting stuck when the value of _bullet_x = 1 |
fy14aaz | 7:b852cf8f4f36 | 59 | if ((_bullet_x == 0)) { |
fy14aaz | 7:b852cf8f4f36 | 60 | clearBullet(lcd); |
fy14aaz | 6:581257752de1 | 61 | _bullet_x = _bullet_x - 1; |
fy14aaz | 6:581257752de1 | 62 | _bullet_y = _bullet_y - 1; |
fy14aaz | 6:581257752de1 | 63 | } |
fy14aaz | 6:581257752de1 | 64 | } |
fy14aaz | 6:581257752de1 | 65 | |
fy14aaz | 6:581257752de1 | 66 | void Bullet::clearBullet(N5110 &lcd) |
fy14aaz | 6:581257752de1 | 67 | { |
fy14aaz | 6:581257752de1 | 68 | lcd.setPixel(_bullet_x,_bullet_y,false); |
fy14aaz | 6:581257752de1 | 69 | lcd.setPixel(_bullet_x,_bullet_y+1,false); |
fy14aaz | 6:581257752de1 | 70 | lcd.setPixel(_bullet_x+1,_bullet_y,false); |
fy14aaz | 6:581257752de1 | 71 | lcd.setPixel(_bullet_x+1,_bullet_y+1,false); |
fy14aaz | 1:6bd0cbdf15f7 | 72 | } |