Snake Game

Introduction

Mis Emilia Oana 1222B

In this project I will implement the classical Snake game using a matrix. The game will be controlled by a joystick and the speed can be changed using a potentiometer.

  • Using the joystick you have to earn as many points as you can. After you lose the game, on the matrix will be displayed the final score followed by the message: GAME OVER.
  • Purpose: To have fun playing a game made by you using hardware components
  • Idea: I was inspired by the original game, the twist is that I increase the speed by hand, not if you get more points

General description

Hardware Design

Parts List

  • LED Matrix
  • Joystick
  • Potentiometer
  • Breadboard

Software Design

Developed using Arduino IDE. When the program starts, the pins and LED matrix (intensity, the display is cleared, etc) are initialized. After the calibration of the joystick, the 'snake' message is shown on the LED matrix.

For each loop, 4 actions are performed: generate food, scan for joystick input, update the snake, and calculate if the game is over. Those actions are performed by 4 functions:

generateFood()
scanJoystick()
calculateSnake()
handleGameStates()

Each action was placed in a separate function in order to preserve code modularity, and allow for ease of expansion.

Also, in order to easily debug the code, in the loop, the function

dumpGameBoard()

can be called. This function prints the game board to the serial monitor.

To make the game easier to write, I created two structs: Point & Coordinate. The Point struct is used to store the coordinates of the snake's head and the coordinate of the food. At boot, the snake is initialized with a length of 3. The snake starts at a random position on the board, and the food is not placed anywhere.

The snake's speed can also be changed, by updating the snakeSpeed variable. The higher the speed, the faster the snake moves.

If the snake crosses an edge, it will appear on the other side of the screen. This is handled by the

fixEdge()

function.

3 default messages are provided: snake message, game over message, score message. Also, 10 (0-9) digits may be written to the LED matrix, using the digits map.

Results

Conclusions

This was my first arduino project and I am proud that I completed it in a few weeks.

Download

Journal

25/05/2022 - wiki page completion

20/05/2022 - finished project

18/05/2022 - finished writing the software part

23/04/2022 - wiki page

21/04/2022 - project selection

Bibliography/Resources

pm/prj2022/apredescu/143.txt · Last modified: 2022/06/01 22:15 by emilia_oana.mis
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0