multiplayer pong game for LPC 1768

Dependencies:   mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt

graphics.cpp

Committer:
vsoltan
Date:
2020-11-16
Revision:
22:1c49e1fae846
Parent:
19:58cc5465f647
Child:
23:c38680c32552

File content as of revision 22:1c49e1fae846:


#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(LAUNCH_SCREEN_COLOR);
    tft->setTextCursor(15, 20); 
    tft->printf("%s", "Multiplayer Pong");
    tft->setTextCursor(15, 80); 
    tft->printf("%s", "press any button"); 
    tft->setTextCursor(15, 90); 
    tft->printf("%s", "to continue"); 
}

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

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

void Graphics::removeBall(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;    
}

void Graphics::removeGameState(GameState *gs) {
    removeBall(gs); 
    //removePlayers(gs); 
}

void Graphics::renderGameState(GameState *gs) {
    renderBall(gs); 
//    renderPlayers(gs);
}