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
Diff: two_player.h
- Revision:
- 1:0589ea36661b
- Parent:
- 0:899c85cd266f
- Child:
- 2:c358ad9aedc4
--- a/two_player.h Tue Oct 06 01:54:18 2015 +0000 +++ b/two_player.h Wed Oct 07 00:43:25 2015 +0000 @@ -28,7 +28,6 @@ BG_COLOR_CMD, CIRCLE_CMD, CLS_CMD, - BUTTONS_CMD }; @@ -40,6 +39,8 @@ void init() { buffer_idx = 0; + memset(buttons, 0, sizeof(buttons)); + sock = new UDPSocket(); endpoint = new Endpoint(); eth = new EthernetInterface(); @@ -50,15 +51,11 @@ eth->connect(); sock->init(); endpoint->set_address(PLAYER2_IP, SERVER_PORT); - //sock.sendTo(endpoint, buffer, sizeof(buffer)); - //int n = sock.receiveFrom(echo_server, in_buffer, sizeof(in_buffer)); break; case PLAYER2: // Server eth->init(PLAYER2_IP, "255.255.255.0", "0.0.0.0"); eth->connect(); sock->bind(SERVER_PORT); - //sock.sendTo(endpoint, buffer, sizeof(buffer)); - //int n = sock.receiveFrom(endpoint, buffer, sizeof(buffer)); break; } } @@ -84,19 +81,31 @@ void background_color(int color) { draw(BG_COLOR_CMD, color, 0,0,0,0,1); } - void set_button_state(int a, int b, int c, int d, int e) { draw(BUTTONS_CMD, a,b,c,d,e,5); } + void set_button_state(int a, int b, int c, int d, int e) { + buttons[0] = a; buttons[1] = b; buttons[2] = c; + buttons[3] = d; buttons[4] = e; + } + int* get_button_state() { + return buttons; + } void line(int sx, int sy, int ex, int ey, int color) { //draw(LINE_CMD, sx, sy, ex, ey, color); } void update() { + sock->set_blocking(true, 100); if(p1_p2 == PLAYER1) { sock->sendTo(*endpoint, (char*)buffer, (buffer_idx+1)*sizeof(buffer[0])); buffer_idx = 0; + + int n = sock->receiveFrom(*endpoint, (char*)buttons, sizeof(buttons)); }else if(p1_p2 == PLAYER2) { - int n = sock->receiveFrom(*endpoint, (char*)buffer, sizeof(buffer)/sizeof(buffer[0])); - buffer[n] = '\0'; + + int n = sock->receiveFrom(*endpoint, (char*)buffer, sizeof(buffer)); + buffer[n] = '\0'; + + sock->sendTo(*endpoint, (char*)buttons, sizeof(buttons)); } int idx = 0; @@ -117,16 +126,6 @@ pc.printf("Clear the screen!\n"); idx += 0; break; - case BUTTONS_CMD: - A_button = buffer[idx+0]; - B_button = buffer[idx+1]; - C_button = buffer[idx+2]; - D_button = buffer[idx+3]; - E_button = buffer[idx+4]; - pc.printf("Button Values: %d %d %d %d %d\n", - A_button, B_button, C_button, D_button, E_button); - idx += 5; - break; default: pc.printf("UNKNOWN CMD %d: This could get ugly!\n", cmd); idx += 0; @@ -155,11 +154,7 @@ uLCD_4DGL* LCD; - int A_button; - int B_button; - int C_button; - int D_button; - int E_button; + int buttons[5]; }; #endif \ No newline at end of file