multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Revision:
17:32ae1f106002
Parent:
15:9d90f68e53da
Child:
18:32fce82690a1
--- a/gamestate.cpp	Fri Nov 13 23:02:56 2020 +0000
+++ b/gamestate.cpp	Sat Nov 14 02:37:13 2020 +0000
@@ -1,9 +1,11 @@
+
 #include "gamestate.h"
 
 GameState::GameState() {
     Coord playerOneLocation = {0, 0};
     Coord playerTwoLocation = {0, 0};
     Coord ballLocation = {0, 0};
+    this->localPlayer = 0; 
     this->p1_loc = playerOneLocation;
     this->p2_loc = playerTwoLocation; 
     this->ball_loc = ballLocation; 
@@ -22,8 +24,20 @@
     return this->ball_loc; 
 }
 
-void GameState::update(char *server_data) {
-    
+void GameState::update(MbedJSONValue *serverResponse) {
+    this->p1_loc.y = (*serverResponse)["playerOnePos"].get<int>(); 
+    this->p2_loc.y = (*serverResponse)["playerTwoPos"].get<int>(); 
+    int updated_ball_x = (*serverResponse)["ballPos"][0].get<int>(); 
+    int updated_ball_y = (*serverResponse)["ballPos"][1].get<int>(); 
+    this->ball_loc.x = updated_ball_x; 
+    this->ball_loc.y = updated_ball_y;
+    this->is_done = (bool)(*serverResponse)["isOver"].get<int>(); 
+}
+
+void GameState::print() {
+    //char to_string[256]; 
+//    sprintf(to_string, "Player1 Pos: [%i, %i], Player 2 Pos: [%i, %i], Ball Pos: [%i, %i], isOver: %i", this->p1_loc->x, this->p1_loc->y, this->p2_loc->x, this->p2_loc->y, this->ball_loc->x, this->ball_loc->y, this->is_done);
+//    printf("Game State: %s\n\r", to_string); 
 }
 
 bool GameState::done() {