A module built for building games which is easy to master. Pygame has certain important call functions that are needed to initialize for every python program that runs on it. These functions are the most important part of a program and even you want to build a 2d minecraft game or complex game such as GTA III. you would need these functions. So the base of every pygame program should look like this:
import pygame pygame.init() gameScreen = pygame.display.set_mode([600,600]) pygame.display.set_caption("Game") pygame.display.update() #you can also use pygame.display.flip() pygame.quit()
- import pygame
The module pygame is imported to be the part of the program you are currently writing.
Importing doesn’t mean initializing in pygame. so you need to initialize the pygame module using pygame.init().It returns a tuple that indicates success and failure. for example:
import pygame initialize = pygame.init() print(initialize)
it means initializing was successful.
gameScreen = pygame.display.set_mode([600,300])
it is used to set the size of the game window or gamescreen. set_mode() takes the parameter as list. here [600,300] is size of screen window and 600 represents horizontal pixels and 300 represents vertical pixels.
If you want to set the size of screen to 1280*760 and full screen mode . you can achieve that by:
This is used to set up your game title that will eventually appear on the title bar when your program runs
when you watch a video, you are actually watching the series of images that is being updated eventually over time. same case goes for the pygame. you draw something like drawing rectangles and show it to screen and when user presses up button then it should move up on y axis if you set the increment variable.pygame doesn’t update itself its screen . you have to say where and which part of a code should it update. there is another function which does the same thing
it says pygame to quit. usually this step is placed at the end of the program when gameExit is stated true by the part of program.