ADAPTCHAR: My experience using Pygame

Over the past few weeks I gave myself the goal of starting my Student Innovation Project (SIP) and getting far enough with it to have something presentable for the SIP Reaffirmations. Since the aim of my SIP was to develop AI for RPG party members, the first thing that I had to do was find an engine that could benefit my SIP’s development process.


pythonI first started with Unity, which I had minimal experience in. While I did have some knowledge of programming in C#, it was not that expansive. I did, however, have experience with 2D game development! On top of that, Unity did have the capability of using Tensorflow, which opened up the possibility of developing machine learning within the engine. This seemed like the best choice, but the issue that ended up deterring me from using Unity was the sensitive and extremely complicated installation process for Tensorflow. It took me days to get anywhere with installing Tensorflow on my computer, and with every step came its own set of issues that took hours to resolve. That, alongside the incredible amount of other applications that you needed to install in order to complete a single step of the installation process simply deterred me from continuing with it.

After trying to download Tensorflow, I looked for another way to start development on my SIP. This then led me to Python and its Pygame library. I had much more experience programming in Python than in C#, but I had no experience with using Pygame. I have played games that were made in Pygame, and even saw one of the professors here use Pygame as a tool for developing a visual novel game. However, having never actually programmed using its library, I was pretty intimidated, but when it came down to the point where I had only a few weeks before the SIP Reaffirmation, I had to make a choice.

Pygame

The first moments of using Pygame were pretty easy, actually! Getting a window up and changing the inside color of that window was easy, But when I started trying to place sprites on the screen, I started experiencing some issues. As I said before, I had no experience using Pygame. I was used to just picking up sprites and dropping them into the scene of an engine, so when faced with having to manually load sprites using Pygame, I struggled a lot.

I decided to look up some tutorials to help me out, but I couldn’t really get a grasp on what was happening. Some tutorials showed me how to draw rectangles to the screen, but it was hard to apply the same procedure to actual PNG files/sprites. Some used classes in their methods, while others just used pygame.image.load to do it, (which was the method that I went with since it was the easiest to grasp), and others used a sprite sheet (which was apparently the smart way to do it). In the end, there were so many ways to do it, but not many of them really explained what was happening or what I was supposed to do clearly. Trying to find a tutorial that I could understand felt like a wild goose chase around the internet.

mygame
In the end, I was able to achieve what I wanted and gained an understanding of how to resize, position, and update these sprites. Despite the amount of time that it took for me to understand what I was supposed to do, the process of actually loading sprites was not that complicated. Still, it took a good while for me to understand what I was supposed to do, and if I were to have gone further with Pygame, I know I would have run out of time to do my SIP. Getting the sprites that you see in the picture above was all that I really needed from Pygame at that moment. So, since I got that environment running, I just had to move on to actually getting the actual innovation ready for the presentation.

While what I did with Pygame was simplistic, my overall experience using the library showed me that there are numerous other options for game development out there that could prove to be more worthwhile than Pygame, such as Unity, GameMaker, and Construct 3. With these engines, in most cases, all you have to do is drag a sprite into a scene and you’ll have a sprite witUnityhin your game, unlike in Pygame, where you have to do multiple operations just to make a sprite appear and look right on the screen. I am not saying that Pygame is unusable, but it is just harder to achieve some things that are otherwise easy and instantaneous with other engines.

But here is the thing: Pygame is NOT an engine. It’s a library that enables you to create games. You would have to use this with a Python editor which, from what I know, wouldn’t have a scene editor or hierarchy or anything of the sort! So to expect to see what you would see in Unity in something like Pygame is pretty outlandish and unfair to the library.

With that said, Pygame is not all that bad. It uses Python, which means that whatever is built within it can be used on a multitude of platforms. No worrying about the platform issues that Unity and Unreal occasionally run into; Python/Pygame has that going for it from the get-go. And, as I said before, the process of actually loading assets was not that complicated. While it is not as easyConstruct as getting sprites working in Unity, it still only took that few lines of code.

Lastly, let’s talk about Pygames possible applications. While it was made to be used to develop games, it pretty much opens up the ability for programmers to visualize what is happening within their code. Someone has previously utilized Pygame for their SIP where they were able to bring up a map that would auto-generate red points when their code detected something online. The Pygame library is flexible, so you can do a lot with it.

In the end, Pygame has its faults, but it also has its successes. It also has plenty of competitors out there. What matters is whether or not using Pygame or those competing game engines helps you achieve what you ultimately want for the development of your project. Let that be the defining part of your decision. From my experience, Pygame takes a bit to get used to, But, when it comes down to the fact that Python is the best language for AI and how Pygame is the only thing out there that can turn my SIP into an actual game that people can play and enjoy, it seems like I’m going to be sticking with Pygame until my SIP is done.

 

A special thanks to Jordan Brown with helping me revise my blog. Without you, I would not have been able to get the point across as effectively as I wanted.

 

References

 

Real Python. (2018, June 11). PyGame – A Primer – Real Python. Retrieved May 05, 2019, from https://realpython.com/pygame-a-primer/

 

Craven, P. V. (n.d.). Program Arcade GamesWith Python And Pygame. Retrieved May 05, 2019, from http://programarcadegames.com/index.php?chapter=introduction_to_sprites&lang=en

 

Bradfield, C. (2016, August 15). Pygame Lesson 1-2: Working with Sprites. Retrieved May 6, 2019, from http://kidscancode.org/blog/2016/08/pygame_1-2_working-with-sprites/

 

Baumgarten, P. (2018, January 23). Learning Python 12: Using sprites (images) with Pygame. Retrieved May 6, 2019, from https://www.youtube.com/watch?v=2ClnBpKGx7o

 

 

Posted on May 8, 2019 2:51:00 PM by Hakim Ottey in Advancing Computer Science, in Student Innovation Project, in SIP, in university for technology, in Advancing tech education

Hakim Ottey

Written by Hakim Ottey

Advancing Computer Science major and Student Ambassador at University of Advancing Technology (UAT)

   

Email me when there is a new post.

I'd like more information about UAT

Lists by Topic

see all

Recent Posts

Posts by Topic

see all

Posts by Author

see all