India

ZestyBeanz Technologies Pvt Ltd 4th Floor, Nila, Technopark Thiruvananthapuram,
India – 695581
Phone: +91 471 4063254
Fax : +91 471 2700171

   .

ZestyBeanz Technologies Pvt Ltd
61/3236, Manikkath Cross Road
Ravipuram, Kochi, India - 682016
Phone: +91 484 4063254

  UAE

Zesty Labs
Office # 2003, Millennium Plaza Building
Sheikh Zayed Rd, Dubai, UAE
Phone: +971 4333 2222​
Mobile: +971-52-7553466

  Germany​

ZestyBeanz Technologies GmbH
Reuterstraße 1
90408 Nürnberg
Fon: +49 911 4801 444
Fax: +49 911 4801 445

Contact Form


omalbastin's picture

Developing a Game in Python using Pygame Module

          Everyone like to play games. If we start to play a computer games sometimes we don't quit the game until we finish it. Game can be developed in  any language. I am using python for developing a game. Usual python language can be used for developing textual games. For developing graphical games we need a special module in python  called pygame.

       As the first phase of developing the graphical game we have to make a game plan and then import the pygame module and necessary modules needed for our game.

                             

Then set up the pygame using pygame.init(). If we want to use sleep function or clock then we have to initiate them also.

                            

Next step is to set up our output window. For this we are using pygame.display.set_mode().  We can also provide a caption for our window using pygame.display.set_caption()

                  

Now set up the color variables. Each color can be created by a tuple with three elements. The three elements are red, blue and green each starting from 0 to 255. To create a black color we have to provide tuple as (0, 0, 0) and for white (255, 255, 255). And thus we can create any color.

                                    

If we want to add a text, then first define the font. Then provide the text. TextRect will help to select a rectangle space where our text will be printed. 

                           

We can fill a background color using

         

Five arguments for drawing a line. First is window surface, second color, third coordinate (x1, y1), fourth coordinate (x2, y2) and finally the width of the line. Like this we can also draw circles, rectangles, ellipse etc.

                      

The keyword blit is used to print the text inside a rectangle which we had already created. pygame.display.update() function is needed to print every operations that have been done. Without this function nothing will be printed. This is because when we create a new object it take a small delay in drawing each object to the screen. So the update function helps to print at the end of definitions. If our game has a game loop - an infinite loop, then this update function will be inside this loop. A user can provide request using pygame.event.get(). On each loop each event is processed and produce a output according to the event.

Reply

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo], [[foo]]. PHP source code can also be enclosed in <?php ... ?> or <% ... %>.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image. Ignore spaces and be careful about upper and lower case.