multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Revision:
23:c38680c32552
Parent:
22:1c49e1fae846
Child:
24:05eb0b0ab554
--- a/graphics.cpp	Mon Nov 16 02:04:23 2020 +0000
+++ b/graphics.cpp	Mon Nov 16 03:01:50 2020 +0000
@@ -30,22 +30,51 @@
     tft->drawPixel(ball_loc.x, ball_loc.y, ST7735_WHITE); 
 }
 
-void Graphics::removeBall(GameState *gs) {
+void Graphics::eraseBall(GameState *gs) {
     Coord ball_loc = gs->getBallLocation(); 
     tft->drawPixel(ball_loc.x, ball_loc.y, BACKGROUND_COLOR); 
 }
 
 void Graphics::renderPlayers(GameState *gs) {
-    int8_t bottomPaddleRenderPos = gs->getPlayerLocation(gs->getLocalPlayerNum()).y;
-    int8_t topPaddleRenderPos = 127 - bottomPaddleRenderPos;    
+    int otherPlayerNum = (gs->getLocalPlayerNum() == 0) ? 1 : 0; 
+    
+    int8_t bottomPaddleRenderPos = gs->getPlayerLocation(gs->getLocalPlayerNum()).x;
+    int8_t topPaddleRenderPos = gs->getPlayerLocation(otherPlayerNum).x;    
+    
+    // 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);
 }
 
-void Graphics::removeGameState(GameState *gs) {
-    removeBall(gs); 
-    //removePlayers(gs); 
+void Graphics::erasePlayers(GameState *gs) {
+    int otherPlayerNum = (gs->getLocalPlayerNum() == 0) ? 1 : 0; 
+    
+    int8_t bottomPaddleRenderPos = gs->getPlayerLocation(gs->getLocalPlayerNum()).x;
+    int8_t topPaddleRenderPos = gs->getPlayerLocation(otherPlayerNum).x;    
+    
+    // draw bottom paddle
+    tft->drawFastHLine(bottomPaddleRenderPos - PADDLE_WIDTH / 2,
+        ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR);
+    
+    // draw top paddle
+    tft->drawFastHLine(topPaddleRenderPos - PADDLE_WIDTH / 2,
+        127 - ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR);
 }
 
 void Graphics::renderGameState(GameState *gs) {
     renderBall(gs); 
-//    renderPlayers(gs);
+    renderPlayers(gs);
+}
+
+void Graphics::eraseGameState(GameState *gs) {
+    eraseBall(gs); 
+    erasePlayers(gs); 
+}
+
+void Graphics::reset() {
+    tft->fillScreen(BACKGROUND_COLOR);
 }
\ No newline at end of file