SharpShooter
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
Bullet.h@15:e09ab0d14d4b, 2016-10-31 (annotated)
- Committer:
- jboettcher
- Date:
- Mon Oct 31 18:15:21 2016 +0000
- Revision:
- 15:e09ab0d14d4b
- Parent:
- 12:2f358065ba3f
Finished
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| jboettcher | 11:55b65415b6ba | 1 | extern uLCD_4DGL uLCD; |
| jboettcher | 12:2f358065ba3f | 2 | extern Mutex mutex; |
| jboettcher | 11:55b65415b6ba | 3 | |
| jboettcher | 11:55b65415b6ba | 4 | struct BulletLocation { |
| jboettcher | 11:55b65415b6ba | 5 | int x, topY, bottomY; |
| jboettcher | 11:55b65415b6ba | 6 | }; |
| jboettcher | 11:55b65415b6ba | 7 | |
| SeanBuckingham | 2:e8f2b2320353 | 8 | class Bullet { |
| SeanBuckingham | 2:e8f2b2320353 | 9 | |
| SeanBuckingham | 7:ed2c73e25681 | 10 | int x, topY, bottomY; |
| jboettcher | 11:55b65415b6ba | 11 | int length; |
| jboettcher | 11:55b65415b6ba | 12 | int speed; |
| jboettcher | 11:55b65415b6ba | 13 | |
| SeanBuckingham | 7:ed2c73e25681 | 14 | |
| SeanBuckingham | 7:ed2c73e25681 | 15 | public: |
| jboettcher | 11:55b65415b6ba | 16 | Bullet(); |
| SeanBuckingham | 7:ed2c73e25681 | 17 | void drawBullet(int x, int bottomY); |
| SeanBuckingham | 7:ed2c73e25681 | 18 | void eraseBullet(); |
| jboettcher | 11:55b65415b6ba | 19 | void move(); |
| jboettcher | 11:55b65415b6ba | 20 | BulletLocation getLocation(); |
| SeanBuckingham | 7:ed2c73e25681 | 21 | }; |
| SeanBuckingham | 7:ed2c73e25681 | 22 | |
| jboettcher | 11:55b65415b6ba | 23 | Bullet::Bullet() { |
| jboettcher | 11:55b65415b6ba | 24 | length = 3; |
| jboettcher | 11:55b65415b6ba | 25 | speed = 3; |
| jboettcher | 11:55b65415b6ba | 26 | x=1; |
| jboettcher | 11:55b65415b6ba | 27 | topY=2; |
| jboettcher | 11:55b65415b6ba | 28 | bottomY=3; |
| SeanBuckingham | 7:ed2c73e25681 | 29 | } |
| SeanBuckingham | 7:ed2c73e25681 | 30 | |
| jboettcher | 12:2f358065ba3f | 31 | void Bullet::drawBullet(int x2, int bottomY2) { |
| jboettcher | 12:2f358065ba3f | 32 | x = x2; |
| jboettcher | 12:2f358065ba3f | 33 | bottomY = bottomY2; |
| jboettcher | 12:2f358065ba3f | 34 | topY = bottomY + length; |
| jboettcher | 12:2f358065ba3f | 35 | mutex.lock(); |
| jboettcher | 12:2f358065ba3f | 36 | uLCD.line(x,topY,x,bottomY, BLACK); |
| jboettcher | 12:2f358065ba3f | 37 | mutex.unlock(); |
| jboettcher | 12:2f358065ba3f | 38 | |
| SeanBuckingham | 7:ed2c73e25681 | 39 | } |
| SeanBuckingham | 7:ed2c73e25681 | 40 | |
| SeanBuckingham | 7:ed2c73e25681 | 41 | void Bullet::move() { |
| jboettcher | 12:2f358065ba3f | 42 | Bullet::eraseBullet(); |
| jboettcher | 12:2f358065ba3f | 43 | bottomY -= speed; |
| jboettcher | 12:2f358065ba3f | 44 | Bullet::drawBullet(x, bottomY); |
| SeanBuckingham | 7:ed2c73e25681 | 45 | } |
| SeanBuckingham | 7:ed2c73e25681 | 46 | |
| SeanBuckingham | 7:ed2c73e25681 | 47 | void Bullet::eraseBullet() { |
| jboettcher | 12:2f358065ba3f | 48 | mutex.lock(); |
| jboettcher | 12:2f358065ba3f | 49 | uLCD.line(x,topY,x,bottomY, BACKGROUND); |
| jboettcher | 12:2f358065ba3f | 50 | mutex.unlock(); |
| jboettcher | 12:2f358065ba3f | 51 | |
| SeanBuckingham | 7:ed2c73e25681 | 52 | } |
| SeanBuckingham | 7:ed2c73e25681 | 53 | |
| jboettcher | 11:55b65415b6ba | 54 | BulletLocation Bullet::getLocation() { |
| jboettcher | 11:55b65415b6ba | 55 | BulletLocation coor {x, topY, bottomY}; |
| SeanBuckingham | 7:ed2c73e25681 | 56 | return coor; |
| SeanBuckingham | 7:ed2c73e25681 | 57 | } |
