multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
Diff: graphics.cpp
- Revision:
- 24:05eb0b0ab554
- Parent:
- 23:c38680c32552
- Child:
- 26:ebadab157abe
--- a/graphics.cpp Mon Nov 16 03:01:50 2020 +0000 +++ b/graphics.cpp Mon Nov 16 03:34:34 2020 +0000 @@ -36,31 +36,35 @@ } void Graphics::renderPlayers(GameState *gs) { - int otherPlayerNum = (gs->getLocalPlayerNum() == 0) ? 1 : 0; + int8_t topPaddleRenderPos = gs->getPlayerLocation(0).x; + int8_t bottomPaddleRenderPos = gs->getPlayerLocation(1).x; + + uint16_t top_color = YOUR_PADDLE_COLOR; + uint16_t bottom_color = OTHER_PADDLE_COLOR; - int8_t bottomPaddleRenderPos = gs->getPlayerLocation(gs->getLocalPlayerNum()).x; - int8_t topPaddleRenderPos = gs->getPlayerLocation(otherPlayerNum).x; + if (gs->getLocalPlayerNum() == 1) { + top_color = OTHER_PADDLE_COLOR; + bottom_color = YOUR_PADDLE_COLOR; + } + + // draw top paddle + tft->drawFastHLine(bottomPaddleRenderPos - PADDLE_WIDTH / 2, + ELEVATION, PADDLE_WIDTH, top_color); // draw bottom paddle - tft->drawFastHLine(bottomPaddleRenderPos - PADDLE_WIDTH / 2, - ELEVATION, PADDLE_WIDTH, PADDLE_COLOR); - - // draw top paddle tft->drawFastHLine(topPaddleRenderPos - PADDLE_WIDTH / 2, - 127 - ELEVATION, PADDLE_WIDTH, PADDLE_COLOR); + 127 - ELEVATION, PADDLE_WIDTH, bottom_color); } void Graphics::erasePlayers(GameState *gs) { - int otherPlayerNum = (gs->getLocalPlayerNum() == 0) ? 1 : 0; + int8_t topPaddleRenderPos = gs->getPlayerLocation(0).x; + int8_t bottomPaddleRenderPos = gs->getPlayerLocation(1).x; - int8_t bottomPaddleRenderPos = gs->getPlayerLocation(gs->getLocalPlayerNum()).x; - int8_t topPaddleRenderPos = gs->getPlayerLocation(otherPlayerNum).x; - - // draw bottom paddle + // draw top paddle tft->drawFastHLine(bottomPaddleRenderPos - PADDLE_WIDTH / 2, ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR); - // draw top paddle + // draw bottom paddle tft->drawFastHLine(topPaddleRenderPos - PADDLE_WIDTH / 2, 127 - ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR); }