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

Welcome!

This is a quail's nest. A very rabid quail. This blog serves to document my projects and my slow descent into insanity. If you're into that kinda stuff, you could follow, but honestly, why would you want to? 

E.D.D.I.E Glasses

Say hello to Frankie. He doesn't do much. Yeah. I kinda realized how I never ended up naming the project. I wanted something like EDITH, but I wanted it to be different enough to feel like its own thing. So we're gonna stick with EDDIE for now. As always, I have some new plans in mind for the project. That's the thing with us procrastinators, we're really good dreamers, but when it comes to execution, we rarely give our full 100% effort. On a side note, Tim Urban has really good posts on the topic of procrastination over on his blog Wait but Why which you should check out if you've got some free time and want to have a good laugh at people like me. Tim Urban's Ted Talk Ok so, in my first post, I mentioned how I was basically trying to recreate a project from one of Jlaser's videos.  I also kinda made fun of myself in my earlier post for basically copying most of my projects from other people's existing projects. As I've gotten slightly more experien...

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...