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:
Thu Oct 29 05:14:49 2015 +0000
Revision:
22:3c68eea5a609
Parent:
21:edfeb289b21f
Child:
23:77049670cae6
The Shell for students to fill in to play their tanks game.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jford38 14:36c306e26317 1 #include "tank.h"
jford38 21:edfeb289b21f 2 #include "misc.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 22:3c68eea5a609 43 // Return 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 22:3c68eea5a609 49 // Move the tank dx pixels in the x direction.
jford38 22:3c68eea5a609 50 // Move the tank dy pixels in the y direction.
jford38 22:3c68eea5a609 51 // Move the tank barrel by an angle dtheta. Don't allow it to go below parallel.
jford38 14:36c306e26317 52
jford38 22:3c68eea5a609 53 // Do collision detection to prevent the tank from hitting things.
jford38 14:36c306e26317 54 }
jford38 14:36c306e26317 55
jford38 14:36c306e26317 56 void Tank::draw() {
jford38 14:36c306e26317 57 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 58 sync.filled_rectangle(x, y+wheel_rad, x+w, y+h+wheel_rad, tank_color);
jford38 14:36c306e26317 59 sync.filled_circle(x+wheel_rad, y+wheel_rad, wheel_rad, BLACK);
jford38 14:36c306e26317 60 sync.filled_circle(x+w-wheel_rad, y+wheel_rad, wheel_rad, BLACK);
jford38 14:36c306e26317 61 }