SharpShooter
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Obstacle.h@11:55b65415b6ba, 2016-10-28 (annotated)
- Committer:
- jboettcher
- Date:
- Fri Oct 28 20:07:38 2016 +0000
- Revision:
- 11:55b65415b6ba
- Parent:
- 9:96a2e663994b
- Child:
- 12:2f358065ba3f
First compile;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jboettcher | 11:55b65415b6ba | 1 | extern uLCD_4DGL uLCD; |
jboettcher | 11:55b65415b6ba | 2 | |
jboettcher | 11:55b65415b6ba | 3 | |
jboettcher | 1:8a3fa9e90572 | 4 | class Obstacle |
jboettcher | 1:8a3fa9e90572 | 5 | { |
jboettcher | 5:f51cdddf541e | 6 | int x1,x2,y1,y2; |
jboettcher | 5:f51cdddf541e | 7 | bool direction; |
jboettcher | 5:f51cdddf541e | 8 | |
jboettcher | 5:f51cdddf541e | 9 | public: |
jboettcher | 11:55b65415b6ba | 10 | Obstacle(int x1, int x2, int y1, int y2); |
jboettcher | 5:f51cdddf541e | 11 | void drawObstacle(); |
jboettcher | 5:f51cdddf541e | 12 | void move(int speed); |
jboettcher | 5:f51cdddf541e | 13 | void changeDirection();// need change direction when hitting wall |
jboettcher | 5:f51cdddf541e | 14 | void setDirection(bool direction); |
jboettcher | 5:f51cdddf541e | 15 | }; |
jboettcher | 5:f51cdddf541e | 16 | |
jboettcher | 11:55b65415b6ba | 17 | Obstacle::Obstacle(int a, int b, int c, int d) { |
jboettcher | 5:f51cdddf541e | 18 | x1 = a; |
jboettcher | 5:f51cdddf541e | 19 | x2 = b; |
jboettcher | 5:f51cdddf541e | 20 | y1 = c; |
jboettcher | 5:f51cdddf541e | 21 | y2 = d; |
jboettcher | 5:f51cdddf541e | 22 | } |
jboettcher | 5:f51cdddf541e | 23 | |
jboettcher | 5:f51cdddf541e | 24 | void Obstacle::drawObstacle() { |
jboettcher | 5:f51cdddf541e | 25 | uLCD.filled_rectangle(x1,y1,x2,y2,0xFFFFFF); |
jboettcher | 5:f51cdddf541e | 26 | } |
jboettcher | 5:f51cdddf541e | 27 | |
jboettcher | 5:f51cdddf541e | 28 | void Obstacle::move(int speed) { |
jboettcher | 5:f51cdddf541e | 29 | if (direction==1) { |
jboettcher | 5:f51cdddf541e | 30 | x1 += speed; |
jboettcher | 5:f51cdddf541e | 31 | x2 += speed; |
jboettcher | 5:f51cdddf541e | 32 | } |
jboettcher | 5:f51cdddf541e | 33 | else { |
jboettcher | 5:f51cdddf541e | 34 | x1 -= speed; |
jboettcher | 5:f51cdddf541e | 35 | x2 -= speed; |
jboettcher | 5:f51cdddf541e | 36 | } |
jboettcher | 5:f51cdddf541e | 37 | } |
jboettcher | 5:f51cdddf541e | 38 | |
jboettcher | 5:f51cdddf541e | 39 | void Obstacle::changeDirection() { |
jboettcher | 11:55b65415b6ba | 40 | direction = !direction; |
jboettcher | 5:f51cdddf541e | 41 | } |
jboettcher | 5:f51cdddf541e | 42 | |
jboettcher | 5:f51cdddf541e | 43 | void Obstacle::setDirection(bool a) { |
jboettcher | 5:f51cdddf541e | 44 | direction = a; |
SeanBuckingham | 8:56a24df93680 | 45 | } |