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

Chapter01_00

Breadboard x1

Chapter02_00

GPIO Extension Board x1

Chapter02_01

USB cable x1

Chapter01_02

Jumper M/M x3

Chapter01_03

Joystick x1

Chapter16_00

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

Chapter4_00

Hardware connection

If you need any support, please feel free to contact us via: support@freenove.com

Chapter4_01

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:

../../../_images/Chapter4_02.png

Press the space bar on keyboard to start the game:

../../../_images/Chapter4_03.png

Press the corresponding button to control the snake’s movements. The game rules are the same as the classic snake game:

../../../_images/Chapter4_04.png

When the game fails, press space bar to restart the game:

../../../_images/Chapter4_05.png

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:

../../../_images/Chapter4_06.png

Press the space bar on keyboard to start the game:

../../../_images/Chapter4_07.png

Press the corresponding button to control the snake’s movements. The game rules are the same as the classic snake game:

../../../_images/Chapter4_08.png

The rest operation is the same as the 2D version.