SharpShooter
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Obstacle.h@6:7f8c3169483a, 2016-10-28 (annotated)
- Committer:
- jboettcher
- Date:
- Fri Oct 28 01:00:49 2016 +0000
- Revision:
- 6:7f8c3169483a
- Parent:
- 5:f51cdddf541e
- Child:
- 9:96a2e663994b
shooter and obstacle initially done
Who changed what in which revision?
User | Revision | Line number | New 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; |
jboettcher | 5:f51cdddf541e | 44 | } |