This program is a personal project when I was learning 'computer organization and architecture' in the second year of my Management Mathematics and Computing bachelors degree. The idea behind of this program was the classic "Snake" game. This program was made using Microsoft Visual Studio 2017's 32bit MASM architecture in protected mode (no interrupts) and the Irvine32 library.
- User may choose from three speed levels, level 1 to level 3, level 3 being the slowest.
- Each of the speed levels have a 40ms difference.
- A coin is generated randomly at the start of every game or when the snake eats the previous coin.
- A checking function is also created to make sure that the random coin doesnt generate on the coordinates of the snake.
- A new coin is regenerated if the current one is generated at an invalid coordinate.
- After the coin is generated, a loop will be initiated to detect for input and jump to specific functions according to the input.
- If no key is entered, the program will keep looping and waiting for an input.
- If the snake is moving and a valid input is not entered, the function will continuously loop and snake will continuous to move at the current direction.
- If the user enters a new input that moves the snake in a different direction, the program will jump to a function that changes the function of the snake.
- The head of the snake will be moved according to the user's last known input.
- The body of the snake will be moved to the coordinate of the unit before it (eg: the 3rd unit of the body will move to the coordinates of the 2nd unit of the body)
- When the Snake moves, the coordinate of the head is compared with the coordinate of the coin to check whether the snake eats a coin
- When a coin is eaten, a new unit is added to the snake to lengthen the snake.
- The new tail is at the position of the old tail, a new tail is added according to the direction of the old tail
- When the Snake moves, the coordinate of the head is compared with the coordinate of the coin to check whether the snake collides with itself
- Snake dies when it collides with itself
- A function loops through the coordinates of the body of the snake and compares with the head position to check if they collide.
- When the Snake moves, the coordinate of the head is compared with the coordinate of the coin to check whether the snake collides with the wall
- Snake dies when it collides with the wall
- A function compares the coordinates of the wall and the head to check if they collide
- When the game is over, a scoreboard is displayed to show the current score and high score of the user.
- The user can also choose to exit the game or restart the game.
- Input Validation is set to detect any invalid input and prompts the user to reenter the input if so.
Flowchart of this program can be downloaded here: snake game flowchart.pdf
Keys | Actions |
---|---|
w | Move up |
a | Move left |
s | Move down |
d | Move right |
x | Quits the game at any time |
enter | Pause, (w,a,s,d to unpause) |
(make sure that your capslock is disabled)
To start the game you will need to install the following items:
- visual studios (can be installed here)
- Irvine32 library (can be downloaded here)
- configure asm file, paste code in and run program
Although the program code for the master branch and the adv branch slightly differs from each other, both codes are completed and able to output and run the full program. The master branch is more basic and easier to understand whereas the code in the develop branch more compact and the end screen displays the high score as well. Feel free to check out both versions of my program.