Hi everyone, we would like to introduce our Snake Game which is implemented on ARM Cortex M0 Microprocessor and we use a lcd screen which has 320*240 resolution. To this day it has remained hugely popular, not only because it carries a strong sense of nostalgia but because this was the first ever mobile gaming experience for many people.
Before everthing we want to introduce our team.Our team has three team members which are Mehmet Albayrak, Fatih Aytemiz and Burak Nayır(me) . All of us are Electronic and communication engineering senior students. We divided into four sub-groups. These are Algorithm Design, Debugging, Graphic design, and Coding. In order to learn assembly coding, all of us wrote our snake game code in some parts. On other categories, we divided sub groups which are have two team members.
The Figure-1 is showed all our algorithm flowchart. Each color of boxes symbol different purpose. The blue boxes show initial steps which execute just one time.The red boxes show the steps that must be executed continuously while the game is running. Also, purple boxes show conditional states. We have two conditional boxes, one of which is the game over condition and the other one is the condition of eating food. In figure, each box is tested individually with assembly codes, then we combined all of them. We are going to detail all boxes of flowchart.
The game loads initial graphic design which we figured on figure-2. We created conditionaly states, we painted each letter.We wrote almost 500 lines of code to create initial screen. To start hold “a” 3 second. You can see button of code on right side.
4×4 pixel paintıng
first of all, we begun with painting sixteenth pixels which are formed four height and width, because one pixel width and height is so small. In order to make bigger snake, we used 4×4 pixel. In addition to that, when snake become bigger, it can move smaller map. You can see ratio of these two pixel sizes and move ranges of columns and rows on figure-3.
Using Ram: the game has initial values of snake and food and the game keeps these initial values on Ram. These values change while game is played. Also, the game needs to keep more values on ram after snake eats food. The game keeps values as half-word expect color of snake. For example location of snake’s head keeps most 8 bit is column location information, least 8 bit is row location information.
Get key Direction
There are two different events. One of them is that player chance direction of snake using key. Other is that snake keeps same direction of itself. When player push of any arrow keys, snake is changed its direction. However player cannot change opposite of current direction instead of current direction. If player does not push any arrow keys, snake keeps same direction. In addition to that if player wants to pause the game, the player can use a key. Then to start again, the player should push any arrow keys. According to new direction and current head location, the game calculates new head location.
If the head register address and food register address is same, then snake’s length is increased and the location variable of the food is updated. The speed of game is also speeded up by eating food. If snake did not eat food, snake is updated corresponding to direction input value. in order to prevent that new food locations and snake place are same, we also read color of lcd on new food locations. according to this, we can change again new food place.
Game Over Condition
with respect to new head location, the game check current head location and snake queue locations whether same or not. If they are in same place, game is over. Then screen covers black.otherwise we pass the other box.
When we try to play first time, we realized snake move so fast. To decrease speed of snake, we put a lot of counters which count between 0 and 240. In addition to that we set counter amount according to lenght. You can see formula of speed
How to run our snake game
You should have “mingwvars.bat”, “Snake-Game-code.s” and “Emulator.exe” , which is for Arm M0 Cortex, files. you can find these files on my github account. Then you should put these files in same file. You should write “cmd” at file search place . you can see figure-9.
Then you should write mingwvars.bat on cmd then push enter. Figure-10 shows it.
Then you should write emulator.exe then ,SnakeGame.s which is game code, on cmd then push enter. Figure-11 shows it. Then to start the game, you should push a key for 3 second 🙂