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: main.cpp
- Revision:
- 9:ee330b1ba394
- Parent:
- 8:e6dd05393290
- Child:
- 10:5da9b27e050e
--- a/main.cpp Thu Oct 22 09:52:53 2015 +0000 +++ b/main.cpp Thu Oct 22 21:34:00 2015 +0000 @@ -23,11 +23,22 @@ int game_menu(void) { // Figure out what mode the game will be run in. + + uLCD.locate(0,1); + uLCD.puts("Select Mode:"); + uLCD.locate(0,3); + uLCD.puts(" Single-Player:"); + uLCD.locate(0,4); + uLCD.puts(" Left Button"); + uLCD.locate(0,6); + uLCD.puts(" Multi-Player:"); + uLCD.locate(0,7); + uLCD.puts(" Right Button"); // Right button -> Multiplayer // Left button -> Single player while(1) { - if(!pb_r) { wait(1); return MULTI_PLAYER; } // Delay to allow user time to stop pushing the button before the game starts! - if(!pb_l) { wait(1); return SINGLE_PLAYER; } // return whichever game mode the user selected. + if(!pb_r) { return MULTI_PLAYER; } + if(!pb_l) { return SINGLE_PLAYER; } } } @@ -43,44 +54,42 @@ pc.printf("\033[2J\033[0;0H"); // Clear the terminal screen. pc.printf("I'm alive! Player 1\n"); // Let us know you made it this far. int mode = game_menu(); - sync.init(&uLCD, mode); // Connect to the other player. + sync.init(&uLCD, mode); // Connect to the other player. + //sync.cls(); pc.printf("Initialized...\n"); // Let us know you finished initializing. } int main (void) { int* p2_buttons; - long int tick, pre_tick; - srand (time(NULL)); - Timer timer; - - game_init(); - timer.start(); - tick = timer.read_ms(); - pre_tick = tick; - + float theta = 0; + bool first = true; - float theta = 0; while(1) { - sync.line(64,64,64+50*cos(theta),64+50*sin(theta), BLACK); + char howdy[] = "Howdy!"; + if(first) { + sync.background_color(BLUE); + sync.cls(); + + sync.locate(5,0); + sync.puts(howdy, sizeof(howdy)); + first = false; + } + sync.line(64,64,64+50*cos(theta),64+50*sin(theta), BLUE); theta += 0.05; sync.line(64,64,64+50*cos(theta),64+50*sin(theta), RED); sync.circle(10,10,100, GREEN); - sync.filled_circle(4,4,10, 0xAB); - sync.triangle(10,10, 20,20, 20,40, 0xAB); + sync.filled_circle(4,4,10, RED); + sync.triangle(10,10, 20,20, 20,40, RED); sync.rectangle(100,100, 90,90, GREEN); - sync.filled_rectangle(100,100, 110,110, 0xAB); + sync.filled_rectangle(100,100, 110,110, RED); sync.pixel(40, 40, WHITE); + sync.update(); - tick = timer.read_ms(); // Read current time - if(tick-pre_tick < 100){;} - pre_tick = tick; - - sync.update(); p2_buttons = sync.get_button_state(); led1 = p2_buttons[0] ^ !pb_u;