multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Diff: gamestate.cpp
- Revision:
- 23:c38680c32552
- Parent:
- 22:1c49e1fae846
- Child:
- 25:4a965eccb922
diff -r 1c49e1fae846 -r c38680c32552 gamestate.cpp --- a/gamestate.cpp Mon Nov 16 02:04:23 2020 +0000 +++ b/gamestate.cpp Mon Nov 16 03:01:50 2020 +0000 @@ -6,7 +6,6 @@ Coord playerTwoLocation = {0, 0}; Coord ballLocation = {0, 0}; this->localPlayerNum = 0; - this->lobbyHash = ""; this->p1_loc = playerOneLocation; this->p2_loc = playerTwoLocation; this->ball_loc = ballLocation; @@ -30,13 +29,17 @@ if (typeResponse == "connected") { gfx->renderWaitingRoom(); } else if (typeResponse == "gameState") { - gfx->removeGameState(this); + if (!has_started) { + has_started = 1; + gfx->reset(); + } + gfx->eraseGameState(this); MbedJSONValue &serverGameState = (*serverResponse)["gameState"]; if (serverGameState.hasMember("playerOnePos")) { - this->p1_loc.y = (serverGameState)["playerOnePos"].get<int>(); + this->p1_loc.x = (serverGameState)["playerOnePos"].get<int>(); } if (serverGameState.hasMember("playerTwoPos")) { - this->p2_loc.y = (serverGameState)["playerTwoPos"].get<int>(); + this->p2_loc.x = (serverGameState)["playerTwoPos"].get<int>(); } if (serverGameState.hasMember("ballPos")) { @@ -54,8 +57,11 @@ this->localPlayerNum = (char)(serverGameState)["player"].get<int>(); } + // TODO: check if hash has already been set if (serverGameState.hasMember("hash")) { - this->lobbyHash = (serverGameState)["hash"].get<std::string>(); + strcpy(this->lobbyHash, + (serverGameState)["hash"].get<std::string>().c_str()); + this->lobbyHash[21] = 0; } gfx->renderGameState(this); } @@ -68,6 +74,10 @@ return getPlayerTwoLocation(); } +char *GameState::getLobbyHash() { + return this->lobbyHash; +} + char GameState::getLocalPlayerNum() { return this->localPlayerNum; }