A simple Pong game with STM32F407VET6 black board (Seeed Arch Max) and ILI9341 320x240 TFT display.
Dependencies: mbed ILI9341_STM32F4
A simple Pong game with STM32F407VET6 black board (compatible with Seed Arch Max) and ILI9341 320x240 TFT display.
Connect the SPI interface of an ILI9341 320x240 TFT display to the STM32F407VET6 board (Seeed Arch Max) as follows:
ILI9341 TFT | SPI interface | STM32F407VET6 |
---|---|---|
VCC | +5V | |
GND | GND | |
CS | PB_7 | |
RESET | PB_8 | |
D/C | PB_6 | |
SDI(MOSI) | PB_5 | |
SCK | PB_3 | |
LED | over a 56 ohm resistor | +5V |
SDO(MISO) | PB_4 |
Diff: Racket.cpp
- Revision:
- 1:971e721f6ef2
- Parent:
- 0:887dd664eca0
diff -r 887dd664eca0 -r 971e721f6ef2 Racket.cpp --- a/Racket.cpp Thu Apr 11 20:18:15 2019 +0000 +++ b/Racket.cpp Mon Apr 15 06:02:55 2019 +0000 @@ -7,7 +7,15 @@ * @retval */ Racket::Racket(int w /*= 20*/, int h /*= 40*/, uint16_t clr /*= TFT_WHITE*/ ) : - width(w), height(h), xPos(320), yPos(240 / 2), velocity(10), xDir(0), yDir(0), color(clr) + width(w), + height(h), + xPos(320), + yPos(240 / 2), + yPosOld(240 / 2), + velocity(4), + xDir(0), + yDir(0), + color(clr) { } /** @@ -16,13 +24,29 @@ * @param * @retval */ +void Racket::home() +{ + xPos = 320; + yPos = 240 / 2; + yPosOld = yPos; + xDir = 0; + yDir = 0; +} + +/** + * @brief + * @note + * @param + * @retval + */ void Racket::move(DigitalIn* btnUp, DigitalIn* btnDown) { yDir = 0; if (*btnUp == 0) - yDir = -1; // move up + yDir = -1; // move up if (*btnDown == 0) - yDir = 1; // move down + yDir = 1; // move down + yPosOld = yPos; yPos += yDir * velocity; if (yPos < height / 2) yPos = height / 2; @@ -36,7 +60,14 @@ * @param * @retval */ -void Racket::paint(uint16_t clr /*= TFT_WHITE*/ ) +void Racket::paint() { - tft_boxfill(xPos - width / 2, yPos - height / 2, xPos, yPos + height / 2, clr); + if (yDir == 1) { + tft_boxfill(xPos - width / 2, yPosOld - height / 2, xPos, yPos - height / 2, TFT_BLACK); // hide racket at old position + tft_boxfill(xPos - width / 2, yPos - height / 2, xPos, yPos + height / 2, TFT_WHITE); // draw racket at new position + } + else { + tft_boxfill(xPos - width / 2, yPos + height / 2, xPos, yPosOld + height / 2, TFT_BLACK); // hide racket at old position + tft_boxfill(xPos - width / 2, yPos - height / 2, xPos, yPos + height / 2, TFT_WHITE); // draw racket at new position + } }