The classic dueling tanks game for mbed.
Dependencies: 4DGL-uLCD-SE DRV2605 EthernetInterface Game_Synchronizer MMA8452 SDFileSystem SparkfunAnalogJoystick mbed-rtos mbed wave_player
Fork of 2035_Tanks_Shell by
Diff: Tank/tank.cpp
- Revision:
- 19:7aa3af04d6a8
- Parent:
- 14:36c306e26317
- Child:
- 20:6a58052b0140
--- a/Tank/tank.cpp Wed Oct 28 06:36:24 2015 +0000 +++ b/Tank/tank.cpp Wed Oct 28 08:40:55 2015 +0000 @@ -36,7 +36,12 @@ by = y+h+wheel_rad + (barrel_length+1)*sin(barrel_theta); } -void Tank::reposition(int new_x, int new_y, float new_theta) { +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; @@ -45,7 +50,7 @@ int maxx = max_x(); int maxy = max_y(); - x = new_x; y = new_y; barrel_theta = new_theta - (int)(new_theta/PI)*PI; + x = new_x; y = new_y; barrel_theta = (new_theta > PI) ? PI : new_theta; if(min_x() < 0 || max_x() > 128) { x = old_x; y = old_y; barrel_theta = old_theta;