Jason McNeely / Mbed 2 deprecated DuelingTanks

Dependencies:   4DGL-uLCD-SE DRV2605 EthernetInterface Game_Synchronizer MMA8452 SDFileSystem SparkfunAnalogJoystick mbed-rtos mbed wave_player

Fork of 2035_Tanks_Shell by ECE2035 Spring 2015 TA

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers bullet.h Source File

bullet.h

00001 #ifndef BULLET_H__
00002 #define BULLET_H__
00003 
00004 #include "tank.h"
00005 
00006 #define BULLET_NO_COLLISION -1
00007 #define BULLET_OFF_SCREEN   -2
00008 
00009 class Bullet{
00010     public:
00011         
00012         // (x0, y0) is the position of the bullet at the start of its trajectory.
00013         int x0, y0;
00014         int vy;
00015         // The components of the bullet's initial velocity.
00016         float vx0, vy0;
00017         
00018         // The current position of the bullet.
00019         int x, y;
00020         
00021         // How fast is the bullet?
00022         int speed;
00023         
00024         // Keep track of the time since the bullet was shot.
00025         float time;
00026         
00027         // Keep track of whether the bullet is currently in flight.
00028         // If it is in_flight, update its position. Otherwise, ignore it.
00029         // Set in_flight when the bullet is shot.
00030         // Reset in_flight when the bullet hits something.
00031         bool in_flight;
00032         
00033         // Keep a pointer to the tank that shot this bullet. You'll need
00034         // it to access information about the tank.
00035         Tank* tank;
00036         
00037         // Create a bullet!
00038         Bullet(Tank* t);
00039         
00040         // Shoot the bullet!
00041         void shoot(void);
00042         
00043         // given a time delta, calculate the new (x, y) coords of the bullet.
00044         void update_position(float dt);
00045         
00046         // Once per frame, plug in the time since the last frame.
00047         // Clear the old bullet and redraw it in the new place.
00048         // Do collision detection here. Return a code describing what has
00049         // (or hasn't) been hit.
00050         int time_step(float dt);    
00051 };
00052 
00053 #endif