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
Revision 18:18dfc9fb33b5, committed 2015-10-28
- Comitter:
- jford38
- Date:
- Wed Oct 28 06:36:24 2015 +0000
- Parent:
- 17:7bc7127782e4
- Child:
- 19:7aa3af04d6a8
- Commit message:
- Most things working! Multi-player and single-player working with accelerometer x controlling the tanks and y controlling the gun. Uses the down button to fire.
Changed in this revision
--- a/Bullet/bullet.cpp Wed Oct 28 04:30:22 2015 +0000 +++ b/Bullet/bullet.cpp Wed Oct 28 06:36:24 2015 +0000 @@ -43,8 +43,13 @@ in_flight = false; if(col == CONVERT_24_TO_16_BPP(TANK_BLUE)) { - return 1; + return TANK_BLUE; } + + if( col == CONVERT_24_TO_16_BPP(TANK_RED)) { + return TANK_RED; + } + return 0; } sync.pixel(x, y, SKY_COLOR);
--- a/Game_Synchronizer.lib Wed Oct 28 04:30:22 2015 +0000 +++ b/Game_Synchronizer.lib Wed Oct 28 06:36:24 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/teams/ECE2035-Spring-2015-TA/code/Game_Synchronizer/#3804888303c0 +http://developer.mbed.org/teams/ECE2035-Spring-2015-TA/code/Game_Synchronizer/#a44cfc9dfe58
--- a/globals/globals.h Wed Oct 28 04:30:22 2015 +0000 +++ b/globals/globals.h Wed Oct 28 06:36:24 2015 +0000 @@ -5,6 +5,19 @@ #define GND_COLOR 0x66CD00 #define TANK_RED 0xCD0000 #define TANK_BLUE 0x000080 + +#define U_BUTTON 0 +#define R_BUTTON 1 +#define D_BUTTON 2 +#define L_BUTTON 3 + +#define TURN_P1 0 +#define TURN_P2 1 + + + +#define ACC_THRESHOLD 0.25 + #define PI 3.1415926535797 int CONVERT_24_TO_16_BPP(int col_24);
--- a/main.cpp Wed Oct 28 04:30:22 2015 +0000 +++ b/main.cpp Wed Oct 28 06:36:24 2015 +0000 @@ -31,7 +31,7 @@ Game_Synchronizer sync(PLAYER1); // Game_Synchronizer (PLAYER) Timer frame_timer; // Timer - +int winner = -1; // Ask the user whether to run the game in Single- or Multi-Player mode. // Note that this function uses uLCD instead of sync because it is only @@ -40,6 +40,7 @@ // the buttons directly e.g. if( !pb_r ) { do something; }. int game_menu(void) { + uLCD.baudrate(BAUD_3000000); uLCD.locate(0,1); uLCD.puts("Select Mode:"); uLCD.locate(0,3); @@ -113,8 +114,8 @@ game_init(); - Tank t1(4, 21, 12, 8, TANK_RED); - Tank t2(111, 21, 12, 8, TANK_BLUE); + Tank t1(4, 21, 12, 8, TANK_RED); // (min_x, min_y, width, height, color) + Tank t2(111, 21, 12, 8, TANK_BLUE); // (min_x, min_y, width, height, color) Bullet b1(&t1); Bullet b2(&t2); @@ -136,42 +137,45 @@ float ax1 = (float) p1_inputs[4] / 65536.0; float ay1 = (float) p1_inputs[5] / 65536.0; float az1 = (float) p1_inputs[6] / 65536.0; - pc.printf("P1 X: %f\tY: %f\tZ: %f\n", ax1, ay1, az1); + //pc.printf("P1 X: %f\tY: %f\tZ: %f\n", ax1, ay1, az1); float ax2 = (float) p2_inputs[4] / 65536.0; float ay2 = (float) p2_inputs[5] / 65536.0; float az2 = (float) p2_inputs[6] / 65536.0; - pc.printf("P2 X: %f\tY: %f\tZ: %f\n", ax2, ay2, az2); + //pc.printf("P2 X: %f\tY: %f\tZ: %f\n", ax2, ay2, az2); - /* - 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_inputs[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(ax1 > ACC_THRESHOLD) { t1.reposition(t1.x-1, t1.y, t1.barrel_theta); } + if(ax1 < -ACC_THRESHOLD) { t1.reposition(t1.x+1, t1.y, t1.barrel_theta); } + if(ax2 > ACC_THRESHOLD) { t2.reposition(t2.x-1, t2.y, t2.barrel_theta); } + if(ax2 < -ACC_THRESHOLD) { 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); + if(ay1 > ACC_THRESHOLD) { t1.reposition(t1.x, t1.y, t1.barrel_theta+PI/30.0); } + if(ay1 < -ACC_THRESHOLD) { t1.reposition(t1.x, t1.y, t1.barrel_theta-PI/30.0); } + + if(ay2 > ACC_THRESHOLD) { t2.reposition(t2.x, t2.y, t2.barrel_theta+PI/30.0); } + if(ay2 < -ACC_THRESHOLD) { t2.reposition(t2.x, t2.y, t2.barrel_theta-PI/30.0); } - if(!pb_d) { b1.shoot(); } - if(p2_buttons[2]) { b2.shoot(); } + if(p1_inputs[D_BUTTON]) { b1.shoot(); } + if(p2_inputs[D_BUTTON]) { b2.shoot(); } - int retval = b1.time_step(frame_timer.read()); - if(retval) { + float time = frame_timer.read(); + int retval = b1.time_step(time); + if(retval == t2.tank_color) { sync.update(); pc.printf("P1 wins!"); + winner = PLAYER1; break; } - retval = b2.time_step(frame_timer.read()); - if(retval) { + retval = b2.time_step(time); + if(retval == t1.tank_color) { sync.update(); pc.printf("P2 wins!"); + winner = PLAYER2; break; } - */ - //frame_timer.reset(); + frame_timer.reset(); sync.update(); } @@ -180,8 +184,14 @@ while(1) { sync.cls(); sync.locate(i, 9); - char msg[] = "GAME OVER!"; - sync.puts(msg, sizeof(msg)); + if(winner == PLAYER1) { + char msg[] = "P1 Wins!"; + sync.puts(msg, sizeof(msg)); + } else if(winner == PLAYER2) { + char msg[] = "P2 Wins!"; + sync.puts(msg, sizeof(msg)); + } + sync.update(); i = (i+1)%10; wait(0.1);