Game Development with Pygame
-
Upload
framgia-vietnam -
Category
Software
-
view
323 -
download
3
description
Transcript of Game Development with Pygame
Game Development with Pygame
HappyCodying Group2014/03/29
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
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
Pygame’s core module• pygame• pygame.Surface• pygame.Rect• pygame.sprite.Sprite• pygame.display• pygame.event• …
Hello world in Pygameimport 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()
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 ?
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))
Sprite (2)
• self.image
• Crop to each frame• Change and blit it on screen according to
object state
Sprite (3)
• self.rect -> rectangle
• Used to check collision with other object
Map
• TMX file (Tilemap XML)
• Tiled (www.mapeditor.org/)• Pygame: TMX library written by Richard Jones
Tileset
Map with layer
• Z-order• Background layer• Midground layer– Mario– Turtle– Coinbox, Coin, ….
• Foreground layer
Map with layer
Background layer
Midground layer
Trigger layer
Foreground layer
Trigger Layer
• Invisible layer• Hold information of
Object– Start position– Custom properties
• Flower : Color• Coinbox: HIDDEN, SECRET,
BLANK– What contain in coinbox :
Mushroom, Star, …
• …
map: underground.tmx
Trigger Layer
Coins
Mario
Bricks
CoinBox
Item Mushroom
Platform
Time for Demo !
Soure code: https://github.com/vigov5/mario_game/
Thank you for your listening !!!