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 8:e6dd05393290, committed 2015-10-22
- Comitter:
- jford38
- Date:
- Thu Oct 22 09:52:53 2015 +0000
- Parent:
- 7:9506f2d84162
- Child:
- 9:ee330b1ba394
- Commit message:
- Done for tonight. Tired. Right now the student side can run independently in single-player mode. The student side LEDs also turn on when you push the buttons on either side. Started some timing stuff. Didn't get far.
Changed in this revision
--- a/Game_Synchronizer/game_synchronizer.cpp Thu Oct 22 09:14:47 2015 +0000 +++ b/Game_Synchronizer/game_synchronizer.cpp Thu Oct 22 09:52:53 2015 +0000 @@ -2,19 +2,28 @@ extern Serial pc; -Game_Synchronizer::Game_Synchronizer(PinName tx, PinName rx, PinName rst, bool player) { - p1_p2 = player; - LCD = new uLCD_4DGL (tx, rx, rst); +Game_Synchronizer::Game_Synchronizer(bool player) { + p1_p2 = player; } -void Game_Synchronizer::init(int mode) { +void Game_Synchronizer::init(uLCD_4DGL* lcd, int mode) { + + // Save a pointer to the local lcd. + LCD = lcd; + // Save the play mode. (Multi-player or Single-player) play_mode = mode; + + // Initialize the idx into the send_buffer to zero. buffer_idx = 0; + + // buttons is the array containing player two's button (and accelerometer) values. + // Initialize it to zero. memset(buttons, 0, sizeof(buttons)); switch (p1_p2) { - case PLAYER1: // Client - + case PLAYER1: // If I am p1... + + // If play_mode is set to multi-player, establish the ethernet connection. if(MULTI_PLAYER == play_mode) { eth = new EthernetInterface(); eth->init(PLAYER1_IP, "255.255.255.0", "0.0.0.0"); @@ -26,7 +35,10 @@ } } break; - case PLAYER2: // Server + case PLAYER2: // If I am p2... + + // If I am player 2, play_mode doesn't matter. I have to assume it's + // set to multi-player and try to connect to p1. eth = new EthernetInterface(); eth->init(PLAYER2_IP, "255.255.255.0", "0.0.0.0"); eth->connect(); @@ -55,8 +67,10 @@ void Game_Synchronizer::_draw(int CMD, int a, int b, int c, int d, int e, int f, int g, char nArgs){ - // Deal with overflows - // if(buffer_idx + nArgs > 256) {//flush();} + // I haven't had time to deal with overflows of the buffer. If you are pushing tons of draw calls into the buffer, + // you could overrun it. This will cause bad things. (At a minimum, your stuff won't be drawn.) + // If you have this problem, try calling update in the middle of your draw calls to flush the buffer. + // Alternatively, you can increase ETH_PACKET_SIZE. if(nArgs > 7) { //pc.printf("Error in call to _draw(): nArgs > 7 not allowed!\n"); @@ -88,7 +102,7 @@ void Game_Synchronizer::pixel(int a, int b, int col) { draw(PIX_CMD, a, b, col); } void Game_Synchronizer::cls(void) { draw(CLS_CMD); } -/*void BLIT(int x1, int y1, int x2, int y2, int *colors) { +/*void Game_Synchronizer::BLIT(int x1, int y1, int x2, int y2, int *colors) { int size = abs((x1-x2)*(y1-y2)); // pad to a multiple of 4 and memset buffer... // I'll get to it later.
--- a/Game_Synchronizer/game_synchronizer.h Thu Oct 22 09:14:47 2015 +0000 +++ b/Game_Synchronizer/game_synchronizer.h Thu Oct 22 09:52:53 2015 +0000 @@ -37,9 +37,9 @@ PIX_CMD }; - Game_Synchronizer(PinName tx, PinName rx, PinName rst, bool player); + Game_Synchronizer(bool player); - void init(int); + void init(uLCD_4DGL*, int); // Yes, this sucks. If you're smart, find a good way to do variable args and show me! // Look into template metaprogramming!
--- 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"); }
--- a/mbed-rtos.lib Thu Oct 22 09:14:47 2015 +0000 +++ b/mbed-rtos.lib Thu Oct 22 09:52:53 2015 +0000 @@ -1,1 +1,1 @@ -http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#d7bd06319118 +http://developer.mbed.org/users/mbed_official/code/mbed-rtos/#12552ef4e980