multiplayer pong game for LPC 1768
Dependencies: mbed MbedJSONValue mbed-rtos Adafruit_ST7735 Adafruit_GFX EthernetInterface DebouncedInterrupt
graphics.cpp@22:1c49e1fae846, 2020-11-16 (annotated)
- Committer:
- vsoltan
- Date:
- Mon Nov 16 02:04:23 2020 +0000
- Revision:
- 22:1c49e1fae846
- Parent:
- 19:58cc5465f647
- Child:
- 23:c38680c32552
improved ball rendering
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vsoltan | 16:7fd48cda0773 | 1 | |
vsoltan | 16:7fd48cda0773 | 2 | #include "graphics.h" |
vsoltan | 16:7fd48cda0773 | 3 | |
vsoltan | 16:7fd48cda0773 | 4 | Graphics::Graphics() { |
vsoltan | 17:32ae1f106002 | 5 | printf("\n\rInitializing Graphics: initializing TFT\n\r"); |
vsoltan | 16:7fd48cda0773 | 6 | this->tft = new Adafruit_ST7735(P_MOSI, P_MISO, P_SOCK, P_CS, P_RS, P_DC); |
vsoltan | 17:32ae1f106002 | 7 | printf("Initializing Graphics: optimizing display for resolution\n\r"); |
vsoltan | 17:32ae1f106002 | 8 | tft->initR(INITR_144GREENTAB); |
vsoltan | 17:32ae1f106002 | 9 | tft->setTextColor(ST7735_WHITE); |
vsoltan | 16:7fd48cda0773 | 10 | } |
vsoltan | 16:7fd48cda0773 | 11 | |
vsoltan | 16:7fd48cda0773 | 12 | void Graphics::renderLaunchScreen() { |
vsoltan | 22:1c49e1fae846 | 13 | tft->fillScreen(LAUNCH_SCREEN_COLOR); |
vsoltan | 22:1c49e1fae846 | 14 | tft->setTextCursor(15, 20); |
vsoltan | 17:32ae1f106002 | 15 | tft->printf("%s", "Multiplayer Pong"); |
vsoltan | 22:1c49e1fae846 | 16 | tft->setTextCursor(15, 80); |
vsoltan | 22:1c49e1fae846 | 17 | tft->printf("%s", "press any button"); |
vsoltan | 22:1c49e1fae846 | 18 | tft->setTextCursor(15, 90); |
vsoltan | 22:1c49e1fae846 | 19 | tft->printf("%s", "to continue"); |
vsoltan | 17:32ae1f106002 | 20 | } |
vsoltan | 17:32ae1f106002 | 21 | |
vsoltan | 18:32fce82690a1 | 22 | void Graphics::renderWaitingRoom() { |
vsoltan | 22:1c49e1fae846 | 23 | tft->fillScreen(WAITING_SCREEN_COLOR); |
vsoltan | 22:1c49e1fae846 | 24 | tft->setTextCursor(5, 20); |
vsoltan | 18:32fce82690a1 | 25 | tft->printf("%s", "Waiting For Player"); |
vsoltan | 18:32fce82690a1 | 26 | } |
vsoltan | 18:32fce82690a1 | 27 | |
vsoltan | 17:32ae1f106002 | 28 | void Graphics::renderBall(GameState *gs) { |
vsoltan | 19:58cc5465f647 | 29 | Coord ball_loc = gs->getBallLocation(); |
vsoltan | 19:58cc5465f647 | 30 | tft->drawPixel(ball_loc.x, ball_loc.y, ST7735_WHITE); |
vsoltan | 17:32ae1f106002 | 31 | } |
vsoltan | 17:32ae1f106002 | 32 | |
vsoltan | 22:1c49e1fae846 | 33 | void Graphics::removeBall(GameState *gs) { |
vsoltan | 22:1c49e1fae846 | 34 | Coord ball_loc = gs->getBallLocation(); |
vsoltan | 22:1c49e1fae846 | 35 | tft->drawPixel(ball_loc.x, ball_loc.y, BACKGROUND_COLOR); |
vsoltan | 22:1c49e1fae846 | 36 | } |
vsoltan | 22:1c49e1fae846 | 37 | |
vsoltan | 17:32ae1f106002 | 38 | void Graphics::renderPlayers(GameState *gs) { |
vsoltan | 19:58cc5465f647 | 39 | int8_t bottomPaddleRenderPos = gs->getPlayerLocation(gs->getLocalPlayerNum()).y; |
vsoltan | 22:1c49e1fae846 | 40 | int8_t topPaddleRenderPos = 127 - bottomPaddleRenderPos; |
vsoltan | 22:1c49e1fae846 | 41 | } |
vsoltan | 22:1c49e1fae846 | 42 | |
vsoltan | 22:1c49e1fae846 | 43 | void Graphics::removeGameState(GameState *gs) { |
vsoltan | 22:1c49e1fae846 | 44 | removeBall(gs); |
vsoltan | 22:1c49e1fae846 | 45 | //removePlayers(gs); |
vsoltan | 17:32ae1f106002 | 46 | } |
vsoltan | 16:7fd48cda0773 | 47 | |
vsoltan | 16:7fd48cda0773 | 48 | void Graphics::renderGameState(GameState *gs) { |
vsoltan | 19:58cc5465f647 | 49 | renderBall(gs); |
vsoltan | 22:1c49e1fae846 | 50 | // renderPlayers(gs); |
vsoltan | 16:7fd48cda0773 | 51 | } |