So I’m teaching a python game development class and I am using the pygame library. There are so many options these days to develop games – unity, unreal, twine, phaser. I was thinking why am I using pygame??
Well I am teaching a “python” class, so there is that, and we can publish our game to the steam store, so that is cool. But pygame is a pretty easy to use and robust. For the class we are using the pygame book at Invent with python.
The core of pygame is a loop that monitors events and updates the screen. It is a while True loop that monitors events, updates the display object and then updates the display. To draw an image, like a jpg, on the surface you use the blit method:
DISPLAYSURF.blit(img, (x,y))
Blit is an ancient command, as I tell my students You look in all sorts of graphics frameworks and languages and you see blit! Blit originally stood for bitmap graphics terminal and it was a different type of computer terminal that could draw bitmap graphics. In graphics programming it also refers to “bit-boundary block transfer”, this is where you transfer a block of memory from one location to another.
In graphics programming you can optimize your library by having a sheet of sprites of graphics that you then draw (blit) to the screen. This is an example of one of the sprite maps from the legend of zelda 1:
First we blit the image from the spritemap, then we blit that image to the pygame surface:
import pygame
spritesheet = pygame.image.load(filename).convert()
rect = pygame.Rect(rectangle)
image = pygame.Surface(rect.size).convert()
image.blit(spritesheet, (0, 0), rect)DISPLAYSURF.blit(image, (x,y))
With this sort of framework I think there is interesting work to be done to sort of remix and reinvent existing games. What would a mashup between zelda and mario look like? What would a game version of fan fiction look like? We are playing with the graphical elements but we can use new different game mechanics and create a new story.