My Adventure of Making a Snake Game with Javascript

Ever since I was a kid, I've always been curious about making games, and I wanted to make my own one day. After spending so much time in the software industry, I asked myself why I shouldn't do it anymore. This way, I'll be able to both improve my Javascript skills and explore the software development process in a way I've never seen before.

Before I started coding the game, I started thinking about what the snake's movement algorithm would be. Some of the first options that came to mind were scanning the entire game board with each move, keeping the coordinates of each snake cell in an array, and updating old and new cells as it moved. Ultimately, I realized that deleting the snake's last cell and adding one at the beginning would be the best option.

First, I created a snake object and wrote the code to create the playing field. After creating the playing field, I found a nice font for the game and added it. After writing the code to create the snake and place it on the playing field, I wrote the algorithm to make the snake move.

When I first wrote the snake's movement, it kept moving out of the game area and could move back in. For example, when the snake was moving up, pressing the down key would move it back in.

First, I wrote code that would ensure that if the snake reached the edge of the playing field, it would continue to the other end. So, for example, if the snake reached the left edge, it would enter the right edge.

Next, I wrote the code to control the directional button, which moves in the direction the snake is moving. So, for example, pressing down on the button while the snake is moving upwards doesn't do anything. Then I added the ability to start and stop the game.

At that point, I stopped paying attention for about a month or two. A lot of different thoughts and things came into play.

Today, I remembered the game again and started playing it again. Finally, I finished the game by adding the bait, the game score, and the ability to manage game settings.

I really enjoyed making this game and I'm excited to see the end result. The only problem is that if you press the arrow keys too quickly, the snake will start doing crazy things. I think it's due to the game's frame rate, but I haven't figured it out yet.

My next goal is to write a Tetris or simpler game than Tetris.

The game from here you can play.

Codes from here You can check.

1 2 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

1 Comment
Newest
Oldest Most Voted
Inline Feedbacks
View all comments