Module for Making games in python : pygame

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.
  • pygame.init()
    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)
    
    

    Output
    (6, 0)
    it means initializing was successful.

  • gameScreen = pygame.display.set_mode([600,300])
    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:

pygame.display.set_mode([1280,760],FULLSCREEN)
  • pygame.display.setCaption(“game”)
    pygame.display.setCaption("game")

    This is used to set up your game title that will eventually appear on the title bar when your program runs

  • pygame.display.update()
    pygame.display.update()

    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

    pygame.display.flip()
  • pygame.quit()
    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.

 

This is Ashish Thapa. It's just a name after all. Just had a thought that our names should signify our situation and should be dynamic. What if our name upgraded with respect to experiences acquired.

1 Comment

Leave a Comment

Your email address will not be published. Required fields are marked *