Revenge of the Mouse
Dependencies: 4DGL-uLCD-SE EthernetInterface Game_Synchronizer LCD_fonts MMA8452 SDFileSystem mbed-rtos mbed wave_player
Fork of 2035_Tanks_Shell by
Tank/tank.cpp
- Committer:
- jford38
- Date:
- 2015-10-29
- Revision:
- 22:3c68eea5a609
- Parent:
- 21:edfeb289b21f
- Child:
- 23:77049670cae6
File content as of revision 22:3c68eea5a609:
#include "tank.h" #include "misc.h" #include "math.h" #include "game_synchronizer.h" extern Game_Synchronizer sync; // sx is the x-coord of the bottom left corner of the tank // sy is the y-coord of the same corner // width is the width of the tank // height is the height of the tank Tank::Tank(int sx, int sy, int width, int height, int color) { x = sx; y = sy; w = width; h = height; tank_color = color; barrel_theta = PI/4.0; barrel_length = w; wheel_rad = 2.0; draw(); } // Return the minimum x-coord of your tank's bounding box. int Tank::min_x(void) { return 0; } // Return the minimum y-coord of your tank's bounding box. int Tank::min_y(void) { return 0; } // Return the maximum x-coord of your tank's bounding box. int Tank::max_x(void) { return 0; } // Return the maximum y-coord of your tank's bounding box. int Tank::max_y(void) { return 1; } void Tank::barrel_end(int* bx, int* by) { // Return the x and y coords of the end of the barrel. // *bx = ??? // *by = ??? } void Tank::reposition(int dx, int dy, float dtheta) { // Move the tank dx pixels in the x direction. // Move the tank dy pixels in the y direction. // Move the tank barrel by an angle dtheta. Don't allow it to go below parallel. // Do collision detection to prevent the tank from hitting things. } void Tank::draw() { 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); sync.filled_rectangle(x, y+wheel_rad, x+w, y+h+wheel_rad, tank_color); sync.filled_circle(x+wheel_rad, y+wheel_rad, wheel_rad, BLACK); sync.filled_circle(x+w-wheel_rad, y+wheel_rad, wheel_rad, BLACK); }