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.
ahmed: Now set up the color variables. plagiarism checker Each color can be created by a tuple with three elements.".
Leave a Reply