For Nikhil
Dependencies: 4DGL-uLCD-SE EthernetInterface Game_Synchronizer MMA8452 SDFileSystem mbed-rtos mbed wave_player
Fork of 2035_Tanks_Shell by
Diff: main.cpp
- Revision:
- 8:e6dd05393290
- Parent:
- 7:9506f2d84162
- Child:
- 9:ee330b1ba394
--- a/main.cpp Thu Oct 22 09:14:47 2015 +0000 +++ b/main.cpp Thu Oct 22 09:52:53 2015 +0000 @@ -13,7 +13,8 @@ DigitalIn pb_u(p22); // up button DigitalIn pb_d(p23); // down button -Game_Synchronizer sync(p9,p10,p11, PLAYER1); // (tx, rx, rst, player mode) +uLCD_4DGL uLCD(p9,p10,p11); // LCD (serial tx, serial rx, reset pin;) +Game_Synchronizer sync(PLAYER1); // (tx, rx, rst, player mode) // For debug only. Don't use in production code. It will slow your game down a lot. Serial pc(USBTX, USBRX); @@ -42,14 +43,24 @@ 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(mode); // Connect to the other player. + sync.init(&uLCD, mode); // Connect to the other player. pc.printf("Initialized...\n"); // Let us know you finished initializing. } int main (void) { - int* buttons; + int* p2_buttons; + + long int tick, pre_tick; + srand (time(NULL)); + Timer timer; + + + game_init(); + + timer.start(); + tick = timer.read_ms(); + pre_tick = tick; - game_init(); float theta = 0; while(1) { @@ -64,13 +75,19 @@ sync.filled_rectangle(100,100, 110,110, 0xAB); sync.pixel(40, 40, WHITE); - sync.update(); - buttons = sync.get_button_state(); + + tick = timer.read_ms(); // Read current time + if(tick-pre_tick < 100){;} + pre_tick = tick; - led1 = buttons[0]; - led2 = buttons[1]; - led3 = buttons[2]; - led4 = buttons[3]; + sync.update(); + p2_buttons = sync.get_button_state(); + + led1 = p2_buttons[0] ^ !pb_u; + led2 = p2_buttons[1] ^ !pb_r; + led3 = p2_buttons[2] ^ !pb_d; + led4 = p2_buttons[3] ^ !pb_l; + //pc.printf("Button State: %x %x %x %x %x\n", buttons[0], buttons[1], buttons[2], buttons[3], buttons[4]); //pc.printf("\033[2J\033[0;0H"); }