KEMBAR78
Game Development with Pygame | PPTX
Game Development with Pygame
HappyCodying Group
2014/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 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()
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 !!!

Game Development with Pygame

  • 1.
    Game Development withPygame HappyCodying Group 2014/03/29
  • 2.
    Members • Nguyen AnhTien • 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
  • 4.
    Pygame’s core module •pygame • pygame.Surface • pygame.Rect • pygame.sprite.Sprite • pygame.display • pygame.event • …
  • 5.
    Hello world inPygame 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) • Coreclass 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
  • 9.
    Sprite (3) • self.rect-> rectangle • Used to check collision with other object
  • 10.
    Map • TMX file(Tilemap XML) • Tiled (www.mapeditor.org/) • Pygame: TMX library written by Richard Jones Tileset
  • 11.
    Map with layer •Z-order • Background layer • Midground layer – Mario – Turtle – Coinbox, Coin, …. • Foreground layer
  • 12.
    Map with layer Backgroundlayer Midground layer Trigger layer Foreground layer
  • 13.
    Trigger Layer • Invisiblelayer • Hold information of Object – Start position – Custom properties • Flower : Color • Coinbox: HIDDEN, SECRET, BLANK – What contain in coinbox : Mushroom, Star, … • …
  • 14.
  • 15.
    Time for Demo! Soure code: https://github.com/vigov5/mario_game/
  • 17.
    Thank you foryour listening !!!