Hello world in Pygame
if not pygame.font: print 'Warning, fonts disabled'
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
# render font and set position
font = pygame.font.Font(None, 36)
text = font.render("Hello World !", 1, (255, 0, 0))
textpos = text.get_rect(centerx=width/2)
# draw to screen
# change buffer
• Purpose ?
– Learn basic game development principle
– Learn to code with Python
• Platform game
• (Try) minic the good old Super Mario Bros
• New features ?
• Core class for each object in game
• 2 important properties
– image : what we see on screen
– rect : position and bounding box of object
• How to load and draw image ?
img = pygame.image.load(“mario.png”)
screen.blit.(img, (100, 100))
• Crop to each frame
• Change and blit it on screen according to
• self.rect -> rectangle
• Used to check
collision with other
• TMX file (Tilemap XML)
• Tiled (www.mapeditor.org/)
• Pygame: TMX library written by Richard Jones