multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

Revision:
37:8a0fc62a0512
Parent:
36:46bb54b669bc
--- a/graphics.cpp	Sat Nov 28 04:21:08 2020 +0000
+++ b/graphics.cpp	Sun Nov 29 22:40:24 2020 +0000
@@ -27,16 +27,23 @@
     tft->printf("%s", "Player..."); 
 }
 
+void Graphics::renderCountdown(GameState *gs) {
+    tft->setTextColor(DEFAULT_TEXT_COLOR); 
+    tft->setTextCursor(63, 63); 
+    tft->printf("%i", gs->getCountdown()); 
+}
+
+void Graphics::renderGameState(GameState *gs) {
+    renderBall(gs); 
+    renderPlayers(gs);
+    renderScore(gs); 
+}
+
 void Graphics::renderBall(GameState *gs) {
     Coord ball_loc = gs->getBallLocation(); 
     tft->drawPixel(ball_loc.x, ball_loc.y, ST7735_WHITE); 
 }
 
-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 topPaddleRenderPos = gs->getPlayerLocation(0).x;    
     int8_t bottomPaddleRenderPos = gs->getPlayerLocation(1).x;
@@ -58,19 +65,6 @@
         127 - ELEVATION, PADDLE_WIDTH, bottom_color);
 }
 
-void Graphics::erasePlayers(GameState *gs) {
-    int8_t topPaddleRenderPos = gs->getPlayerLocation(0).x;    
-    int8_t bottomPaddleRenderPos = gs->getPlayerLocation(1).x;
-    
-    // erase top paddle
-    tft->drawFastHLine(topPaddleRenderPos - PADDLE_WIDTH / 2,
-        ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR);
-    
-    // erase bottom paddle
-    tft->drawFastHLine(bottomPaddleRenderPos - PADDLE_WIDTH / 2,
-        127 - ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR);
-}
-
 void Graphics::renderScore(GameState *gs) {
     tft->setTextColor(ST7735_WHITE);
     tft->setTextCursor(120, 50); 
@@ -79,14 +73,6 @@
     tft->printf("%i", gs->getPlayerTwoScore());
 }
 
-void Graphics::eraseScore(GameState *gs) {
-    tft->setTextColor(BACKGROUND_COLOR);
-    tft->setTextCursor(120, 50); 
-    tft->printf("%i", gs->getPlayerOneScore());
-    tft->setTextCursor(120, 77); 
-    tft->printf("%i", gs->getPlayerTwoScore());
-}
-
 void Graphics::renderGameOver(GameState *gs) {
     reset(); 
     tft->setTextColor(DEFAULT_TEXT_COLOR);
@@ -110,22 +96,36 @@
     tft->printf("to play again!"); 
 }
 
-void Graphics::renderCountdown(GameState *gs) {
-    tft->setTextColor(DEFAULT_TEXT_COLOR); 
-    tft->setTextCursor(63, 63); 
-    tft->printf("%i", gs->getCountdown()); 
-}
-
 void Graphics::eraseCountdown(GameState *gs) {
     tft->setTextColor(BACKGROUND_COLOR); 
     tft->setTextCursor(63, 63); 
     tft->printf("%i", gs->getCountdown());
 }
 
-void Graphics::renderGameState(GameState *gs) {
-    renderBall(gs); 
-    renderPlayers(gs);
-    renderScore(gs); 
+void Graphics::eraseBall(GameState *gs) {
+    Coord ball_loc = gs->getBallLocation(); 
+    tft->drawPixel(ball_loc.x, ball_loc.y, BACKGROUND_COLOR); 
+}
+
+void Graphics::erasePlayers(GameState *gs) {
+    int8_t topPaddleRenderPos = gs->getPlayerLocation(0).x;    
+    int8_t bottomPaddleRenderPos = gs->getPlayerLocation(1).x;
+    
+    // erase top paddle
+    tft->drawFastHLine(topPaddleRenderPos - PADDLE_WIDTH / 2,
+        ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR);
+    
+    // erase bottom paddle
+    tft->drawFastHLine(bottomPaddleRenderPos - PADDLE_WIDTH / 2,
+        127 - ELEVATION, PADDLE_WIDTH, BACKGROUND_COLOR);
+}
+
+void Graphics::eraseScore(GameState *gs) {
+    tft->setTextColor(BACKGROUND_COLOR);
+    tft->setTextCursor(120, 50); 
+    tft->printf("%i", gs->getPlayerOneScore());
+    tft->setTextCursor(120, 77); 
+    tft->printf("%i", gs->getPlayerTwoScore());
 }
 
 void Graphics::eraseGameState(GameState *gs) {