SharpShooter

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

Committer:
jboettcher
Date:
Mon Oct 31 18:15:21 2016 +0000
Revision:
15:e09ab0d14d4b
Parent:
12:2f358065ba3f
Finished

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 15:e09ab0d14d4b 3 extern wave_player waver;
jboettcher 11:55b65415b6ba 4
jboettcher 5:f51cdddf541e 5 class Shooter
jboettcher 5:f51cdddf541e 6 {
jboettcher 5:f51cdddf541e 7 int x;
jboettcher 6:7f8c3169483a 8
jboettcher 5:f51cdddf541e 9 public:
jboettcher 5:f51cdddf541e 10 Shooter();
jboettcher 5:f51cdddf541e 11 void drawShooter();
jboettcher 6:7f8c3169483a 12 void eraseShooter();
jboettcher 6:7f8c3169483a 13 void moveLeft();
jboettcher 6:7f8c3169483a 14 void moveRight();
jboettcher 12:2f358065ba3f 15 int getLocation();
jboettcher 5:f51cdddf541e 16 };
jboettcher 5:f51cdddf541e 17
jboettcher 5:f51cdddf541e 18 Shooter::Shooter() {
jboettcher 5:f51cdddf541e 19 x = 64;
jboettcher 5:f51cdddf541e 20 }
jboettcher 5:f51cdddf541e 21
jboettcher 6:7f8c3169483a 22 void Shooter::drawShooter() {
jboettcher 12:2f358065ba3f 23 mutex.lock();
jboettcher 12:2f358065ba3f 24 uLCD.triangle(x, 115, x-5, 125, x+5, 125, BLUE);
jboettcher 12:2f358065ba3f 25 uLCD.triangle(x, 118, x-2, 123, x+2, 123, BLUE);
jboettcher 12:2f358065ba3f 26 mutex.unlock();
jboettcher 6:7f8c3169483a 27 }
jboettcher 6:7f8c3169483a 28
jboettcher 6:7f8c3169483a 29 void Shooter::eraseShooter() {
jboettcher 12:2f358065ba3f 30 mutex.lock();
jboettcher 12:2f358065ba3f 31 uLCD.filled_rectangle(0, 115, 127, 127, BACKGROUND);
jboettcher 12:2f358065ba3f 32 mutex.unlock();
jboettcher 6:7f8c3169483a 33 }
jboettcher 6:7f8c3169483a 34
jboettcher 6:7f8c3169483a 35 void Shooter::moveLeft() {
jboettcher 12:2f358065ba3f 36 if (x==24) return;
jboettcher 12:2f358065ba3f 37 mutex.lock();
jboettcher 12:2f358065ba3f 38 Shooter::eraseShooter();
jboettcher 12:2f358065ba3f 39 if (x==64) x = 24;
jboettcher 12:2f358065ba3f 40 if (x==104) x = 64;
jboettcher 12:2f358065ba3f 41 Shooter::drawShooter();
jboettcher 12:2f358065ba3f 42 mutex.unlock();
jboettcher 15:e09ab0d14d4b 43
jboettcher 15:e09ab0d14d4b 44 FILE *wave_file;
jboettcher 15:e09ab0d14d4b 45 wave_file=fopen("/sd/wavfiles/move.wav","r");
jboettcher 15:e09ab0d14d4b 46 waver.play(wave_file);
jboettcher 15:e09ab0d14d4b 47 fclose(wave_file);
jboettcher 6:7f8c3169483a 48 }
jboettcher 6:7f8c3169483a 49
jboettcher 6:7f8c3169483a 50 void Shooter::moveRight() {
jboettcher 12:2f358065ba3f 51 if (x==104) return;
jboettcher 12:2f358065ba3f 52 mutex.lock();
jboettcher 12:2f358065ba3f 53 Shooter::eraseShooter();
jboettcher 12:2f358065ba3f 54 if (x==64) x = 104;
jboettcher 12:2f358065ba3f 55 if (x==24) x = 64;
jboettcher 12:2f358065ba3f 56 Shooter::drawShooter();
jboettcher 12:2f358065ba3f 57 mutex.unlock();
jboettcher 15:e09ab0d14d4b 58
jboettcher 15:e09ab0d14d4b 59 FILE *wave_file;
jboettcher 15:e09ab0d14d4b 60 wave_file=fopen("/sd/wavfiles/move.wav","r");
jboettcher 15:e09ab0d14d4b 61 waver.play(wave_file);
jboettcher 15:e09ab0d14d4b 62 fclose(wave_file);
jboettcher 6:7f8c3169483a 63 }
jboettcher 6:7f8c3169483a 64
jboettcher 12:2f358065ba3f 65 int Shooter::getLocation() {
jboettcher 12:2f358065ba3f 66 return x;
jboettcher 12:2f358065ba3f 67 }