Game for 4180 Lab4
Dependencies: 4DGL-uLCD-SE 4180_lab4_tank_war_game Game_Synchronizer MMA8452 SDFileSystem mbed-rtos mbed wave_player
Dependents: 4180_lab4_tank_war_game
Bullet/bullet.h@0:ffed9a3bc797, 2017-03-13 (annotated)
- Committer:
- ychen644
- Date:
- Mon Mar 13 21:23:17 2017 +0000
- Revision:
- 0:ffed9a3bc797
Uploading 4180 Lab4 game to Notebook wiki
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ychen644 | 0:ffed9a3bc797 | 1 | #ifndef BULLET_H__ |
ychen644 | 0:ffed9a3bc797 | 2 | #define BULLET_H__ |
ychen644 | 0:ffed9a3bc797 | 3 | |
ychen644 | 0:ffed9a3bc797 | 4 | #include "tank.h" |
ychen644 | 0:ffed9a3bc797 | 5 | |
ychen644 | 0:ffed9a3bc797 | 6 | #define BULLET_NO_COLLISION -1 |
ychen644 | 0:ffed9a3bc797 | 7 | #define BULLET_OFF_SCREEN -2 |
ychen644 | 0:ffed9a3bc797 | 8 | |
ychen644 | 0:ffed9a3bc797 | 9 | class Bullet{ |
ychen644 | 0:ffed9a3bc797 | 10 | public: |
ychen644 | 0:ffed9a3bc797 | 11 | // sky color |
ychen644 | 0:ffed9a3bc797 | 12 | int SKY_COLOR; |
ychen644 | 0:ffed9a3bc797 | 13 | |
ychen644 | 0:ffed9a3bc797 | 14 | // (x0, y0) is the position of the bullet at the start of its trajectory. |
ychen644 | 0:ffed9a3bc797 | 15 | int x0, y0; |
ychen644 | 0:ffed9a3bc797 | 16 | |
ychen644 | 0:ffed9a3bc797 | 17 | // The components of the bullet's initial velocity. |
ychen644 | 0:ffed9a3bc797 | 18 | float vx0, vy0; |
ychen644 | 0:ffed9a3bc797 | 19 | |
ychen644 | 0:ffed9a3bc797 | 20 | // The current position of the bullet. |
ychen644 | 0:ffed9a3bc797 | 21 | int x, y; |
ychen644 | 0:ffed9a3bc797 | 22 | |
ychen644 | 0:ffed9a3bc797 | 23 | // currernt velocity |
ychen644 | 0:ffed9a3bc797 | 24 | float vx, vy; |
ychen644 | 0:ffed9a3bc797 | 25 | int bounce; |
ychen644 | 0:ffed9a3bc797 | 26 | |
ychen644 | 0:ffed9a3bc797 | 27 | // power up |
ychen644 | 0:ffed9a3bc797 | 28 | int powerups; |
ychen644 | 0:ffed9a3bc797 | 29 | int power; |
ychen644 | 0:ffed9a3bc797 | 30 | |
ychen644 | 0:ffed9a3bc797 | 31 | // How fast is the bullet? |
ychen644 | 0:ffed9a3bc797 | 32 | int speed; |
ychen644 | 0:ffed9a3bc797 | 33 | |
ychen644 | 0:ffed9a3bc797 | 34 | // Keep track of the time since the bullet was shot. |
ychen644 | 0:ffed9a3bc797 | 35 | float time; |
ychen644 | 0:ffed9a3bc797 | 36 | |
ychen644 | 0:ffed9a3bc797 | 37 | // Keep track of whether the bullet is currently in flight. |
ychen644 | 0:ffed9a3bc797 | 38 | // If it is in_flight, update its position. Otherwise, ignore it. |
ychen644 | 0:ffed9a3bc797 | 39 | // Set in_flight when the bullet is shot. |
ychen644 | 0:ffed9a3bc797 | 40 | // Reset in_flight when the bullet hits something. |
ychen644 | 0:ffed9a3bc797 | 41 | bool in_flight; |
ychen644 | 0:ffed9a3bc797 | 42 | |
ychen644 | 0:ffed9a3bc797 | 43 | // Keep a pointer to the tank that shot this bullet. You'll need |
ychen644 | 0:ffed9a3bc797 | 44 | // it to access information about the tank. |
ychen644 | 0:ffed9a3bc797 | 45 | Tank* tank; |
ychen644 | 0:ffed9a3bc797 | 46 | |
ychen644 | 0:ffed9a3bc797 | 47 | // Create a bullet! |
ychen644 | 0:ffed9a3bc797 | 48 | Bullet(Tank* t); |
ychen644 | 0:ffed9a3bc797 | 49 | |
ychen644 | 0:ffed9a3bc797 | 50 | // change sky |
ychen644 | 0:ffed9a3bc797 | 51 | void changeSky(int SKY_COLOR2); |
ychen644 | 0:ffed9a3bc797 | 52 | |
ychen644 | 0:ffed9a3bc797 | 53 | // powerup |
ychen644 | 0:ffed9a3bc797 | 54 | void powerUp(void); |
ychen644 | 0:ffed9a3bc797 | 55 | |
ychen644 | 0:ffed9a3bc797 | 56 | // Shoot the bullet! |
ychen644 | 0:ffed9a3bc797 | 57 | void shoot(void); |
ychen644 | 0:ffed9a3bc797 | 58 | |
ychen644 | 0:ffed9a3bc797 | 59 | // given a time delta, calculate the new (x, y) coords of the bullet. |
ychen644 | 0:ffed9a3bc797 | 60 | void update_position(float dt); |
ychen644 | 0:ffed9a3bc797 | 61 | |
ychen644 | 0:ffed9a3bc797 | 62 | // Once per frame, plug in the time since the last frame. |
ychen644 | 0:ffed9a3bc797 | 63 | // Clear the old bullet and redraw it in the new place. |
ychen644 | 0:ffed9a3bc797 | 64 | // Do collision detection here. Return a code describing what has |
ychen644 | 0:ffed9a3bc797 | 65 | // (or hasn't) been hit. |
ychen644 | 0:ffed9a3bc797 | 66 | int time_step(float dt); |
ychen644 | 0:ffed9a3bc797 | 67 | }; |
ychen644 | 0:ffed9a3bc797 | 68 | |
ychen644 | 0:ffed9a3bc797 | 69 | #endif |