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 12:2f358065ba3f 3 extern DigitalOut myled1;
jboettcher 11:55b65415b6ba 4
jboettcher 12:2f358065ba3f 5 struct ObstLocation {
jboettcher 12:2f358065ba3f 6 int x1, y1, x2, y2;
jboettcher 12:2f358065ba3f 7 };
jboettcher 11:55b65415b6ba 8
jboettcher 1:8a3fa9e90572 9 class Obstacle
jboettcher 1:8a3fa9e90572 10 {
jboettcher 5:f51cdddf541e 11 int x1,x2,y1,y2;
jboettcher 5:f51cdddf541e 12 bool direction;
jboettcher 5:f51cdddf541e 13
jboettcher 5:f51cdddf541e 14 public:
jboettcher 12:2f358065ba3f 15 Obstacle();
jboettcher 12:2f358065ba3f 16 Obstacle(int x1, int y1, int x2, int y2);
jboettcher 5:f51cdddf541e 17 void drawObstacle();
jboettcher 12:2f358065ba3f 18 void eraseObstacle();
jboettcher 5:f51cdddf541e 19 void move(int speed);
jboettcher 5:f51cdddf541e 20 void changeDirection();// need change direction when hitting wall
jboettcher 5:f51cdddf541e 21 void setDirection(bool direction);
jboettcher 12:2f358065ba3f 22 ObstLocation getLocation();
jboettcher 5:f51cdddf541e 23 };
jboettcher 5:f51cdddf541e 24
jboettcher 12:2f358065ba3f 25 Obstacle::Obstacle() {
jboettcher 12:2f358065ba3f 26 x1 = 2;
jboettcher 12:2f358065ba3f 27 x2 = 50;
jboettcher 12:2f358065ba3f 28 y1 = 62;
jboettcher 12:2f358065ba3f 29 y2 = 65;
jboettcher 12:2f358065ba3f 30 direction = 1;
jboettcher 12:2f358065ba3f 31 }
jboettcher 12:2f358065ba3f 32
jboettcher 11:55b65415b6ba 33 Obstacle::Obstacle(int a, int b, int c, int d) {
jboettcher 5:f51cdddf541e 34 x1 = a;
jboettcher 12:2f358065ba3f 35 y1 = b;
jboettcher 12:2f358065ba3f 36 x2 = c;
jboettcher 5:f51cdddf541e 37 y2 = d;
jboettcher 5:f51cdddf541e 38 }
jboettcher 5:f51cdddf541e 39
jboettcher 5:f51cdddf541e 40 void Obstacle::drawObstacle() {
jboettcher 12:2f358065ba3f 41 mutex.lock();
jboettcher 12:2f358065ba3f 42 uLCD.filled_rectangle(x1,y1,x2,y2,DGREY);
jboettcher 12:2f358065ba3f 43 mutex.unlock();
jboettcher 12:2f358065ba3f 44
jboettcher 12:2f358065ba3f 45 }
jboettcher 12:2f358065ba3f 46
jboettcher 12:2f358065ba3f 47 void Obstacle::eraseObstacle() {
jboettcher 12:2f358065ba3f 48 mutex.lock();
jboettcher 12:2f358065ba3f 49 uLCD.filled_rectangle(x1,y1,x2,y2,BACKGROUND);
jboettcher 12:2f358065ba3f 50 mutex.unlock();
jboettcher 12:2f358065ba3f 51
jboettcher 5:f51cdddf541e 52 }
jboettcher 5:f51cdddf541e 53
jboettcher 5:f51cdddf541e 54 void Obstacle::move(int speed) {
jboettcher 12:2f358065ba3f 55 mutex.lock();
jboettcher 12:2f358065ba3f 56 Obstacle::eraseObstacle();
jboettcher 12:2f358065ba3f 57 if (x1<=1 || x2>=127) {
jboettcher 12:2f358065ba3f 58 Obstacle::changeDirection();
jboettcher 12:2f358065ba3f 59 myled1=!myled1;
jboettcher 12:2f358065ba3f 60 }
jboettcher 5:f51cdddf541e 61 if (direction==1) {
jboettcher 5:f51cdddf541e 62 x1 += speed;
jboettcher 5:f51cdddf541e 63 x2 += speed;
jboettcher 5:f51cdddf541e 64 }
jboettcher 5:f51cdddf541e 65 else {
jboettcher 5:f51cdddf541e 66 x1 -= speed;
jboettcher 5:f51cdddf541e 67 x2 -= speed;
jboettcher 5:f51cdddf541e 68 }
jboettcher 12:2f358065ba3f 69 Obstacle::drawObstacle();
jboettcher 12:2f358065ba3f 70 mutex.unlock();
jboettcher 5:f51cdddf541e 71 }
jboettcher 5:f51cdddf541e 72
jboettcher 5:f51cdddf541e 73 void Obstacle::changeDirection() {
jboettcher 11:55b65415b6ba 74 direction = !direction;
jboettcher 5:f51cdddf541e 75 }
jboettcher 5:f51cdddf541e 76
jboettcher 5:f51cdddf541e 77 void Obstacle::setDirection(bool a) {
jboettcher 5:f51cdddf541e 78 direction = a;
SeanBuckingham 8:56a24df93680 79 }
jboettcher 12:2f358065ba3f 80
jboettcher 12:2f358065ba3f 81 ObstLocation Obstacle::getLocation() {
jboettcher 12:2f358065ba3f 82 ObstLocation coor {x1, y1, x2, y2};
jboettcher 12:2f358065ba3f 83 return coor;
jboettcher 12:2f358065ba3f 84 }