The classic dueling tanks game for mbed.
Dependencies: 4DGL-uLCD-SE DRV2605 EthernetInterface Game_Synchronizer MMA8452 SDFileSystem SparkfunAnalogJoystick mbed-rtos mbed wave_player
Fork of 2035_Tanks_Shell by
Bullet/bullet.cpp@27:bd55ab4d137c, 2015-10-30 (annotated)
- Committer:
- jford38
- Date:
- Fri Oct 30 11:08:31 2015 +0000
- Revision:
- 27:bd55ab4d137c
- Parent:
- 26:317310d660b2
- Child:
- 28:8dbb85f35be6
Added a folder for sound. Clarified the role of globals.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jford38 | 17:7bc7127782e4 | 1 | #include "uLCD_4DGL.h" |
jford38 | 15:4b27a3a95772 | 2 | #include "bullet.h" |
jford38 | 15:4b27a3a95772 | 3 | #include "game_synchronizer.h" |
jford38 | 27:bd55ab4d137c | 4 | #include "globals.h" |
jford38 | 15:4b27a3a95772 | 5 | #include "math.h" |
jford38 | 15:4b27a3a95772 | 6 | |
jford38 | 15:4b27a3a95772 | 7 | extern Game_Synchronizer sync; |
jford38 | 15:4b27a3a95772 | 8 | |
jford38 | 22:3c68eea5a609 | 9 | // Initialize the bullet. Don't have to do much here. |
jford38 | 23:77049670cae6 | 10 | // Keep a pointer to this bullet's tank. |
jford38 | 23:77049670cae6 | 11 | // Set the speed, and default the bullet to not in_flight. |
jford38 | 15:4b27a3a95772 | 12 | Bullet::Bullet(Tank* t) { |
jford38 | 15:4b27a3a95772 | 13 | tank = t; |
jford38 | 22:3c68eea5a609 | 14 | //speed = ???; |
jford38 | 15:4b27a3a95772 | 15 | in_flight = false; |
jford38 | 15:4b27a3a95772 | 16 | } |
jford38 | 22:3c68eea5a609 | 17 | |
jford38 | 23:77049670cae6 | 18 | // If in_flight, do nothing. Otherwise, |
jford38 | 23:77049670cae6 | 19 | // set the in_flight flag, and initialize values needed for |
jford38 | 23:77049670cae6 | 20 | // the trajectory calculations. (x0, y0), (vx0, vy0), time |
jford38 | 23:77049670cae6 | 21 | // Hint: tank->barrel_end(...) is useful here. |
jford38 | 15:4b27a3a95772 | 22 | void Bullet::shoot(void) { |
jford38 | 23:77049670cae6 | 23 | in_flight = true; |
jford38 | 15:4b27a3a95772 | 24 | } |
jford38 | 15:4b27a3a95772 | 25 | |
jford38 | 22:3c68eea5a609 | 26 | // If the bullet is in flight, calculate its new position |
jford38 | 22:3c68eea5a609 | 27 | // after a time delta dt. |
jford38 | 21:edfeb289b21f | 28 | void Bullet::update_position(float dt) { |
jford38 | 22:3c68eea5a609 | 29 | |
jford38 | 21:edfeb289b21f | 30 | } |
jford38 | 21:edfeb289b21f | 31 | |
jford38 | 21:edfeb289b21f | 32 | int Bullet::time_step(float dt) { |
jford38 | 22:3c68eea5a609 | 33 | // If the bullet hasn't hit anything, |
jford38 | 22:3c68eea5a609 | 34 | // redraw the bullet at its new location. |
jford38 | 23:77049670cae6 | 35 | // If it has hit something (obstacle, tank, edge of the screen), |
jford38 | 26:317310d660b2 | 36 | // set the in_flight flag back to false, explode the nearby area, |
jford38 | 26:317310d660b2 | 37 | // and return one of the following codes. |
jford38 | 23:77049670cae6 | 38 | // |
jford38 | 23:77049670cae6 | 39 | // return codes: |
jford38 | 23:77049670cae6 | 40 | // BULLET_NO_COLLISION: no collision |
jford38 | 23:77049670cae6 | 41 | // BULLET_OFF_SCREEN: off the side of the screen |
jford38 | 23:77049670cae6 | 42 | // Otherwise, return the color you've hit in 16bpp format. |
jford38 | 27:bd55ab4d137c | 43 | return BULLET_NO_COLLISION; |
jford38 | 21:edfeb289b21f | 44 | } |