multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

graphics.cpp

Committer:
vsoltan
Date:
2020-11-15
Revision:
19:58cc5465f647
Parent:
18:32fce82690a1
Child:
22:1c49e1fae846

File content as of revision 19:58cc5465f647:


#include "graphics.h"

Graphics::Graphics() {
    printf("\n\rInitializing Graphics: initializing TFT\n\r");
    this->tft = new Adafruit_ST7735(P_MOSI, P_MISO, P_SOCK, P_CS, P_RS, P_DC);
    printf("Initializing Graphics: optimizing display for resolution\n\r");
    tft->initR(INITR_144GREENTAB); 
    tft->setTextColor(ST7735_WHITE);
}

void Graphics::renderLaunchScreen() {
    tft->fillScreen(ST7735_BLACK);
    tft->setTextCursor(20, 20); 
    tft->printf("%s", "Multiplayer Pong");
    tft->setTextCursor(20, 80); 
    tft->printf("%s", "Press any button to continue."); 
}

void Graphics::renderWaitingRoom() {
    tft->fillScreen(ST7735_GREEN);
    tft->setTextCursor(20, 20); 
    tft->printf("%s", "Waiting For Player");
}

void Graphics::renderBall(GameState *gs) {
    // erase previous ball location
    Coord ball_loc = gs->getBallLocation(); 
    tft->drawPixel(ball_loc.x, ball_loc.y, ST7735_WHITE); 
}

void Graphics::renderPlayers(GameState *gs) {
    int8_t bottomPaddleRenderPos = gs->getPlayerLocation(gs->getLocalPlayerNum()).y;
    int8_t topPaddleRenderPos = 127 - bottomPaddleRenderPos;   
    
     
}

void Graphics::renderGameState(GameState *gs) {
    tft->fillScreen(ST7735_BLACK); 
    renderBall(gs); 
    renderPlayers(gs);
}