Chapter 3 Snake Game

We have learned how control 2D and 3D figures. Now, we will use ESP32 board to play the classic snake game. There are both 2D and 3D version.

Project 3.1 Snake Game

First, let’s play a 2D snake game.

Component List

ESP32-WROVER x1

Chapter01_00

GPIO Extension Board x1

Chapter01_01

Breadboard x1

Chapter01_02

Joystick x1

Chapter14_00

Jumper M/M x3

Chapter01_05

Circuit

Use Pin36 and Pin39 (A0 and A3) ports to detect the voltage value of two rotary potentiometers inside joystick.

Schematic diagram

Chapter03_00

Hardware connection

Chapter03_01

Sketch

Sketch Snake_Game

Use Processing to open Freenove Ultimate Starter Kit for ESP32CProcessingProcessingBox_3DBox_3D.pde , and click Run.Snake_Game.pde and click Run. If the connection succeeds, the follow will be shown:

../../../_images/Chapter03_021.png

Press the space bar on keyboard to start the game:

../../../_images/Chapter03_031.png

Shift the joystick to control the snake action. The game rules are the same as the classic snake game:

../../../_images/Chapter03_041.png

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

../../../_images/Chapter03_051.png

Additionally, you can restart the game by pressing the space bar at any time.

Project 3.2 Snake Game 3D

Now, let’s experience the 3D version game.

Component list

The same as last section.

Circuit

The same as last section.

Sketch

Sketch Snake_Game_3D

Use Processing to open Freenove Ultimate Starter Kit for ESP32CProcessingProcessingSnake_Game_3DSnake_Game_3D.pde Snake_Game_3D.pde and click Run. If the connection succeeds, the follow will be shown:

../../../_images/Chapter03_06.png

Press the space bar on keyboard to start the game:

../../../_images/Chapter03_07.png

Shift the joystick to control the snake action. The game rules are the same as the classic snake game:

../../../_images/Chapter03_08.png

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