Skip to main content

SNAKE GAME in PYTHON

                    


So things began when I started my O'levels. we started studying computer science which I literally loved. At that time I was just finding a simple project to enhance my skill in python. I already had some basic understanding about python's syntax, I gained that through watching YouTube videos of course. Out of nowhere while again watching YouTube vids I came across this channel called Dani and another called polymars these guys were expert in game development and I thought I could do that too.

I was 16 at that time and I just started searching beginner game dev ideas in python and I had this Idea of snake game. It looked like a huge project considering my little knowledge about coding and programming. However I went on and started searching 'how to code snake in python'. I read articles and stuff and got this initial understanding that python has modules and I will be using pygame.
That was it I started reading pygame docs...….but to legit no use because I was not able to understand a bit I read in its docs and hence I went on to my old buddy YouTube and started watching pygame tutorials and it took me a week to just initialize a screen in pygame and add a 2D square in the middle. After setting up I had to stop my exams were near and I had to study.
A month later when I got back I had legit no idea about what I had written in the code and how the heck was it even showing a square up on the screen. it was a clear indication that I had to read articles and watch vids again. nevertheless in less than 3 days I knew everything and was moving forward now. next thing was to simply add inputs so that my square snake could move. It was pretty simple and I was able to move on to create a smaller box on the screen I defined as snake's food. now I felt that I was progressing. the next thing I did was to randomize the position of the food. After research I did that by using random module of python. at this time as soon as I launched the game the food was randomly placed and my snake was placed in the center and was able to move in all directions. after this I again lost interest in development and got back to studying.
It was the mid of second year of O'levels and I showed my game to my best friend in school and my Computer's Teacher both of them were fascinated and my sir appreciated me which turned out to be a motivation and I got back to the development. little did I knew, things got freaking worse I mean now I had to do two things one to make the snake eat the food which was a not that big of a problem because it was just that as soon as snake's x and y coordinates were same as the x and y coordinates of the food I added the food randomization line so at that instant the food would again be randomly placed and also add 1 to the score value. It was still not a problem. The real issue was to make the snake's length grow as soon as it ate. now growing its length was something like I made snake's body a list and appended his head again and again into it as it ate and added those blocks at his back constantly something like that and I had a growing snake (this logic was not mine i simply copied the code haha..). 
fast forward to O3 and I had again forgotten the game and was studying hard for my final cies I don't know why, but this time I started development as soon as cies started and continued development throughout. But the thing was that during those hard study sessions I found that I was loving development so as little time I got between those days and nights I continued building game and things were not simpler....Because in one month of cies I built two menus for the game designed its art including buttons and title. Also developed a function to store and show new highscores for the game. and yeah the game was complete.
what started as a simple project turned out to be a professional game with menus, art, music and gameplay! 
It took three years of olevels and was completed on 26th may 2022. A day before my Maths cie and immediately I created an itch.io page. you can visit it and download my game here: https://1571alli.itch.io/retro-snake 


Comments

Popular posts from this blog

TCP & UDP

TCP stands for "Transmission Control Protocol." it is the special way in which computers talk, communicate and share information. in simple words TCP is used by computers to send and recieve data. Now comes in TCP connections. TCP connection is established between two computers when they want to talk and communicate i.e they want to share data. In TCP connections there are servers and clients, Imagine the client as a person who wants to ask for something, and the server as the person who provides what the client needs. Clients send requests to the server, asking for information or help. The server, on the other hand, receives the client's request and provides the requested information or service. Before the client and server start exchanging information, they perform a special handshake. It's like when you meet someone new and say "hello" before you start talking. the client sends the request to establish connection, the server checks it and acknowledges it ...

ARRAYS IN PYTHON

An array in python is a data structure that can hold more than one value at a time just like a list but their is a slight different in both of them which is discussed below. arrays can hold values of only single data type e.g integers or strings. All values in an array are indexed hence have their own unique address by which they can be called at any time. Now the indexing of array values in python always starts from 0, so if I have an array starting from 1 till 100 the first value of this array i.e 1 will have its index number as 0 and the array's last value i.e 100 will have an index number of 99. to visualise it we can say: array:     1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 ,9 , .........., 100           array's       index  :  0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , .........,  99 So now you can easily see how arrays are indexed in python so If using python code which is (discussed below), call out a specific index number it wi...

WHY PYTHON IS BETTER THAN ANY OTHER PROGRAMMING LANGUAGE?

Python is a really popular programming language and there are reasons for this popularity. python is extremely easy to learn because it is beginner-friendly language with really simple easy to understand syntax, readability and closeness to english language. e.g if you want to display something on the screen; in python you will type: print('yourtext') and boom you have displayed your text onto the screen whereas in java you would have to type: system.out.printIn('yourtext') so clearly you can see the difference how simple it is to code in python. further python code is always relatively smaller and cleaner to look at than other programming languages. this program adds two number in python: num1 = 1.5 num2 = 6.3 sum = num1 + num2 print('the sum of', num1, '+', num2, 'is: ', sum) this program adds two numbers in JAVA: class Main {   public static void main(String[] args) {          System.out.println("Enter two numbers");     int first =...