4. Chapter Snake Game
We have learned how control 2D and 3D figures. Now, we will use control board to play the classic snake game. There are both 2D and 3D version.
4.1. Project 4.1 Snake Game
First, let’s play a 2D snake game.
4.1.1. Component list
Control board x1
|
||
Breadboard x1
|
GPIO Extension Board x1
|
|
USB cable x1
|
Jumper M/M x3
|
|
Joystick x1
|
||
4.1.2. Circuit
Use pin A0 and pin A1 on control board to detect the voltage value of two rotary potentiometers inside Joystick, and use pin 8 port to detect the vertical button.
Schematic diagram |
|
Hardware connection If you need any support, please feel free to contact us via: support@freenove.com |
|
4.1.3. Sketch
4.1.3.1. Sketch Snake_Game
Use Processing to open .\Processing\Processing\Box_3D\Box_3D.pde, and click Run.
If the connection succeeds, the follow will be shown:
Press the space bar on keyboard to start the game:
Press the corresponding button to control the snake’s movements. The game rules are the same as the classic snake game:
When the game fails, press space bar to restart the game:
Additionally, you can restart the game by pressing the space bar at any time.
4.2. Project 4.2 Snake Game 3D
Now, let’s experience the 3D version game.
4.2.1. Component list
The same as last section.
4.2.2. Circuit
The same as last section.
4.2.3. Sketch
4.2.3.1. Sketch Snake_Game_3D
Use Processing to open .\Processing\Processing\Snake_Game_3D\Snake_Game_3D.pde and click Run.
If the connection succeeds, the follow will be shown:
Press the space bar on keyboard to start the game:
Press the corresponding button to control the snake’s movements. The game rules are the same as the classic snake game:
The rest operation is the same as the 2D version.







