App 4 Snake Game

In this chapter, we will play a classic game, snake.

App 4.1 Snake Game

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

Component List

Freenove Projects Board for Raspberry Pi

Chapter01_04

Raspberry Pi

Chapter01_05

GPIO Ribbon Cable

Chapter01_06

Circuit

Schematic diagram

APP4_00

Hardware connection:

APP4_01

Note

If you have any concerns, please send an email to: support@freenove.com

Sketch

Sketch 4.1.1 SnakeGame

Note

If you have any concerns, please send an email to: support@freenove.com

First, enter where the project is located:

/home/pi/Freenove_Kit/Processing/Apps/App_04_1_1_Snake_Game

And then right-click to select Processing IDE

../../../_images/APP4_02.png

Or you can enter a command in the terminal to open the file App_04_1_1_Snake_Game. (The following is only one line of command. There is a Space after Processing.)

processing ~/Freenove_Kit/Processing/Apps/App_04_1_1_Snake_Game/App_04_1_1_Snake_Game.pde

Open Processing and click Run.

../../../_images/APP4_03.png

The result is as shown below. Pressing Space to start the game.

../../../_images/APP4_04.png

Pressing the space can start the game:

../../../_images/APP4_05.png

You can control the movement direction of the snake through the four buttons in circuit or four arrow keys on the keyboard. The rules are the same as the classic Snake game:

../../../_images/APP4_06.png

When the game is over, pressing the space can restart the game:

../../../_images/APP4_07.png

You can restart the game by pressing the space bar at any time during the game.

Note

If you have any concerns, please send an email to: support@freenove.com