Source: Google Images

Fun with Python Play

Joshua Fitzgerald
The Startup
Published in
3 min readJun 25, 2019

--

If you’re a Pythonista then you might be excited to hear about a library available called Python Play. Making games with Python Play is simple and easy. Repl.it has a newsletter, and in this week’s edition there was a story about a few engineers leading a workshop using Python Play (one engineer, Timmy Chen, made a cool game you can view here). The documentation shows how simple and easy building a serious game with Python Play could be. The library is an excellent choice for young, or inexperienced programmers to dive into Python and start building.

In the Python Play library images and text are referred to as sprites and they have functions that you can pass them to make animations like moving, and rotating simple and easy. There are also various properties that can be defined to make common aspects of a game easy to implement; for more advanced implementations Pymunk is used to add physics to objects allowing collisions and other experiences.

In the README for Python Play there is an example game that shows the basics of how to use the library to build games.

Example Game from Python Play README

In this example you can see that the cat object is created as a text object is set as the object that will be animated for the game. The cat.show() function is called to make it visible and then the program is suspended for a specified time, then the cat.hide() function is called. The cat object is only able to be clicked when cat.show() is called.

If the user is able to click on cat while it is visible then win.function() will be called and the text object created that looks similar to a cat will be replaced with the victory message 'You won!' . This game is simple and easy to build. The text and settings are easy to manipulate, making it a great introduction into the functionality of the library.

Python Play is also intuitive when it comes to mouse events. The library includes most functions you would need to use the mouse as a main component of a game. The same is also true for keyboard events. Python Play handles keyboard events in a easy to understand way, allowing for key combinations events to be implemented in a single line with one function play.key_is_pressed(*'key') where key will be a defined as a key on the keyboard; multiple keys can be passed as arguments in the function as well.

Summary

The Python Play library allows for substantial games to be built easily with the library. I would encourage everyone to give it a try, especially if you have ever programmed with Pygame.

Check out the example game in the Repl below. Adjust the settings and see if you can still beat the game if the cat shows for less than 0.6 seconds. If you do give it try, post a link to your Repl in the comments.

Repl of the Example Game Python Play

--

--

Joshua Fitzgerald
The Startup

I am a software developer based in Houston, TX. I am passionate about ideas that make an impact. I tell stories about interesting and interactive technology.