For Nikhil

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

Fork of 2035_Tanks_Shell by ECE2035 Spring 2015 TA

Committer:
jford38
Date:
Fri Oct 30 11:08:31 2015 +0000
Revision:
27:bd55ab4d137c
Parent:
25:b3c075a2f2c7
Added a folder for sound. Clarified the role of globals.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jford38 14:36c306e26317 1 #include "tank.h"
jford38 27:bd55ab4d137c 2 #include "globals.h"
jford38 14:36c306e26317 3 #include "math.h"
jford38 14:36c306e26317 4 #include "game_synchronizer.h"
jford38 14:36c306e26317 5
jford38 14:36c306e26317 6 extern Game_Synchronizer sync;
jford38 14:36c306e26317 7
jford38 20:6a58052b0140 8 // sx is the x-coord of the bottom left corner of the tank
jford38 20:6a58052b0140 9 // sy is the y-coord of the same corner
jford38 20:6a58052b0140 10 // width is the width of the tank
jford38 20:6a58052b0140 11 // height is the height of the tank
jford38 14:36c306e26317 12 Tank::Tank(int sx, int sy, int width, int height, int color) {
jford38 14:36c306e26317 13 x = sx; y = sy;
jford38 14:36c306e26317 14 w = width; h = height;
jford38 14:36c306e26317 15 tank_color = color;
jford38 14:36c306e26317 16 barrel_theta = PI/4.0;
jford38 14:36c306e26317 17 barrel_length = w;
jford38 14:36c306e26317 18 wheel_rad = 2.0;
jford38 14:36c306e26317 19 draw();
jford38 14:36c306e26317 20 }
jford38 22:3c68eea5a609 21
jford38 22:3c68eea5a609 22 // Return the minimum x-coord of your tank's bounding box.
jford38 14:36c306e26317 23 int Tank::min_x(void) {
jford38 22:3c68eea5a609 24 return 0;
jford38 22:3c68eea5a609 25 }
jford38 22:3c68eea5a609 26
jford38 22:3c68eea5a609 27 // Return the minimum y-coord of your tank's bounding box.
jford38 22:3c68eea5a609 28 int Tank::min_y(void) {
jford38 22:3c68eea5a609 29 return 0;
jford38 14:36c306e26317 30 }
jford38 14:36c306e26317 31
jford38 22:3c68eea5a609 32 // Return the maximum x-coord of your tank's bounding box.
jford38 22:3c68eea5a609 33 int Tank::max_x(void) {
jford38 22:3c68eea5a609 34 return 0;
jford38 14:36c306e26317 35 }
jford38 14:36c306e26317 36
jford38 22:3c68eea5a609 37 // Return the maximum y-coord of your tank's bounding box.
jford38 22:3c68eea5a609 38 int Tank::max_y(void) {
jford38 22:3c68eea5a609 39 return 1;
jford38 22:3c68eea5a609 40 }
jford38 22:3c68eea5a609 41
jford38 22:3c68eea5a609 42 void Tank::barrel_end(int* bx, int* by) {
jford38 25:b3c075a2f2c7 43 // Set the x and y coords of the end of the barrel.
jford38 22:3c68eea5a609 44 // *bx = ???
jford38 22:3c68eea5a609 45 // *by = ???
jford38 14:36c306e26317 46 }
jford38 14:36c306e26317 47
jford38 19:7aa3af04d6a8 48 void Tank::reposition(int dx, int dy, float dtheta) {
jford38 23:77049670cae6 49 // Blank out the old tank position, and
jford38 23:77049670cae6 50 // Move the tank dx pixels in the x direction.
jford38 23:77049670cae6 51 // Move the tank dy pixels in the y direction.
jford38 23:77049670cae6 52 // Move the tank barrel by an angle dtheta. Don't allow it to go below parallel.
jford38 14:36c306e26317 53
jford38 23:77049670cae6 54 // Do collision detection to prevent the tank from hitting things.
jford38 23:77049670cae6 55 // (obstacles, side of the screen, other tanks, etc.)
jford38 14:36c306e26317 56 }
jford38 14:36c306e26317 57
jford38 23:77049670cae6 58
jford38 23:77049670cae6 59 // Example tank draw function. We expect you to get creative on this one!
jford38 14:36c306e26317 60 void Tank::draw() {
jford38 14:36c306e26317 61 sync.line(x + w/2.0, y+h+wheel_rad, x + w/2.0 + barrel_length*cos(barrel_theta), y+h+wheel_rad + barrel_length*sin(barrel_theta), BLACK);
jford38 14:36c306e26317 62 sync.filled_rectangle(x, y+wheel_rad, x+w, y+h+wheel_rad, tank_color);
jford38 14:36c306e26317 63 sync.filled_circle(x+wheel_rad, y+wheel_rad, wheel_rad, BLACK);
jford38 14:36c306e26317 64 sync.filled_circle(x+w-wheel_rad, y+wheel_rad, wheel_rad, BLACK);
jford38 14:36c306e26317 65 }