2. App Tetris Game

In this chapter, we will play a game, Tetris game.

2.1. App Tetris Game

Now, let’s create and experience our own game.

2.1.1. Component List

  1. Raspberry Pi (with 40 GPIO) x1

  2. GPIO Extension Board & Ribbon Cable x1

  3. Breadboard x1

Jumper Wires x12

jumper-wire

Push button x4

button-small

Resistor 10kΩ x4

Resistor-10kΩ

2.1.2. Circuit

Schematic diagram

snake_game_Sc

Hardware connection. If you need any support,please feel free to contact us via:

support@freenove.com

snake_game_Fr

2.1.3. Sketch

2.1.3.1. Sketch TetrisGame

  1. Use Processing to open the file Sketch_05_1_1_TetrisGame.

$ processing ~/Freenove_Kit/Processing/Apps/App_02_1_1_Tetris/App_02_1_1_Tetris.pde
  1. Click on “RUN” to run the code.

After the program is executed, Display Window displays as below.

../../../_images/Tetris_Game.png

The left and right button in the circuit can control the movement of the falling block to left or right. And the button below can accelerate falling of the block. The button above is used for rotating of the block. Four direction keys on keyboard can also be used to play the game.

../../../_images/Tetris_Game_1.png

In the process of game, pressing the space bar on the keyboard can pause the game. The right side of the Display Window shows the upcoming block, the current game speed and the current score. The more lines you eliminate once, the higher the scores you will get. If you eliminate one line once, you will get 10 points. If you eliminate 4 lines once, you will get 70 points.

../../../_images/Tetris_Game_2.png

When the blocks are beyond the screen, the game is over. After the game is over, press the space bar to start a new game.

../../../_images/Tetris_Game_3.png