Recreating Snake, the Goofy Five Day Journey

Day 1 - Humble Beginnings

The first day wasn't too bad, however I did forget a lot of stuff from the Kitchen Chaos Tutorial that I watched, and that probably means I didn't learn anything from that tutorial. But I like to think that the tutorial helped me reach the intermediate-ish stage of game development where I can actually make my own games without too much help from AI or any forums.

Starting a project from scratch also just felt really weird. When I was following the tutorial, I didn't have to think much about how to organize everything, all I had to do was do exactly what the guy did. Now however, I had to think about exactly what I should name my scripts. And let me tell you, figuring out what to name your first script feel like trying to choose a perfect name for a new character in a book, its practically impossible. After some hard thought, I finally named it "SnakePlayer" (of course I changed it later on in the development process). In this script I was able to make my snake head move up, down, left, and right using the arrow keys. I decided that was literally it for day one.

Day 2 - Da Food

On day two I decided to add in the food that the snake eats to become longer. Now this was a bit harder than I realized because in the tutorial I followed, we talked nothing about colliders, and so I had to figure out that functions for the colliders are actually built in and you can just call it within the GameObject that has the collider. After figuring that out, the snake could finally pick up the food. There was a problem though, whenever I tried to destroy the food after it got picked up, it would throw a MissingReferenceException. I can't recall how I fixed it, but I think it had to do with me putting something in a Start function and not an Awake function.

Fixing that took a good five minutes or so, but I got the food working to the point where after the snake head touched it, it would create a snake body. This snake body would only spawn in the middle though and wouldn't follow the head. After feeling really accomplished with myself I headed into day three, ready to truly start, but I had no idea what I was about to go up against.

Day 3 - Painnnnn

On this day I came back to the game to work on the snake bodies following the snake head. Now this should be really simple right? Wrong. Or at least because I was heading in the wrong direction. To understand why I struggled with this we have to look at how I did the snake head movement

.
Essentially I would take the player input, match to a direction of movement, then make the snake head's position like this equation:

new position = position + action (the direction of movement)

I know, really professional. Anyways this was how I applied the movement to the snake head. The idea I had was to apply the same movement direction to the snake body that the snake head had. Of course this is slightly flawed because if all the snake bodies followed the head, well then it would start to look like 
Tetris. My first thought was to have each snake body contain the last action they have done, and so each snake body would do the last action that the snake body did in front of them. This however did not fix it, and instead did the exact same thing where the all of the bodies followed the head.

Before I moved on to continue fixing it, I changed the movement system to where it would constantly be moving the snake, and depending on what key you press all it would change was the action for the snake head (basically before it wasn't the actual snake movement where you press an arrow key and it goes on in that direction forever, then I made it the actual snake movement)

After making that movement and fixing some other bugs, I didn't want to tackle the problem that day so I held it off till the next day.

Day 4 - The Discovery

Today, I finally got the movement to be working. The real solution wasn't applying the action that the snake head did to the snake bodies. Instead the solution was saving the snake head's and all of the snake bodies' last position, then every time we move the snake, we update the bodies' positions. I was a bit frustrated that the solution was much easier and not as complex as it was. However that is part of the game development process where you have to keep problem solving until you figure it out.

Then I made a lot of things:
  • Added a simple thing where whenever the snake goes out the wall, it comes out the other side.
  • Created it where the food would spawn after being eaten, and making sure that it wouldn't spawn on the snake. (However I forgot to account for a food spawning on a food) 
  • Made the Game Over screen which would trigger whenever the head collided with a body.
Some of them had bugs the first time I tested it, but they were easy fixes. However the next thing I attempted was something that I decided to entirely scrap.

I was trying to make a play again feature where after your snake died, you could play again via a button on the game over screen. Loading the scene was pretty easy, but the part where there were errors saying that there was a MissingReferenceException was insane. The reason these errors were happening was because after it reloaded the scene, the reference to the snake head and snake body that the script has are destroyed, thus throwing the MissingReferenceException error. After turning to the internet and attempting all of the easy fixes that I could do (which didn't work at all) I decided to scrap the play again button.

Day 5 - Final Touches

Today nothing much happened, all I really added was a score UI which increased whenever you ate a food. 

The last thing I did was adding snake eyes to the head and making the head look at wherever it was going. I decided it was all the polish that the game needed.

I made a build of the game and saved it to my computer, I also made another build to upload it to the web (a build of a game is where you take it out of the editor, and make it into a playable game)

Here is the final game if you want to play it: https://thecodingtaco.itch.io/snake-recreation

Reflection and Final Notes

Creating that game taught me a looottttt about game development. The first thing being that it is a lot harder than you think it is. Even after following a really good tutorial, you still have a lot to learn like learning the best way to organize your game for you. I also learned that planning your game is very important because if you want to implement something like the play again button. You have to structure your game to be able to do that function without having a lot of errors.

Another huge thing that I learned is that the first idea that you have to make the snake (or whatever you're working on) isn't always the best idea. In my case it was very far from close to the correct solution. Yet I also learned that stepping away and coming back can help you realize the correct way to do something, or the solution to a problem.

That's all I really have to say about my journey doing my first beginner project. I will have to say that watching all the devlogs on Youtube make it look easy, but the thing that they don't show is all the work that they have to put into making the game. The next game that I am recreating is flappy bird, so look out for that devlog!

Thanks for reading,
TacoDev





Comments

Popular posts from this blog

Welcome to my Game Development Blog!