multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Revision:
18:32fce82690a1
Parent:
17:32ae1f106002
Child:
19:58cc5465f647
--- a/main.cpp	Sat Nov 14 02:37:13 2020 +0000
+++ b/main.cpp	Sun Nov 15 21:55:35 2020 +0000
@@ -1,10 +1,11 @@
+
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "network.h"
 #include "gamestate.h"
 #include "graphics.h" 
 #include "DebouncedInterrupt.h"
-#include "MbedJSONValue.h" 
+#include "MbedJSONValue.h"
 
 #define DEBOUNCE 50
 
@@ -48,7 +49,8 @@
     
     MbedJSONValue serverResponse; 
     
-    char toSend[] = "{\"type\": \"connected\", \"data\": \"Ay whats good\"}"; 
+    char connectionRequest[] = "{\"type\": \"connected\"}";
+    char toSend[] = "{\"type\": \"move\", \"delta\": 5}"; 
     char readTo[256]; 
     
     gfx->renderLaunchScreen(); 
@@ -57,8 +59,9 @@
         if (menuPress) {
             GameState *gs = new GameState();
             
-            gfx->renderGameState(gs); 
-            
+            // request an open lobby from the server 
+            sock.sendTo(nist, connectionRequest, sizeof(connectionRequest) - 1); 
+                        
             // change ISRs to game controls 
             leftButton.attach(&pressLeftGame, IRQ_RISE, DEBOUNCE);
             rightButton.attach(&pressRightGame, IRQ_RISE, DEBOUNCE);
@@ -75,7 +78,11 @@
                 if (bytesRead > 0) {
                     printf("Reading: %i bytes, data: %s\n\r", bytesRead, readTo); 
                     parse(serverResponse, readTo); 
-                    gs->update(&serverResponse);
+                    
+                    printf("type is: %s\n\r", serverResponse["type"].get<std::string>().c_str());
+                    
+                    // TODO: check for connection ping back
+                    gs->update(&serverResponse, gfx);
                 } 
                 wait(.1);
             }