Python Retro Pong Game

Python Retro Pong Game

After a lot of full stack projects in Java and still a bit mentally exhausted from exam week, I wanted to take a break from Java but still code a bit. My personal projects are all planned out in Python and I paused them all during Java exam week. In hopes of motivating me to get back into my Python projects, and also back to sharing my Java projects, I took the weekend 95% off from coding.

I wanted to code during the weekend but I wanted it to be fun and have nothing to do with my personal projects or classwork.

This is where the Python retro pong game comes in!

The Tutorial

This was a fun and easy YouTube tutorial from freecodecamp by @TokyoEdTech and you can check out my README file in my GitHub to find a link to his video, along with the link to where I acquired sound effects, as well as the entire project code. In the tutorial, you use turtle vs pygame. Turtle is supposed to be easier and beginner friendly for small and simple games like the retro pong game.

Issues

The tutorial was less than an hr and it probably took me, casually coding, about 2 hours. I was struggling for 30 minutes at the end because I was unable to play the sound effects using the os module. I tried playsound module which then did not work either. It turns out that even though I was referencing the correct file name in my code, I had placed the wrong file in the project folder so the project was unable to find it. Once I fixed that, both os module and playsound modules worked.

However, the playsound module has a delay in playing the sound effect and then freezes the game and/or crashes the game. I did not want to debug that for this simple tutorial so I went back to using the os module, now with the correct file in the project, which worked and has an easier fix for delays where you just add the "&" symbol at the end of the file wherever you use it as follows:

The reason I wanted to use playsound was that using afplay is for Mac, I believe. That said, I think that means this line of code would not work in a system that is not a Mac OS which would cause the game not to play the music. Linux uses aplay, without the f, which was mentioned in the tutorial.

Notes

If you do check out my code in GitHub, you will notice my notes. This was my first game app and my first time using the turtle library so as I was watching the tutorial and following along, I did include some notes for myself which is a good thing to do in your own code! Doing this when something is new to me has helped me as I reference past code when creating projects to see how I did something and why I did it a certain way or what the heck a line of code does.

It was a lot of fun using the turtle library and seeing what you can do with it.

Demo

I included a demo so you can see what the game looks like when it runs! You can play around with the speed of the ball and other attributes of any object you create in your code. Try it out for yourself!