multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Revision 33:98ba7b0b8c2b, committed 2020-11-28
- Comitter:
- vsoltan
- Date:
- Sat Nov 28 03:30:09 2020 +0000
- Parent:
- 32:7cbf4d9a82af
- Child:
- 34:b19f39ad74ac
- Commit message:
- added dynamic game over display
Changed in this revision
graphics.cpp | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/graphics.cpp Sat Nov 28 03:22:06 2020 +0000 +++ b/graphics.cpp Sat Nov 28 03:30:09 2020 +0000 @@ -89,14 +89,21 @@ void Graphics::renderGameOver(GameState *gs) { reset(); - tft->setTextColor(DEFAULT_TEXT_COLOR); + tft->setTextColor(DEFAULT_TEXT_COLOR); tft->setTextCursor(15, 20); tft->printf("Game Over"); tft->setTextCursor(15, 40); - tft->printf("Final Score %i : %i", - gs->getPlayerOneScore(), gs->getPlayerTwoScore()); + + bool winner = gs->getPlayerOneScore() > gs->getPlayerTwoScore() ? 0 : 1; + + if (winner == gs->getLocalPlayerNum()) { + tft->printf("You won :)"); + } else { + printf("You lost :("); + } + tft->setTextCursor(15, 60); - tft->printf("Press any button to play again!"); + tft->printf("Press any button to play again!"); } void Graphics::renderCountdown(GameState *gs) {
--- a/main.cpp Sat Nov 28 03:22:06 2020 +0000 +++ b/main.cpp Sat Nov 28 03:30:09 2020 +0000 @@ -108,7 +108,7 @@ // cleanup the socket from the previous game int flushBytes = 0; - while ((receiveFrom = sock.receiveFrom(nist, tmp_buffer, sizeof(tmp_buffer))) != 0) {} + while ((flushBytes = sock.receiveFrom(nist, tmp_buffer, sizeof(tmp_buffer))) != 0) {} gfx->renderGameOver(gs);