SharpShooter

Dependencies:   4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player

Committer:
jboettcher
Date:
Sat Oct 29 00:18:10 2016 +0000
Revision:
12:2f358065ba3f
Parent:
11:55b65415b6ba
Child:
15:e09ab0d14d4b
Lotttttta shit today;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jboettcher 11:55b65415b6ba 1 extern uLCD_4DGL uLCD;
jboettcher 12:2f358065ba3f 2 extern Mutex mutex;
jboettcher 11:55b65415b6ba 3
jboettcher 11:55b65415b6ba 4 struct BulletLocation {
jboettcher 11:55b65415b6ba 5 int x, topY, bottomY;
jboettcher 11:55b65415b6ba 6 };
jboettcher 11:55b65415b6ba 7
SeanBuckingham 2:e8f2b2320353 8 class Bullet {
SeanBuckingham 2:e8f2b2320353 9
SeanBuckingham 7:ed2c73e25681 10 int x, topY, bottomY;
jboettcher 11:55b65415b6ba 11 int length;
jboettcher 11:55b65415b6ba 12 int speed;
jboettcher 11:55b65415b6ba 13
SeanBuckingham 7:ed2c73e25681 14
SeanBuckingham 7:ed2c73e25681 15 public:
jboettcher 11:55b65415b6ba 16 Bullet();
SeanBuckingham 7:ed2c73e25681 17 void drawBullet(int x, int bottomY);
SeanBuckingham 7:ed2c73e25681 18 void eraseBullet();
jboettcher 11:55b65415b6ba 19 void move();
jboettcher 11:55b65415b6ba 20 BulletLocation getLocation();
SeanBuckingham 7:ed2c73e25681 21 };
SeanBuckingham 7:ed2c73e25681 22
jboettcher 11:55b65415b6ba 23 Bullet::Bullet() {
jboettcher 11:55b65415b6ba 24 length = 3;
jboettcher 11:55b65415b6ba 25 speed = 3;
jboettcher 11:55b65415b6ba 26 x=1;
jboettcher 11:55b65415b6ba 27 topY=2;
jboettcher 11:55b65415b6ba 28 bottomY=3;
SeanBuckingham 7:ed2c73e25681 29 }
SeanBuckingham 7:ed2c73e25681 30
SeanBuckingham 7:ed2c73e25681 31 /*Bullet::Bullet(int x, int bottomY, uLCD_4DGL uLCD) {
SeanBuckingham 7:ed2c73e25681 32 this->x = x;
SeanBuckingham 7:ed2c73e25681 33 this->bottomY = bottomY;
SeanBuckingham 7:ed2c73e25681 34 this->topY = bottomY + length;
SeanBuckingham 7:ed2c73e25681 35 this->uLCD = uLCD;
SeanBuckingham 7:ed2c73e25681 36 }*/
SeanBuckingham 7:ed2c73e25681 37
jboettcher 12:2f358065ba3f 38 void Bullet::drawBullet(int x2, int bottomY2) {
jboettcher 12:2f358065ba3f 39 x = x2;
jboettcher 12:2f358065ba3f 40 bottomY = bottomY2;
jboettcher 12:2f358065ba3f 41 topY = bottomY + length;
jboettcher 12:2f358065ba3f 42 mutex.lock();
jboettcher 12:2f358065ba3f 43 uLCD.line(x,topY,x,bottomY, BLACK);
jboettcher 12:2f358065ba3f 44 mutex.unlock();
jboettcher 12:2f358065ba3f 45
SeanBuckingham 7:ed2c73e25681 46 }
SeanBuckingham 7:ed2c73e25681 47
SeanBuckingham 7:ed2c73e25681 48 void Bullet::move() {
jboettcher 12:2f358065ba3f 49 Bullet::eraseBullet();
jboettcher 12:2f358065ba3f 50 bottomY -= speed;
jboettcher 12:2f358065ba3f 51 Bullet::drawBullet(x, bottomY);
SeanBuckingham 7:ed2c73e25681 52 }
SeanBuckingham 7:ed2c73e25681 53
SeanBuckingham 7:ed2c73e25681 54 void Bullet::eraseBullet() {
jboettcher 12:2f358065ba3f 55 mutex.lock();
jboettcher 12:2f358065ba3f 56 uLCD.line(x,topY,x,bottomY, BACKGROUND);
jboettcher 12:2f358065ba3f 57 mutex.unlock();
jboettcher 12:2f358065ba3f 58
SeanBuckingham 7:ed2c73e25681 59 }
SeanBuckingham 7:ed2c73e25681 60
jboettcher 11:55b65415b6ba 61 BulletLocation Bullet::getLocation() {
jboettcher 11:55b65415b6ba 62 BulletLocation coor {x, topY, bottomY};
SeanBuckingham 7:ed2c73e25681 63 return coor;
SeanBuckingham 7:ed2c73e25681 64 }