Pygame – Game Module for Python

Python is a language which is easy to study and program. Development of games in Python is a easy job, as it provide a specialized game module named pygame. With usual Python modules we can develop only textual games. For the development of graphical games the pygame module is needed.

Let us see the common usage of this module with the help of some small examples.

There are two things to be imported for the use of pygame in graphical game development.

The first step to do is to set up up pygame.

Next step is to set up the window for the game. An object is created, for further use, deployment of some images to the surface can be made using this object

Color is given as a tuple with three elements. As it is tedious step to type the full tuple every time, we can create a constant which holds this tuple and can be used whenever needed.

If we want to add a text to the window, first we have to select a font style and a font size.

None gives the default font style and 48 gives the size. In-order to set up the text

An object of the text, textRect, is made.

To fill the background with a specific color

Geometrical figures can be drawn easily, a blue filled circle can be drawn as

In-order to print the text we have created to the window we have to use the keyword blit.

Until now nothing will be displayed on the screen. It will take time to draw something to screen. Thus if we try to draw on the surface each time we create a new object it will create a big delay. In-order to avoid this delay all the updates are written to the screen after a update keyword is used.

A game loop runs until the user explicitly tells to terminate. All the events occurred during a single iteration can be obtained using

If an explicit signal to quit occurs the window is shutdown.


About Odol Shinu

I've completed my B Tech in Information Technology in 2010 from Government Engineering College Sreekrishnapuram Palakkad under Calicut University.

Posted on November 11, 2010, in Python. Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: