ECE434 Project - SnakeGame

Team members: Mark A. Yoder

Grading Template
I'm using the following template to grade. Each slot is 10 points. 0 = Missing, 5=OK, 10=Wow!

 Add Extras

09 Executive Summary 09 Packaging 09 Installation Instructions 09 User Instructions 09 Highlights 09 Theory of Operation 09 Work Breakdown 09 Future Work/Conclusions 09 Hackster.io 09 Demo/Poster 00 Not Late

Score: 90/100

Executive Summary
The project runs the snake game where you are a snake going in a world and you have to try and eat the apple in the game. Each time you eat the apple your snake grows in size. The goal is to not run into your own self and to stay in the game screen and continue to grow your snake as big as possible.

We have the python script running pygame to display the game onto the LCD screen. We have all the growing and collisions working properly. We also have three GPIO buttons working. One is to slow down the game to make it easier to play, another to speed up the game to make it faster and a third one to start and reset the game back to the start whenever pressed, and a fourth to end the game whenever pressed. You can play the game using one of the rotary encoders to turn the snake left or right from the current direction the snake is moving. We have an 8x8 LED Matrix to display the score of the game as you play it and will reset back to 0 when you start or restart the game.

We do not have the flask working currently to have the scoreboard updated so whenever you eat a fruit in the game the scoreboard would update the score to add 1 each time. The flask also doesn't work to control the game using the flask so that when you press the right button the snake would turn right and vice versa for the left turn button and the reset button.

Overall the project has been fun to implement and has some frustrations involving the Flask but works good and does the snake game good. The game has several different aspects we have used in the class such as GPIO, Rotary encoders, and I2C.

Packaging
The hardware used in this project is the LCD, Rotary Encoder, 4 Push buttons, 4 resistors, Matrix 8x8 LED display with 2 I2C pins and the BeagleBone Black.

The LCD is setup for SPI1. The Rotary Encoder is set to pins P8_11 and P8_12. The push buttons are set to P9_21,P9_22, P9_23,and P9_26. We have the LED Matrix I2C pins connected to P9_19 and P9_20 connected to bus 2 of the I2C bus.

Installation Instructions
Give step by step instructions on how to install your project. To the find all the code and instructions go to this github link: https://github.com/rhit-kimmw/ECE434Project-SnakeGame In this github you will find the README.md with all the up to date of how to run the files and the necessary setup instructions to do before you run the files.

User Instructions
The first thing you do to run the code is first to do 'chmod +x setup.sh' and then run './setup.sh' this will setup all your ports to be gpio or eqep for the necessary pins to run the program. After that is complete do 'chmod +x snake.py' and to run the file do 'sudo ./snake.py' this will run the snake game on the LCD and you can play the game as instructed.

To turn right turn the encoder counter-clockwise.

To turn left turn the encoder clockwise. To slow the game down press the push button connected to pin P9_23 or to speed the game up press the push button connected to P9_21.

To start and restart the game press the push button connected to P9_26.

To end the Game once in play press the push button connected to P9_22.

To get the LED matrix to work connected the SCL to P9_19 and the SDA to P9_20 and connected the positive pin to voltage and the negative pin to ground.

Highlights
Our project can run a fully functional Snake game in which the snake grows as you eat an apple and an apple randomly appears on the screen as you eat one. You can turn the head of the snake left or right as it moves to get the apples. Using the Push buttons you can speed up how fast the snake goes to make the game harder or slow down the game by pushing another push button. To start the game or restart the game you press the same push button whenever you are ready. To stop the program you simply press the fourth push button to end the game. We also have an LED 8x8 Matrix displaying the score of the game. If you eat an apple your score goes up and will display a 1 and continue to display the scores each time you eat an apple and will go back to 0 if you press the restart button.

Theory of Operation
Youtube Video of Project : https://youtu.be/SN_Hy4Xf2fg

We are using a python script called snake.py to run the snake game. Inside that snake game we are using pygame to run the game onto the LCD. We have three different classes in our code called Game, Snake, and Apple. The Game class controls the functionality of the game such as initializing the game and setting up the structure of how the game works. There are several functions within Game such as runGame which is called to run the game and inside that function it initializes the Snake and Apple and calls those classes to set up the Snake and Apple for the Game. In Snake class we set the snakes positions and also the snakes movements and the function of how it grows after it has a collision with the apple and eats it. The Apple class is very basic and just chooses a base position to start but once eaten the apple will choose a random position in the game and go to there and wait until the game restarts or is eaten by the snake. There are also several other functions within the game to do the features we have added such as increasing or decreasing the speed of the game in which we simply increase or decrease the ticks of the timer to control the speeds. There is functions to end and restart the game and to display the scores in which we make the byte values for each digit and then write functions to get them properly displayed onto the LED Matrix.

Work Breakdown
Martino wrote the Python Script for the Game and got the collisions working between the them, He got the rotary encoder code working and made the Byte values to display on the LED Matrix.

Ethan Set up the hardware and got the GPIO pins and the functionalities to work. Martino made the individual components but Ethan combined them to work together.

Both worked to get the LCD to work properly.

Ethan did the Wiki page stuff and Martino did the Hackster.io documentations.

The things listed above are working for the project and Ethan worked on getting the Flask in the project but was not able to do so with either displaying the score or controlling the game.

Future Work
we suggest sing the Flask would be something that we wanted to do but couldn't. Using the flask to display the score or to control the game would be something we would of wanted but couldn't do.

Conclusions
Give some concluding thoughts about the project. Suggest some future additions that could make it even more interesting.

Overall the project was fun to implement and try different things but some future additions that could be made is adding the Flask to either display the score of the game or control the snake game would be something that we weren't able to do. Another thing that could be done is a bigger screen to use and on a LED Matrix if wanted instead of the LCD. You can control the snake with a different controller is another good idea if you possibly could using a PlayStation controller or some of device would be cool. Overall getting the GPIO, I2C and the rotary encoders with the LCD to work and display together was fun and decent amount of features is overall good we think.