This is an old revision of the document!


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

O schemă bloc cu toate modulele proiectului vostru, atât software cât şi hardware însoţită de o descriere a acestora precum şi a modului în care interacţionează.

Hardware Design

Aici puneţi tot ce ţine de 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

Care au fost rezultatele obţinute în urma realizării proiectului vostru.

Conclusions

Journal

Puteți avea și o secțiune de jurnal în care să poată urmări asistentul de proiect progresul proiectului.

Bibliography/Resources

Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe Resurse Software şi Resurse Hardware.

Export to PDF

pm/prj2022/apredescu/143.1653329423.txt.gz · Last modified: 2022/05/23 21:10 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