Games with Pygame

We now have a basic idea about python programming as we had discussed lot of concepts and programs in my previous blogs. As suggested by my brother, I think now it is the time that we can go for advanced topics like data structures, networking, game development etc. We created 2 small games with the help of turtle interface, but we can also make real games with graphics in python. So the first step that I took towards advanced python was to build a game in python. So I started reading “Making Games with Python & Pygame” by Al Sweigart, which I was able to find online easily. So today we will see how we can install the pygame library and also about PIP. Below is the list of some of the games which are written in python or they use some of the features of this language:

https://wiki.python.org/moin/PythonGames

All the games are written in python with the help of pygame library which we have to download as it doesn’t come during the time of installation. So we have to first download the library and then install it using the pip. So what is actually this pip??? The pip is a package management system which is used to install and manage the packets/libraries written in python language. So in simple terms, it is like an installer and it will install the packages which are not present by-default in our python. PIP can sometimes be abbreviated as Pip Installs Packages or Pip install python, but there is no official full form for PIP. In python 3.6, we have pip3 which is used for this purpose. To install any package, the syntax is:

pip3 install package_name

After this, installation will be done and you can check your files in Lib folder inside site-packages. But firstly we have to download the pygame package as per our system requirement. For this, google ‘Unofficial Python Binaries’ and click on the first result which appears. Then search ‘pygame’, as that page will have a lot of data and it will be difficult to find manually. Then we can select and download the package as per your choice shown below:

cp 27/34/35/36 indicates the python version as 2.7, 3.4, 3.5 and 3.6. win32 and amd64 indicates whether you want for 32 bit or 64 bit, so download the package carefully.

I have a 64 bit operating system but the 32 bit with python 3.6 package was working perfectly in my PC. After downloading the package copy the package in the script folder of python. Then click the right mouse button while holding the shift key and we click on the option “open command window here”. Then a command window will open where we have to type the command for installing a package as discussed above and we can get the result as:

For typing the full name of the file, just type first few characters and then press TAB, whole file name will come automatically.

There are some of the picture and sounds required for the coming programs which you can download from http://invpy.com/downloads/, it was specified in the book. I have pasted the link for a video tutorial on how to install pygame module, if you want you can go through it. We will continue with our Sfirst game in next blog, till then keep coding…

https://vimeo.com/235729449

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.