SharpShooter

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

Committer:
SeanBuckingham
Date:
Fri Oct 28 01:06:01 2016 +0000
Revision:
9:96a2e663994b
Parent:
6:7f8c3169483a
Parent:
8:56a24df93680
Child:
11:55b65415b6ba
recent commit w most updated version;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jboettcher 1:8a3fa9e90572 1 class Obstacle
jboettcher 1:8a3fa9e90572 2 {
jboettcher 5:f51cdddf541e 3 int x1,x2,y1,y2;
jboettcher 5:f51cdddf541e 4 uLCD_4DGL uLCD;
jboettcher 5:f51cdddf541e 5 bool direction;
jboettcher 5:f51cdddf541e 6
jboettcher 5:f51cdddf541e 7 public:
jboettcher 5:f51cdddf541e 8 Obstacle(int x1, int x2, int y1, int y2, uLCD_4DGL uLCD);
jboettcher 5:f51cdddf541e 9 void drawObstacle();
jboettcher 5:f51cdddf541e 10 void move(int speed);
jboettcher 5:f51cdddf541e 11 void changeDirection();// need change direction when hitting wall
jboettcher 5:f51cdddf541e 12 void setDirection(bool direction);
jboettcher 5:f51cdddf541e 13 };
jboettcher 5:f51cdddf541e 14
jboettcher 5:f51cdddf541e 15 Obstacle::Obstacle(int a, int b, int c, int d, uLCD_4DGL e) {
jboettcher 5:f51cdddf541e 16 x1 = a;
jboettcher 5:f51cdddf541e 17 x2 = b;
jboettcher 5:f51cdddf541e 18 y1 = c;
jboettcher 5:f51cdddf541e 19 y2 = d;
jboettcher 5:f51cdddf541e 20 this->uLCD = e;
jboettcher 5:f51cdddf541e 21 }
jboettcher 5:f51cdddf541e 22
jboettcher 5:f51cdddf541e 23 void Obstacle::drawObstacle() {
jboettcher 5:f51cdddf541e 24 uLCD.filled_rectangle(x1,y1,x2,y2,0xFFFFFF);
jboettcher 5:f51cdddf541e 25 }
jboettcher 5:f51cdddf541e 26
jboettcher 5:f51cdddf541e 27 void Obstacle::move(int speed) {
jboettcher 5:f51cdddf541e 28 if (direction==1) {
jboettcher 5:f51cdddf541e 29 x1 += speed;
jboettcher 5:f51cdddf541e 30 x2 += speed;
jboettcher 5:f51cdddf541e 31 }
jboettcher 5:f51cdddf541e 32 else {
jboettcher 5:f51cdddf541e 33 x1 -= speed;
jboettcher 5:f51cdddf541e 34 x2 -= speed;
jboettcher 5:f51cdddf541e 35 }
jboettcher 5:f51cdddf541e 36 }
jboettcher 5:f51cdddf541e 37
jboettcher 5:f51cdddf541e 38 void Obstacle::changeDirection() {
jboettcher 5:f51cdddf541e 39 direction = !direction
jboettcher 5:f51cdddf541e 40 }
jboettcher 5:f51cdddf541e 41
jboettcher 5:f51cdddf541e 42 void Obstacle::setDirection(bool a) {
jboettcher 5:f51cdddf541e 43 direction = a;
SeanBuckingham 8:56a24df93680 44 }