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
Diff: Bullet/bullet.h
- Revision:
- 21:edfeb289b21f
- Parent:
- 17:7bc7127782e4
- Child:
- 28:8dbb85f35be6
--- a/Bullet/bullet.h Thu Oct 29 02:21:11 2015 +0000 +++ b/Bullet/bullet.h Thu Oct 29 03:56:30 2015 +0000 @@ -3,22 +3,50 @@ #include "tank.h" +#define BULLET_NO_COLLISION -1 +#define BULLET_OFF_SCREEN -2 + class Bullet{ public: - int x0; - int y0; - float vx0; - float vy0; - int x; - int y; + + // (x0, y0) is the position of the bullet at the start of its trajectory. + int x0, y0; + + // The components of the bullet's initial velocity. + float vx0, vy0; + + // The current position of the bullet. + int x, y; + + // How fast is the bullet? int speed; + + // Keep track of the time since the bullet was shot. float time; + + // Keep track of whether the bullet is currently in flight. + // If it is in_flight, update its position. Otherwise, ignore it. + // Set in_flight when the bullet is shot. + // Reset in_flight when the bullet hits something. bool in_flight; + // Keep a pointer to the tank that shot this bullet. You'll need + // it to access information about the tank. Tank* tank; + // Create a bullet! Bullet(Tank* t); + + // Shoot the bullet! void shoot(void); + + // given a time delta, calculate the new (x, y) coords of the bullet. + void update_position(float dt); + + // Once per frame, plug in the time since the last frame. + // Clear the old bullet and redraw it in the new place. + // Do collision detection here. Return a code describing what has + // (or hasn't) been hit. int time_step(float dt); };