Skip to main content

Python Snake

Snake LED Matrix Game - Hackster.io

The Snake game is one of the oldest and most popular mobile games that first appeared on a Nokia phone or something. So I set out to recreate that game in Python just for the joke.

I used Spyder.

Modules needed: i) Pygame
                             ii) Everything else is built-in.
Because I'm bad at initiating stuff, this program was also based on ( read as 'copied from') a YouTube video:


The basic code is the same, I've only made cosmetic changes.


Because this project was basically copy-pasted, I felt a bit guilty ( just a little bit). So I decided to try to add a rudimentary self-playing algorithm.

Basically, I tried to remove the 'game' part of The Snake Game and make it computer automated using a path-finding algorithm.

After hours and hours of searching, I settled on the A* path-finding algorithm to do the work. But I ran into more problems. The algorithm itself was copied from the web and it worked perfectly. The idea was to map out a short path between the head of the snake and the fruit and have the head of the snake follow that path.

The path generated was perfect, but I wasn't able to get the snake to follow the path properly. The snake kept running around like a headless chicken. So I gave up.

Then I decided to add multiplayer capabilities to my game. So I added 4 new parameters to my 'snake' class that details on the movement keys that can be used. For example, the given parameters for one snake can be the arrow keys while they can be WASD for another snake.

But something really unexpected happened.


Somehow....the snakehead had detached from its body. That's not what it was, but that's what it looked like. On further inspection, I found out that the two snakes remained the same colour, the second snake followed the first snake, there was no reaction to the input of the WASD keys and the hitbox on the fruit wasn't responding at all.

So...I left that too. For now.

As it stands now, I want to continue on both paths I set out on. I aim to create a working .exe file that plays like a real game ( Interactive GUI, multiplayer and single-player options and 'play against computer' options, etc.)

So I'll get back when I calm down from the snake detachment I just witnessed. 





Comments

Popular posts from this blog

Student Website

This is a different type of Django. The hardest part of writing these blog posts is deciding the picture to go along with them. You know what's the fun part? Creating labels. I discovered Blogger allows you to categorize posts using labels and I've been using them vehemently ever since. I'm a sucker for alliteration, and using it on creating labels is by far the best thing Blogger offers. It was probably a bad idea to create this blog using Blogger. Now don't get me wrong, I love the innate simplicity of Blogger, and this thing isn't supposed to be professional anyway, but Blogger is so old that people don't realize that blogs can be followed to get updates on new posts. Even I didn't know that until like a month ago.  But I guess the purpose of this blog isn't to attract followers, it's to give me a platform to document developments on my ever-expanding list of incomplete projects. What new thing do I have now? Well, I got interested in web developm...

CHEAT!

I literally have no idea where this picture is from. Hello, hello, hello and welcome to CHEAT! , the only game show where you're rewarded for cheating! I tried doing a gameshow host impression but since I don't watch any TV, I have no idea how gameshow hosts act. Okay so yeah. Not really a game show, but I did come up with an idea for a verbal game. Before I get into the specifics on how the game is played, it's better to define some terms first. Host - This is kinda self-explanatory. The host is the one who'll be asking questions. Except for this time, the host isn't permanent. Every round the host changes. Players - Players. Nothing else to it. Candidate - The player who is being questioned by the host. The way the game works is that a player is selected to be the host. This can be completely random, or it can be turn-based, that part's up to you.  Once the host is selected, he/she now has to think of a topic or an activity in which it would be difficult and/o...

Python : The Game

Well, it finally happened. I finished a project for the first time in my life. I never thought this day would come. I have so many people to thank. First and foremost, Frankie, with his soulless eyes, kept pushing me to achieve far and beyond.    That's the look of utmost happiness The Python Snake game project was my Grade 10 Final Project submission. Back then it was just a rudimentary shell of what it is today. It only implemented the single-player mode of the game, and it didn't have any of the bells and whistles it does today.  So here's my final post on this topic. Initially, I didn't plan on working on this project. I didn't feel like creating a game for the second time and decided I wanted to do something with a real-world value.  My plan was to expand on the idea of the COVID Calculator I had mentioned in one of my previous posts. With all this stuff going on in the world right now, what could get more 'real-world' than a program that predicts the ...