This slide introduct about pygame and show some technique that used in demo game Mario of Happycodyng Group.
More info at: http://tech.blog.framgia.com/vn/
2. Members
• Nguyen Anh Tien
• Nguyen Anh Tuan
• Cao Thanh Luc
• Nguyen Thi Huyen
• Nguyen Minh Tien
• Ngo Duy Trung
• Pham Ngoc Tam
• Nguyen Van Tung
3. What’s Pygame ?
• Cross-platform set of Python modules
• designed for writing video games
• No need knowledge about C, OpenGL, ….
• Pyweek Contest
– Write a game during one week using Python
5. Hello world in Pygame
import sys
import pygame
if not pygame.font: print 'Warning, fonts disabled'
pygame.init()
size = width, height = 640, 480
screen = pygame.display.set_mode(size)
while True:
if pygame.font:
# 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
screen.blit(text, textpos)
# change buffer
pygame.display.flip()
6. Mario Clone
• Purpose ?
– Learn basic game development principle
– Learn to code with Python
• Platform game
• (Try) minic the good old Super Mario Bros
• New features ?
7. Sprite (1)
• 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))
8. Sprite (2)
• self.image
• Crop to each frame
• Change and blit it on screen according to
object state