SlideShare a Scribd company logo
Pygame - Game
Development
Matheus Melo
XIX PUG-PE
Schedule
 Introduction


 What   is PyGame?

 PyGame   essential Elements

 Developing     games with Pygame
What is Pygame?
 Set   of Python modules for writing games

 Compatible    with SDL

 Free   
Best Features
 No need to OpenGL setup
 Multi-core
 C/Assembler Core Functions
 Portable
 Easy to use
 Comunity
Problems
 Python     is slow 
     But you can do something to turn this out.


 You     write too much

 Isn’t   a Game Engine, it’s a library.
Essential Elements
   Surface
       What is surface?
       2D and 3D planes.

       Eg:
         tamanho = ( 640 , 480 )
         cor = ( 255 , 0 , 0 ) # v e rme lho
         superficie = Surface ( tamanho )
         superficie . set_at ( ( 10 , 20 ) , cor )
         superficie . fill ( cor , ( 11 , 21 , 50 , 50 ) )
         tela = pygame . display . set_mode ( tamanho )
Surface – Important Functions
 fill(   color, area)
      Fill a area with the selected color
 get_at(     position )
      Returns the color that was in the setted
       position
 set_at(     position, color)
      Set the color on that position
Surface – Color Depth
 256   Colors



 24   bpp RGB
    3 Bytes per color
Surface - Transparency
 ColorKey
     One color is chosen to be transparent
 Image    Alpha
     Can have his Translucency between 0 and
      255
     Can be used together with ColorKey
 Per-Pixel   Alpha
     Has a associated Alpha component.
     Cannot be used with another transparency
What is Blit ?
 Convert  the current Surface Color Depth
  to the next Surface Color Depth

 It   is a very costly function

 What     is the alternative?
Rect
   What is it?

   Eg:
       r = Rect ( ( 10 , 10 , 50 , 100 ) )
       print r.top , r. bottom # 1 0 1 1 0
       print r.left , r. right # 1 0 6 0
       print r.midtop , r. midleft # ( 3 5 , 1 0 ) ( 1 0 , 6 0 )
       print r. center # ( 3 5 , 6 0 )
       c1 = r. collidepoint ( 30 , 40 )
       c2 = r. colliderect ( ( 0 , 0 , 100 , 200 ) )
       r2 = r. inflate ( 10 , 10 )
       r2. move_ip ( 5 , 5 )
Rect – Important Functions
   clamp (area)
       Returns a new rectangle inside this area
   clip(area)
       Returns a new rectangle with his area cliped to
        fill the new area
   collidepoint(x, y)
       Check if the point is in the rectangle.
   colliderect(area)
       Check if the area toch the current rectangle
Rect – Important Functions
   contains(area)
       Check if the area is in the rectangle.
   inflate(x,y)
       Returns a new rectangle with the dimensions of
        the current rectangle increased according to
        the passed value
   move(x,y)
       Returns a new rectangle with the positions of
        current rectangle driven by passed values ​
Display
   What is it?

   Eg:
       modos = pygame . display . list_modes ()
       tela = pygame . display . set_mode ( modos [ 0 ] )
       rect = pygame . Rect ( 0 , 0 , 10 , 10 )
       pygame . display . set_caption ( " Teste do PyGame " )
       while tela . get_rect (). contains ( rect ):
       tela . fill ( ( 0 , 0 , 0 ) )
       tela . fill ( ( 255 , 0 , 0 ) , rect )
       rect . move_ip ( 10 , 10 )
       pygame . display . flip ()
Display – Essential Functions
 flip()
     Update all the screen content
 get_surface()
     Return the current surface
 list_modes()
     List possible resolutions/dimensions
 set_caption(title)
     Change screen title
Display – Essential Functions
 set_mode(size)
     Setup the screen with the passed size
 toggle_fullscreen()
     Toggle to fullscreen
 update(rect_list)
     Update certain areas of the screen
      depending of the passed list of rectangles
Event
 What    is it?

 Thereare two methods to handle the line
 of events
    Event Queued
    Direct consultation of devices
Event Queued

 from  pygame . locals import *
 for event in pygame . event .get ():
     if event . type == QUIT :
       sys   . exit ()
     elif event . type == KEYDOWN :
       print   event .key
Direct Consultation of Devices
 from  pygame . locals import *
 while not ( pygame . mouse . get_pressed ()[ 0 ]
  or  pygame .key . get_pressed ()[ K_SPACE ] ):
        pygame . event . pump ()
References
   Python: http://www.python.org/
   PyGame: http://www.pygame.org/
   A Newbie Guide to pygame:
   http://www.pygame.org/docs/tut/newbieguide.html
   Introdução ao Pygame:
   http://www.pygame.org/docs/tut/intro/intro.html
   Dicas de Performance para Python: http:
   //www.python.org/moin/PythonSpeed/Performance
    Tips
   Introdução ao Módulo Sprite do PyGame:
   http://www.pygame.org/docs/tut/SpriteIntro.html
Contact Details
 Matheus Melo
 Work mail:
     matheus.melo@idealizza.com.br
 Personal   mail:
     matheuscmpm@gmail.com
 Twitter:
     @matheuscmpm
 Facebook
     /matheuscmpm

More Related Content

PDF
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
PPTX
Presentation2
PPTX
Presentation2
PPTX
Python programing
PPT
Circular queues
PPTX
MapReduce
PPTX
2.5 function transformations
PPTX
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
CLIM Undergraduate Workshop: Tutorial on R Software - Huang Huang, Oct 23, 2017
Presentation2
Presentation2
Python programing
Circular queues
MapReduce
2.5 function transformations
2.2 stack applications Infix to Postfix & Evaluation of Post Fix

What's hot (20)

DOC
Infix to-postfix examples
PDF
Om (Cont.)
PPT
Infix prefix postfix
DOCX
ggtimeseries-->ggplot2 extensions
PPT
Module 2 topic 2 notes
PPT
Bayesian learning
PPT
Lesson 3.4
PPT
Application of Stacks
PPTX
My lecture infix-to-postfix
PDF
Data visualization with multiple groups using ggplot2
PDF
Geo Spatial Plot using R
PDF
SupportVectorRegression
DOCX
Experement no 6
PDF
Data visualization using the grammar of graphics
PDF
Ejemplograficar
PDF
C Graphics Functions
PDF
Test
PPTX
Butterfly Counting in Bipartite Networks
DOCX
Array using recursion
PPTX
Boolean Algebra by SUKHDEEP SINGH
Infix to-postfix examples
Om (Cont.)
Infix prefix postfix
ggtimeseries-->ggplot2 extensions
Module 2 topic 2 notes
Bayesian learning
Lesson 3.4
Application of Stacks
My lecture infix-to-postfix
Data visualization with multiple groups using ggplot2
Geo Spatial Plot using R
SupportVectorRegression
Experement no 6
Data visualization using the grammar of graphics
Ejemplograficar
C Graphics Functions
Test
Butterfly Counting in Bipartite Networks
Array using recursion
Boolean Algebra by SUKHDEEP SINGH
Ad

Viewers also liked (20)

PDF
E dá para desenvolver webgames com Django?
PDF
E o que danado é o PUG-PE?
PPT
[2012] XIX PUGPE - Projeto Amadeus
PPTX
Lp script pug-pe
PDF
Palestra Institucional PUG-PE
PDF
Mini-Curso de Python dia 21/03 (Segunda-Feira) no II Workshop de SL do CIN/UFPE
PPTX
Suporte a macros na sua aplicação com PowerShell
PPTX
Acelere - e melhore! - o feedback com testes automatizados rápidos
PDF
Com vocês, Django!
PDF
Tdd not sure if testing or developing
PPT
W2py pyconpe
PDF
TDC2016SP - Luiza Labs - Migrando .NET p/ Python
PDF
TDC2016SP - Flask para Web
PPTX
Testes exploratórios não são sinônimo de bagunça! (TDC 2016 SP)
PDF
Python, A pílula Azul da programação
PDF
Devcommerce 2016: Migração plataforma Magazine Luiza e seu laboratório de in...
PDF
Python e Cadeias de Markov GHMM
PDF
NoSQL com Cassandra e Python
PDF
Python Debugger - PUG-PE
PPT
Pyjamas: Uma Ferramenta Pythônica para Web
E dá para desenvolver webgames com Django?
E o que danado é o PUG-PE?
[2012] XIX PUGPE - Projeto Amadeus
Lp script pug-pe
Palestra Institucional PUG-PE
Mini-Curso de Python dia 21/03 (Segunda-Feira) no II Workshop de SL do CIN/UFPE
Suporte a macros na sua aplicação com PowerShell
Acelere - e melhore! - o feedback com testes automatizados rápidos
Com vocês, Django!
Tdd not sure if testing or developing
W2py pyconpe
TDC2016SP - Luiza Labs - Migrando .NET p/ Python
TDC2016SP - Flask para Web
Testes exploratórios não são sinônimo de bagunça! (TDC 2016 SP)
Python, A pílula Azul da programação
Devcommerce 2016: Migração plataforma Magazine Luiza e seu laboratório de in...
Python e Cadeias de Markov GHMM
NoSQL com Cassandra e Python
Python Debugger - PUG-PE
Pyjamas: Uma Ferramenta Pythônica para Web
Ad

Similar to XIX PUG-PE - Pygame game development (20)

PPT
Pygame : créer des jeux interactifs en Python.
PPT
"Pemrograman Python untuk Pemula dan Ahli"
PDF
Introduction to Pygame (Lecture 7 Python Game Development)
PDF
Pygame presentation
PPTX
MODULE III.pptx
PDF
Денис Ковалев «Python в игровой индустрии»
PDF
Introduction to Game programming with PyGame Part 1
PDF
learning_Pygame_Basics_Part _1f_for_beginner.pdf
PDF
Game Development With Python and Pygame
PDF
SunPy: Python for solar physics
PDF
Lecture 3 - Driving.pdf
PDF
Cg lab cse-v (1) (1)
PDF
Python lecture 10
PDF
Migrating from matlab to python
PDF
Computer graphics system project report..pdf
PPTX
Objects and Graphics
PPTX
Chapter04.pptx
PDF
A Simple 3D Graphics Engine Written in Python and Allegro
PPTX
B. SC CSIT Computer Graphics Lab By Tekendra Nath Yogi
PDF
Report om 3
Pygame : créer des jeux interactifs en Python.
"Pemrograman Python untuk Pemula dan Ahli"
Introduction to Pygame (Lecture 7 Python Game Development)
Pygame presentation
MODULE III.pptx
Денис Ковалев «Python в игровой индустрии»
Introduction to Game programming with PyGame Part 1
learning_Pygame_Basics_Part _1f_for_beginner.pdf
Game Development With Python and Pygame
SunPy: Python for solar physics
Lecture 3 - Driving.pdf
Cg lab cse-v (1) (1)
Python lecture 10
Migrating from matlab to python
Computer graphics system project report..pdf
Objects and Graphics
Chapter04.pptx
A Simple 3D Graphics Engine Written in Python and Allegro
B. SC CSIT Computer Graphics Lab By Tekendra Nath Yogi
Report om 3

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Encapsulation theory and applications.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
NewMind AI Monthly Chronicles - July 2025
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Electronic commerce courselecture one. Pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Encapsulation theory and applications.pdf
Unlocking AI with Model Context Protocol (MCP)
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
NewMind AI Monthly Chronicles - July 2025
Digital-Transformation-Roadmap-for-Companies.pptx
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Network Security Unit 5.pdf for BCA BBA.
Electronic commerce courselecture one. Pdf

XIX PUG-PE - Pygame game development

  • 2. Schedule  Introduction  What is PyGame?  PyGame essential Elements  Developing games with Pygame
  • 3. What is Pygame?  Set of Python modules for writing games  Compatible with SDL  Free 
  • 4. Best Features  No need to OpenGL setup  Multi-core  C/Assembler Core Functions  Portable  Easy to use  Comunity
  • 5. Problems  Python is slow   But you can do something to turn this out.  You write too much  Isn’t a Game Engine, it’s a library.
  • 6. Essential Elements  Surface  What is surface?  2D and 3D planes.  Eg:  tamanho = ( 640 , 480 )  cor = ( 255 , 0 , 0 ) # v e rme lho  superficie = Surface ( tamanho )  superficie . set_at ( ( 10 , 20 ) , cor )  superficie . fill ( cor , ( 11 , 21 , 50 , 50 ) )  tela = pygame . display . set_mode ( tamanho )
  • 7. Surface – Important Functions  fill( color, area)  Fill a area with the selected color  get_at( position )  Returns the color that was in the setted position  set_at( position, color)  Set the color on that position
  • 8. Surface – Color Depth  256 Colors  24 bpp RGB  3 Bytes per color
  • 9. Surface - Transparency  ColorKey  One color is chosen to be transparent  Image Alpha  Can have his Translucency between 0 and 255  Can be used together with ColorKey  Per-Pixel Alpha  Has a associated Alpha component.  Cannot be used with another transparency
  • 10. What is Blit ?  Convert the current Surface Color Depth to the next Surface Color Depth  It is a very costly function  What is the alternative?
  • 11. Rect  What is it?  Eg:  r = Rect ( ( 10 , 10 , 50 , 100 ) )  print r.top , r. bottom # 1 0 1 1 0  print r.left , r. right # 1 0 6 0  print r.midtop , r. midleft # ( 3 5 , 1 0 ) ( 1 0 , 6 0 )  print r. center # ( 3 5 , 6 0 )  c1 = r. collidepoint ( 30 , 40 )  c2 = r. colliderect ( ( 0 , 0 , 100 , 200 ) )  r2 = r. inflate ( 10 , 10 )  r2. move_ip ( 5 , 5 )
  • 12. Rect – Important Functions  clamp (area)  Returns a new rectangle inside this area  clip(area)  Returns a new rectangle with his area cliped to fill the new area  collidepoint(x, y)  Check if the point is in the rectangle.  colliderect(area)  Check if the area toch the current rectangle
  • 13. Rect – Important Functions  contains(area)  Check if the area is in the rectangle.  inflate(x,y)  Returns a new rectangle with the dimensions of the current rectangle increased according to the passed value  move(x,y)  Returns a new rectangle with the positions of current rectangle driven by passed values ​
  • 14. Display  What is it?  Eg:  modos = pygame . display . list_modes ()  tela = pygame . display . set_mode ( modos [ 0 ] )  rect = pygame . Rect ( 0 , 0 , 10 , 10 )  pygame . display . set_caption ( " Teste do PyGame " )  while tela . get_rect (). contains ( rect ):  tela . fill ( ( 0 , 0 , 0 ) )  tela . fill ( ( 255 , 0 , 0 ) , rect )  rect . move_ip ( 10 , 10 )  pygame . display . flip ()
  • 15. Display – Essential Functions  flip()  Update all the screen content  get_surface()  Return the current surface  list_modes()  List possible resolutions/dimensions  set_caption(title)  Change screen title
  • 16. Display – Essential Functions  set_mode(size)  Setup the screen with the passed size  toggle_fullscreen()  Toggle to fullscreen  update(rect_list)  Update certain areas of the screen depending of the passed list of rectangles
  • 17. Event  What is it?  Thereare two methods to handle the line of events  Event Queued  Direct consultation of devices
  • 18. Event Queued  from pygame . locals import *  for event in pygame . event .get ():  if event . type == QUIT :  sys . exit ()  elif event . type == KEYDOWN :  print event .key
  • 19. Direct Consultation of Devices  from pygame . locals import *  while not ( pygame . mouse . get_pressed ()[ 0 ] or pygame .key . get_pressed ()[ K_SPACE ] ):  pygame . event . pump ()
  • 20. References  Python: http://www.python.org/  PyGame: http://www.pygame.org/  A Newbie Guide to pygame:  http://www.pygame.org/docs/tut/newbieguide.html  Introdução ao Pygame:  http://www.pygame.org/docs/tut/intro/intro.html  Dicas de Performance para Python: http:  //www.python.org/moin/PythonSpeed/Performance Tips  Introdução ao Módulo Sprite do PyGame:  http://www.pygame.org/docs/tut/SpriteIntro.html
  • 21. Contact Details  Matheus Melo  Work mail:  [email protected]  Personal mail:  [email protected]  Twitter:  @matheuscmpm  Facebook  /matheuscmpm