Game Development with Pygame

17
Game Development with Pygame HappyCodying Group 2014/03/29

description

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/

Transcript of Game Development with Pygame

Page 1: Game Development with Pygame

Game Development with Pygame

HappyCodying Group2014/03/29

Page 2: Game Development with Pygame

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

Page 3: Game Development with Pygame

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

Page 4: Game Development with Pygame

Pygame’s core module• pygame• pygame.Surface• pygame.Rect• pygame.sprite.Sprite• pygame.display• pygame.event• …

Page 5: Game Development with Pygame

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()

Page 6: Game Development with Pygame

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 ?

Page 7: Game Development with Pygame

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))

Page 8: Game Development with Pygame

Sprite (2)

• self.image

• Crop to each frame• Change and blit it on screen according to

object state

Page 9: Game Development with Pygame

Sprite (3)

• self.rect -> rectangle

• Used to check collision with other object

Page 10: Game Development with Pygame

Map

• TMX file (Tilemap XML)

• Tiled (www.mapeditor.org/)• Pygame: TMX library written by Richard Jones

Tileset

Page 11: Game Development with Pygame

Map with layer

• Z-order• Background layer• Midground layer– Mario– Turtle– Coinbox, Coin, ….

• Foreground layer

Page 12: Game Development with Pygame

Map with layer

Background layer

Midground layer

Trigger layer

Foreground layer

Page 13: Game Development with Pygame

Trigger Layer

• Invisible layer• Hold information of

Object– Start position– Custom properties

• Flower : Color• Coinbox: HIDDEN, SECRET,

BLANK– What contain in coinbox :

Mushroom, Star, …

• …

Page 14: Game Development with Pygame

map: underground.tmx

Trigger Layer

Coins

Mario

Bricks

CoinBox

Item Mushroom

Platform

Page 15: Game Development with Pygame

Time for Demo !

Soure code: https://github.com/vigov5/mario_game/

Page 16: Game Development with Pygame
Page 17: Game Development with Pygame

Thank you for your listening !!!