Sunday, 15 July 2012

Pygame Basics

        Pygame is a cross platform set of python modules designed for writing video games. It provides simple libraries, with the intention of allowing real time computer game  development without the low level mechanics of C programming. We can draw simple geometrics figures like rectangle, square,  polygon or circle. A sample syntax to draw a rectangle of length and breadth 50, 100 respectively is: 
                               pygame.draw.rect(screen,(0,0,0),(50, 50, 100, 100))
                               pygame.display.flip().
        Here screen is the surface on which the figure gets displayed or the basic background, (0, 0, 0) stands for the color of the rectangle to be drawn, flip() updates the full display surface to the screen.

The screenshot shows the output of the code I wrote to draw a rectangle.







  PYGAME ESSENTIALS

Pygame program to work the most essential things to be included in the program are:-

  1. import pygame module.
  2. initialize pygame using pygame.init().
  3. you need a display screen to display your figure. Select a background color and also the size of the screen for your figure.
  4. RGB color scheme represented by the tuple(0,0,0) which stands for black and (255,255,255) for white. Any combination in the tuple give you different colors.
  5. the figure to be drawn. 
  6. display the figure using pygame.display.flip().  
Using pygame you can also import images, audio, video files and texts to make your game look more interesting! 
  

No comments:

Post a Comment