I am a Zoologist from the Arduino Chinese community. I personally like to make all kinds of interesting things with Arduino. This time I brought you a Tetris game console made by ESP32 (DFRobot’s FireBeetle).
“In 1984, in Moscow, the capital of the country that was still called the Soviet Union, Alexei Pajitnov, an engineer at the Computer Center at the headquarters of the Russian Academy of Sciences (of course it was also called the Soviet Academy of Sciences at that time), began to consider the idea of computer science. He developed some simple games on his own. After a period of experimentation, he got inspiration from another jigsaw puzzle game and considered letting different shapes of figures fall one after another, stacking them at the bottom of the rectangle so that they could be arranged in a complete row and then eliminate them. With the assistance of two other companions, he finally completed the game he named "Tetris" (Russian: Тетрис), which we are more accustomed to calling "Tetris" today. June 6, 1984 Recognized as the anniversary of the birth of Tetris, the game was originally developed by Alexey Pajitnov, an engineer at the Computing Center of the Soviet Academy of Sciences, who was inspired by another jigsaw puzzle game. According to another person involved, "Tetris "The word was invented and insisted on by Alexey himself. It comes from the combination of "four" (Greek: tetra) which reflects the basic structure of the Tetris pattern and Alexey's own favorite sport "tennis" .The original name of "Tetris" (Russian: Тетрис) is a word coined by the inventor Alexey Pajitnov himself, from the "four" (Greek: Greek: 四) that reflects the basic structure of the Tetris pattern. tetra) and Alexei's own favorite sport "tennis" (tennis).
The original Tetris program recognized as the first was born on June 6, 1984, running on the Elektronika 60 computer copied by the Soviet Union at the time. Because this computer could not display color block patterns, the original version could only use strings to represent graphics, but even so it reflected the charm of the game itself, and Alexey and his friends soon began to fall in love with it. Addicted. In 1985, one of the development partners, Vadin Gerasimov, ported Tetris under MS-DOS so that more personal computers could run it, and the game quickly became popular. Alexei initially hoped to make it legal Selling Tetris games, but this was very difficult under the Soviet system at the time. After several attempts failed, Alexei expressed that he could consider handing over the copyright of the game to the state-the then Soviet Academy of Sciences. A few years after its birth Here, Tetris has been disseminated in the form of free copies, expanding from the Soviet Union to the entire Europe, and also attracted more people's attention.
The first Tetris program was run on the Soviet Union's imitation Elektronika 60 computer, because it could not display colors. Blocks could only use characters to represent graphics. The following year, the game was ported to the MS-DOS version, and the pattern screen presented for the first time in this version became the basis of the game for the next thirty years, without even much change. In 1986, Hungary Programmers ported the game on the Apple II and Commodore 64. Robert Stein, a manager at the British game company Andromeda, noticed this business opportunity. He began to contact Alexei and Hungarian programmers to try to buy the copyright of Tetris. And before it was confirmed, it was sold to the British game company Mirrorsoft and the American game company Spectrum Holobyte respectively, which led to the copyright dispute over Tetris for more than ten years, and can even be said to have changed the development of the game. A series of events in history. "The above text is excerpted from "Thirty Years of Development History of Classic Legends" [Reference 1] This time, ESP32 is used with ILI9341 (240*320) to realize a handheld Tetris game console.
* 2. Describe the challenges faced by the project and the problems solved. 1. For the display control of ILI9341, I finally chose to use the Adafruit_GFX display library; pay special attention to the compatibility issue of this library with ESP32, which was solved by modifying the Adafruit_BusIOAdafruit_SPIDevice.cpp file:
/*!
* @brief Transfer (send/receive) one byte over hard/soft SPI
* @param buffer The buffer to send and receive at the same time
* @param len The number of bytes to transfer
*/
void Adafruit_SPIDevice::transfer(uint8_t *buffer, size_t len) {
if (_spi) {
// hardware SPI is easy
//LABZDebug _spi->transfer(buffer, len);
_spi->transferBytes(buffer,NULL,len); //LABZDebug
return;
}
2. Modify the library compatibility code of IL9341 and add a function to fill the imagevoid Adafruit_ILI9341::fillImage(void *image, int x, int y, int w, int h) {
//drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap, int16_t w,int16_t h),
Adafruit_SPITFT::drawRGBBitmap(x, y,(uint16_t *)image, w, h);
}
3. Added a scoring function. Every time a line is eliminated, the score is calculated. Specifically, if (DeleteCount!=0) {score+=DeleteCount*DeleteCount;}2 in the DeleteLine() function
4. Added a mechanism to control the speed based on the score. The descending speed is controlled in the GetNextPosRot() function: if ((millis()-TimeElsp)>Score2Level()) {pnext_pos->Y += 1;TimeElsp=millis(); }Score2Level() function returns the delay corresponding to the current score. The higher the score, the faster the falling speed will be;
5. Display the "next" function. It is designed in the Draw() function. For efficiency reasons, the display will only be updated when there is a change next time. At the same time, there is a special point here. For example, we have defined an image of image[20][20], but if we want to display the 10 x 20 content in it, we cannot directly use tft.fillImage. Because this function will assume that the display Buffer is 20x20 in size by default, confusion will occur.
* 3. Describe the key points involved in the hardware and software parts of the project
Hardware: DFRobot's TinkerNode ESP32 development board, chosen because it has its own power management chip and can easily use 18650 rechargeable batteries. At the same time, ESP32 provides a powerful interface (SPI can easily reach 40Mhz) and performance (the core can reach 240Mhz); Medium Jingyuan's ILI9431 TFT display; and a PS2 joystick for control, analog output XY four directions and a switch button;
Software: Use Arduino IDE for editing. The project refers to the open source design https://github.com/MhageGH/esp32_ILI9328_Tetris. . The serial port control and network parts of the project were deleted and modified to be controlled by the PS2 joystick. In addition, the functions of score display and next reality were added. * 4. Project material list display circuit board PS2 direction key ILI9341 TFT screen DFRobot TinkerNode female header several screws several project demonstration video: https://www.bilibili.com/video/BV1jA411e7h4/
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet