![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Shell code for the Tanks game
Dependencies: 4DGL-uLCD-SE EthernetInterface Game_Synchronizer MMA8452 SDFileSystem mbed-rtos mbed wave_player
Diff: main.cpp
- Revision:
- 11:f455e907baba
- Parent:
- 10:5da9b27e050e
- Child:
- 12:088a8203a9bb
--- a/main.cpp Fri Oct 23 03:33:35 2015 +0000 +++ b/main.cpp Fri Oct 23 04:18:28 2015 +0000 @@ -80,12 +80,12 @@ } int min_x(void) { return x; } int min_y(void) { return y; } - int max_x(void) { return x + w; } + int max_x(void) { return x + w + ceil(barrel_length*cos(barrel_theta)); } int max_y(void) { return y + h + wheel_rad + ceil(barrel_length*sin(barrel_theta)); } - void reposition(int new_x, int new_y, int new_theta) { + void reposition(int new_x, int new_y, float new_theta) { sync.filled_rectangle(min_x(), min_y(), max_x(), max_y(), SKY_COLOR); - sync.line(x + w/2.0, y+h+wheel_rad, x + w/2.0 + barrel_length*cos(barrel_theta), y+h + barrel_length*sin(barrel_theta), SKY_COLOR); + sync.line(x + w/2.0, y+h+wheel_rad, x + w/2.0 + 1 + barrel_length*cos(barrel_theta), y+h + barrel_length*sin(barrel_theta), SKY_COLOR); x = new_x; y = new_y; barrel_theta = new_theta; draw(); } @@ -123,7 +123,7 @@ Tank t2(111, 20, 12, 8, TANK_BLUE); while(1) { - sync.line(0,0, 5,5, BLACK); + sync.line(0,0, 5,5, BLACK); // Update pukes if you try to send nothing :P sync.update(); p2_buttons = sync.get_button_state(); @@ -132,5 +132,17 @@ led2 = p2_buttons[1] ^ !pb_r; led3 = p2_buttons[2] ^ !pb_d; led4 = p2_buttons[3] ^ !pb_l; + + if(!pb_l) t1.reposition(t1.x-1, t1.y, t1.barrel_theta); + if(!pb_r) t1.reposition(t1.x+1, t1.y, t1.barrel_theta); + if(p2_buttons[3]) t2.reposition(t2.x-1, t2.y, t2.barrel_theta); + if(p2_buttons[1]) t2.reposition(t2.x+1, t2.y, t2.barrel_theta); + + if(!pb_d) t1.reposition(t1.x, t1.y, t1.barrel_theta+PI/30.0); + if(!pb_u) t1.reposition(t1.x, t1.y, t1.barrel_theta-PI/30.0); + if(p2_buttons[0]) t2.reposition(t2.x, t2.y, t2.barrel_theta+PI/30.0); + if(p2_buttons[2]) t2.reposition(t2.x, t2.y, t2.barrel_theta-PI/30.0); + + } } \ No newline at end of file