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 ECE2035 Spring 2015 TA

Revision:
22:3c68eea5a609
Parent:
21:edfeb289b21f
Child:
23:77049670cae6
--- a/Tank/tank.cpp	Thu Oct 29 03:56:30 2015 +0000
+++ b/Tank/tank.cpp	Thu Oct 29 05:14:49 2015 +0000
@@ -18,63 +18,39 @@
     wheel_rad = 2.0;
     draw();
 }
+
+// Return the minimum x-coord of your tank's bounding box.
 int Tank::min_x(void) { 
-    int barrel_extent = (-barrel_length*cos(barrel_theta) > w/2.0) ? barrel_length*cos(barrel_theta) + w/2.0 : 0;
-    return x + barrel_extent;
-}
-    
-int Tank::min_y(void) { return y; }
-int Tank::max_x(void) { 
-    int barrel_extent = (barrel_length*cos(barrel_theta) > w/2.0) ? barrel_length*cos(barrel_theta) : w/2.0;
-    return x + w/2.0 + barrel_extent; 
+    return 0;
+}    
+
+// Return the minimum y-coord of your tank's bounding box.
+int Tank::min_y(void) {
+    return 0;
 }
 
-int Tank::max_y(void) { 
-    int barrel_extent = (sin(barrel_theta) > 0) ? barrel_length*sin(barrel_theta) : 0;
-    return y + h + wheel_rad + barrel_extent;
+// Return the maximum x-coord of your tank's bounding box.
+int Tank::max_x(void) { 
+    return 0;
 }
 
-void Tank::barrel_end(int& bx, int& by) {
-    bx = x + w/2.0 + (barrel_length+1)*cos(barrel_theta);
-    by = y+h+wheel_rad + (barrel_length+1)*sin(barrel_theta);
+// 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) {
-    
-    int new_x = x+dx;
-    int new_y = y+dy;
-    float new_theta = abs(barrel_theta+dtheta);
-    
-    float old_theta = barrel_theta;
-    int old_x = x;
-    int old_y = y;
-    int minx = min_x();
-    int miny = min_y();
-    int maxx = max_x();
-    int maxy = max_y();
-    
-    x = new_x; y = new_y; barrel_theta = (new_theta > PI) ? PI : new_theta;
+    // 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.
     
-    if(min_x() < 0 || max_x() > 128) { 
-        x = old_x; y = old_y; barrel_theta = old_theta;
-        draw();
-        return;
-    }
-    
-    int right_edge = sync.read_pixel(min_x()-1, (min_y()+max_y())/2.0);
-    int left_edge  = sync.read_pixel(max_x()+1, (min_y()+max_y())/2.0);
-    
-    if( ( right_edge != CONVERT_24_TO_16_BPP(SKY_COLOR) && new_x < old_x ) ||
-        ( left_edge  != CONVERT_24_TO_16_BPP(SKY_COLOR) && new_x > old_x ) ) {
-        x = old_x; y = old_y; barrel_theta = old_theta;
-        draw();
-        return;  
-    } 
-    
-    
-    sync.filled_rectangle(minx, miny, maxx, maxy, SKY_COLOR);
-    sync.line(old_x + w/2.0, old_y+h+wheel_rad, old_x + w/2.0 + 1 + barrel_length*cos(old_theta), old_y+h + barrel_length*sin(old_theta), SKY_COLOR);
-    draw();
+    // Do collision detection to prevent the tank from hitting things.
 }
 
 void Tank::draw() {