multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Diff: gamestate.cpp
- Revision:
- 37:8a0fc62a0512
- Parent:
- 36:46bb54b669bc
--- a/gamestate.cpp Sat Nov 28 04:21:08 2020 +0000 +++ b/gamestate.cpp Sun Nov 29 22:40:24 2020 +0000 @@ -24,10 +24,56 @@ return this->p2_loc; } +Coord GameState::getPlayerLocation(char player) { + if (player == 0) { + return getPlayerOneLocation(); + } + return getPlayerTwoLocation(); +} + Coord GameState::getBallLocation() { return this->ball_loc; } +char *GameState::getLobbyHash() { + return this->lobbyHash; +} + +char GameState::getLocalPlayerNum() { + return this->localPlayerNum; +} + +char GameState::hasStarted() { + return this->has_started; +} + +char GameState::done() { + return this->is_done; +} + +int GameState::getCountdown() { + return this->countdown; +} + +int GameState::getPlayerOneScore() { + return this->score[0]; +} + +int GameState::getPlayerTwoScore() { + return this->score[1]; +} + +int GameState::getPlayerScore(int player) { + if (player == 0) { + return getPlayerOneScore(); + } + return getPlayerTwoScore(); +} + +void GameState::setCountdown(int val) { + this->countdown = val; +} + void GameState::updateAndRender(MbedJSONValue *serverResponse, Graphics *gfx) { string typeResponse = (*serverResponse)["type"].get<std::string>(); if (typeResponse == "connected") { @@ -73,7 +119,6 @@ this->score[0] = (serverGameState)["score"][0].get<int>(); this->score[1] = (serverGameState)["score"][1].get<int>(); } - // TODO: check if hash has already been set if (serverGameState.hasMember("hash")) { strcpy(this->lobbyHash, (serverGameState)["hash"].get<std::string>().c_str()); @@ -83,48 +128,4 @@ } } -Coord GameState::getPlayerLocation(char player) { - if (player == 0) { - return getPlayerOneLocation(); - } - return getPlayerTwoLocation(); -} -char *GameState::getLobbyHash() { - return this->lobbyHash; -} - -char GameState::getLocalPlayerNum() { - return this->localPlayerNum; -} - -int GameState::getCountdown() { - return this->countdown; -} - -void GameState::setCountdown(int val) { - this->countdown = val; -} - -int GameState::getPlayerOneScore() { - return this->score[0]; -} - -int GameState::getPlayerTwoScore() { - return this->score[1]; -} - -int GameState::getPlayerScore(int player) { - if (player == 0) { - return getPlayerOneScore(); - } - return getPlayerTwoScore(); -} - -char GameState::hasStarted() { - return this->has_started; -} - -char GameState::done() { - return this->is_done; -}