class for bullet in Car_race game

Committer:
fy14aaz
Date:
Thu Apr 13 22:16:14 2017 +0000
Revision:
5:fd945bf405dc
Parent:
4:a32443aee8f8
Child:
6:581257752de1
made the bullet go into three different directions

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 5:fd945bf405dc 48 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 5:fd945bf405dc 53 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 1:6bd0cbdf15f7 57 }