class for bullet in Car_race game

Committer:
fy14aaz
Date:
Sat Apr 15 18:18:39 2017 +0000
Revision:
6:581257752de1
Parent:
5:fd945bf405dc
Child:
7:b852cf8f4f36
however i dont know why this was happening but ill try figure out

Who changed what in which revision?

UserRevisionLine numberNew 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 4:a32443aee8f8 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 5:fd945bf405dc 41
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 6:581257752de1 58 // the problem is apparently due to the ball being darw with coordinates 1,1 and particularly X=1
fy14aaz 6:581257752de1 59 if ((_bullet_x == 1)) {
fy14aaz 6:581257752de1 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 }