SlideShare a Scribd company logo
Introduction to
            PyGame
Abhishek Mishra   hello@ideamonk.com
Agenda
• Games - 2d games
• Basics
• Python
• PyGame
• Examples
Whats inside a Game?
• Multidisciplinary Process
• Graphics
• Input Control
• Game Logic / AI
• Sound effects / Music
• Communication
• Physics, etc
• Frameworks ^ Libraries ^^
Basics - Drawing
• Drawing primitives
• Pixels, Square, Rect, Ellipse, etc
• Provided by development env
Basics - Animation

• Draw things
• Change their positon
• Draw them again
• Repeat
Basics - Animation

• Draw things
• Change their positon
• Draw them again
• Repeat
Basics - Animation

• Draw things
• Change their positon
• Draw them again
• Repeat
Basics - Animation

• Draw things
• Change their positon
• Draw them again
• Repeat
Basics - Animation

• Draw things
• Change their positon
• Draw them again
• Repeat
Basics - Surfaces
• Drawing primitives use algorithms
• Slow for repetitive work
Basics - Surfaces
• Drawing primitives use algorithms
• Slow for repetitive work
Basics - Surfaces
• How do we save time?
Basics - Surfaces
• How do we save time?
Basics - Surfaces
• How do we save time?


      A Surface / Bitmap
Basics - Surfaces
• How do we save time?



                         RAM
Basics - Surfaces
• How do we save time?



                         RAM
Basics - Surfaces
• Bitmaps
• Rectangular
• CPU Inexpensive
• Can be layered
Basics - Surfaces
  • Bitmaps
  • Rectangular
  • CPU Inexpensive
  • Can be layered
Sky layer
 Trees
Enemies
Basics - Animation Again!
• Monitors have refresh rate
• Can’t draw so many surfaces on live screen
• How do we make it smooth?
• How do we sync?
Basics - Animation Again!
• Draw on a buffer surface
• Wait for vertical sync
• Transfer the whole buffer to screen
Basics - Animation Again!
• Draw on a buffer surface
• Wait for vertical sync
• Transfer the whole buffer to screen
Basics - Animation Again!
• Draw on a buffer surface
• Wait for vertical sync
• Transfer the whole buffer to screen
Basics - Animation Again!
• Draw on a buffer surface
• Wait for vertical sync
• Transfer the whole buffer to screen
Collision Detection
Collision Detection




     2D Bound checks
Collision Detection




                        Pixel Perfect
http://wiki.allegro.cc/index.php?title=Pixel_Perfect_Collision
Introduction to Game programming with PyGame Part 1
Ah! So many things to do?
Ah! So many things to do?
  Enter Frameworks /
   Engines/ Libraries
    & other angels
Programming
• Lot of repetitive tasks
• Lot of things you don’t wish to figure out
• Technologies - OpenGL, DirectX, SDL
• Interfacing Libraries
• Generic set of solutions - frameworks
• Complete solutions - Game Engines,
  toolsets
Programming
• Many options to choose from -
• DirectQB (old MSDOS days)
• Allegro (C/C++, cross platform)
• PyGame (Python, SDL)
• PyGlet (Python, OpenGL)
• XNA (Windows, XBox, dotNET, C#,VB)
• DirectX (Windows specific,VC++, C# ...)
Programming
• Many options to choose from -
• DirectQB (old MSDOS days)
• Allegro (C/C++, cross platform)
• PyGame (Python, SDL)
• PyGlet (Python, OpenGL)
• XNA (Windows, XBox, dotNET, C#,VB)
• DirectX (Windows specific,VC++, C# ...)
A Basic Game Loop
Start       While player is alive

           take input

           find collisions

           draw on buffer

           put everything on screen
A Basic Game Loop
Start       While player is alive

           take input

           find collisions

           draw on buffer

           put everything on screen
A Basic Game Loop
Start       While player is alive

           take input

           find collisions

           draw on buffer

           put everything on screen
A Basic Game Loop
Start       While player is alive

           take input

           find collisions

           draw on buffer

           put everything on screen
A Basic Game Loop
Start       While player is alive

           take input

           find collisions

           draw on buffer

           put everything on screen
A Basic Game Loop
Start       While player is alive

           take input

           find collisions

           draw on buffer

           put everything on screen
A Basic Game Loop
Start       While player is alive

           take input

           find collisions

           draw on buffer

           put everything on screen
What now?
• An entertaining idea
• A Programming Language
• A Game programming framework
• Some bells, whistles & decorations
Python
• Dynamic, Interpreted, Interactive
• Object Oriented
• Easy to write, easy to read
• Popular - education, prototyping, quick
  hacks, research, unlimited
• Batteries included
• From web to standalones
Python
• Free
• On many platforms (Unix, Linux, Windows,
  OS X, Symbian S60, Java, BeOS)
• Lacks type declaration
• Huge library of modules
Python
• printf (“Hi %s”, name);
  print “Hi %s” % name
• int x = 45;   float y = 1.01
  x = 45        y = 1.01
• int a[4] = {1,2,3,4}
  a = [1,2,3,4]
  a = [1,2,‘abhishek’, 4, 4.5]
Python
Indentation

if (name == ‘abc’):
    print “Yes”
else:
    print “No”
Python
Strings

fruit = “Apple”
fruit = ‘Apple’
fruit = “““ Apple and ‘apple” ”””
fruit = ‘‘‘ foo bar ’’’
message = “Hello %s. Total is %d” % (name, total)
Python
Lists

l = [1,2,3, ‘foo’, 4.5]
print l[3]
foo
l = [ [1,2,3], ‘a’, ‘b’, ‘c’ ]
innerlist = l[0]
print innerlist
[1,2,3]
Python
Dictionaries

Associative key => value pairs
d = { ‘name’ : ‘Ram’, ‘age’:45 }
print d[‘name’]
print d[‘age’]
d[‘salary’] = 45000
Python
Loops

for (int x=0; x<10; x+=2) { // do something }
for x in range(0,10,2):
   # do something
Python
Loops

L = [1,2,4,5,3,1]
for i in L:
   print i
1
2
4
5
3
1
Python
Functions

def factorial( num ):
  if num==1:
      return 1
  else:
      return num * factorial(num-1)

print factorial(4)
24
Python
Comments

# single line comment
“““ multi
            line ”””
Python
Modules

import math
print math.pi
• Based on SDL (Simple Directmedia Layer)
• Works on Windows, OSX, Linux, N900, etc
• Big array of modules, does a lot to save
  time
• http://pygame.org
• $ sudo easy_install pygame
Introduction to Game programming with PyGame Part 1
http://www.pygame.org/docs/

http://www.pygame.org/docs/
       ref/examples.html
Introduction to Game programming with PyGame Part 1
pygame.Color pygame.transform    pygame.draw
pygame.Rect    pygame.Surface   pygame.mouse

pygame.image   pygame.movie     pygame.display

               pygame.camera     pygame.time
pygame.midi
pygame.event   pygame.mixer      pygame.font

                                       ...
Code / Demo time
To be continued ...

More Related Content

What's hot (20)

PPTX
PRESENTATION ON Game Engine
Diksha Bhargava
 
PPTX
UNITY 3D.pptx
Omgworkspace
 
PPTX
Introduction to Game Development
Sumit Jain
 
PPTX
Snake game powerpoint presentation by rohit malav
Rohit malav
 
PPSX
An Introduction To Game development
Ahmed
 
PPTX
LAFS SVI Level 3 - Game Design and Analysis
David Mullich
 
PDF
Brief Introduction to Game Design
Lennart Nacke
 
PPTX
Rock, Paper, Scissors
Johnathan
 
PPTX
Unity 3D, A game engine
Md. Irteza rahman Masud
 
PPT
What Is A Game Engine
Seth Sivak
 
PPTX
Game dev process
Yassine Arif
 
PDF
Gamification - Defining, Designing and Using it
Zac Fitz-Walter
 
PPTX
Course Presentation: Games design
Brunel University
 
PPT
introduction to blender
anand09
 
PPTX
Game Design
April Bundridge
 
PPTX
Unity 3d Basics
Chaudhry Talha Waseem
 
PPTX
Game Design as a Career
ArtfulArtsyAmy
 
PPTX
Game Design as Career
ArtfulArtsyAmy
 
PDF
06. Game Architecture
Amin Babadi
 
PDF
Game Design Fundamentals: The Formal Elements
Christina Wodtke
 
PRESENTATION ON Game Engine
Diksha Bhargava
 
UNITY 3D.pptx
Omgworkspace
 
Introduction to Game Development
Sumit Jain
 
Snake game powerpoint presentation by rohit malav
Rohit malav
 
An Introduction To Game development
Ahmed
 
LAFS SVI Level 3 - Game Design and Analysis
David Mullich
 
Brief Introduction to Game Design
Lennart Nacke
 
Rock, Paper, Scissors
Johnathan
 
Unity 3D, A game engine
Md. Irteza rahman Masud
 
What Is A Game Engine
Seth Sivak
 
Game dev process
Yassine Arif
 
Gamification - Defining, Designing and Using it
Zac Fitz-Walter
 
Course Presentation: Games design
Brunel University
 
introduction to blender
anand09
 
Game Design
April Bundridge
 
Unity 3d Basics
Chaudhry Talha Waseem
 
Game Design as a Career
ArtfulArtsyAmy
 
Game Design as Career
ArtfulArtsyAmy
 
06. Game Architecture
Amin Babadi
 
Game Design Fundamentals: The Formal Elements
Christina Wodtke
 

Viewers also liked (20)

PDF
3D Computer Graphics with Python
Martin Christen
 
PPTX
Minecraft in 500 lines with Pyglet - PyCon UK
Richard Donkin
 
PPTX
Minecraft in 500 lines of Python with Pyglet
Richard Donkin
 
KEY
Introduction to Game Programming Tutorial
Richard Jones
 
KEY
Intro to Game Programming
Richard Jones
 
PPT
Introduction To Facebook: Opportunities and Challenges For The Institution
lisbk
 
PPTX
Python games
dxbeeh
 
KEY
Facebook Development for Beginners
Jesse Stay
 
PPTX
RDS_Photoscan_Eval_Cloud
Raminder Singh
 
PDF
Introduction to Facebook Python API
Colin Su
 
PPTX
introduction to server-side scripting
Amirul Shafeeq
 
PPTX
Server and Client side comparision
Stew Duncan
 
PDF
Workshop : Facebook JavaScript SDK
Dimitar Danailov
 
PDF
Website vs web app
Immortal Technologies
 
PDF
Introduction to Facebook JavaScript & Python SDK
Colin Su
 
PDF
Facebook Python SDK - Introduction
Colin Su
 
KEY
Mobile app Vs Web App
Htain Lin Shwe
 
PPTX
Client & server side scripting
baabtra.com - No. 1 supplier of quality freshers
 
PPTX
Facebook essay ideas
Lisa Shaw
 
PPT
Scripting languages
teach4uin
 
3D Computer Graphics with Python
Martin Christen
 
Minecraft in 500 lines with Pyglet - PyCon UK
Richard Donkin
 
Minecraft in 500 lines of Python with Pyglet
Richard Donkin
 
Introduction to Game Programming Tutorial
Richard Jones
 
Intro to Game Programming
Richard Jones
 
Introduction To Facebook: Opportunities and Challenges For The Institution
lisbk
 
Python games
dxbeeh
 
Facebook Development for Beginners
Jesse Stay
 
RDS_Photoscan_Eval_Cloud
Raminder Singh
 
Introduction to Facebook Python API
Colin Su
 
introduction to server-side scripting
Amirul Shafeeq
 
Server and Client side comparision
Stew Duncan
 
Workshop : Facebook JavaScript SDK
Dimitar Danailov
 
Website vs web app
Immortal Technologies
 
Introduction to Facebook JavaScript & Python SDK
Colin Su
 
Facebook Python SDK - Introduction
Colin Su
 
Mobile app Vs Web App
Htain Lin Shwe
 
Client & server side scripting
baabtra.com - No. 1 supplier of quality freshers
 
Facebook essay ideas
Lisa Shaw
 
Scripting languages
teach4uin
 
Ad

Similar to Introduction to Game programming with PyGame Part 1 (20)

PDF
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
PPT
"Pemrograman Python untuk Pemula dan Ahli"
Muhammadlenterabawon
 
PPT
Pygame : créer des jeux interactifs en Python.
fakhroushka
 
PDF
Python lecture 10
Tanwir Zaman
 
PDF
The Ring programming language version 1.7 book - Part 53 of 196
Mahmoud Samir Fayed
 
PDF
Денис Ковалев «Python в игровой индустрии»
DataArt
 
PDF
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.3 book - Part 58 of 184
Mahmoud Samir Fayed
 
ODP
Python Games
FahadAlH
 
PDF
The Ring programming language version 1.5.1 book - Part 47 of 180
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.2 book - Part 36 of 84
Mahmoud Samir Fayed
 
PPTX
C game programming - SDL
Wingston
 
PDF
The Ring programming language version 1.4 book - Part 14 of 30
Mahmoud Samir Fayed
 
PDF
There is more to C
Juraj Michálek
 
PDF
The Ring programming language version 1.8 book - Part 55 of 202
Mahmoud Samir Fayed
 
PDF
learning_Pygame_Basics_Part _1f_for_beginner.pdf
AihamSlaiman1
 
PDF
The Ring programming language version 1.5.2 book - Part 48 of 181
Mahmoud Samir Fayed
 
PDF
The Ring programming language version 1.5.4 book - Part 50 of 185
Mahmoud Samir Fayed
 
PDF
Makinggames
Rashi Agarwal
 
PDF
The Ring programming language version 1.3 book - Part 38 of 88
Mahmoud Samir Fayed
 
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 
"Pemrograman Python untuk Pemula dan Ahli"
Muhammadlenterabawon
 
Pygame : créer des jeux interactifs en Python.
fakhroushka
 
Python lecture 10
Tanwir Zaman
 
The Ring programming language version 1.7 book - Part 53 of 196
Mahmoud Samir Fayed
 
Денис Ковалев «Python в игровой индустрии»
DataArt
 
The Ring programming language version 1.5.3 book - Part 48 of 184
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.3 book - Part 58 of 184
Mahmoud Samir Fayed
 
Python Games
FahadAlH
 
The Ring programming language version 1.5.1 book - Part 47 of 180
Mahmoud Samir Fayed
 
The Ring programming language version 1.2 book - Part 36 of 84
Mahmoud Samir Fayed
 
C game programming - SDL
Wingston
 
The Ring programming language version 1.4 book - Part 14 of 30
Mahmoud Samir Fayed
 
There is more to C
Juraj Michálek
 
The Ring programming language version 1.8 book - Part 55 of 202
Mahmoud Samir Fayed
 
learning_Pygame_Basics_Part _1f_for_beginner.pdf
AihamSlaiman1
 
The Ring programming language version 1.5.2 book - Part 48 of 181
Mahmoud Samir Fayed
 
The Ring programming language version 1.5.4 book - Part 50 of 185
Mahmoud Samir Fayed
 
Makinggames
Rashi Agarwal
 
The Ring programming language version 1.3 book - Part 38 of 88
Mahmoud Samir Fayed
 
Ad

More from Abhishek Mishra (11)

PDF
Paddles at pelham
Abhishek Mishra
 
PDF
All in a day
Abhishek Mishra
 
PDF
Scraping with Python for Fun and Profit - PyCon India 2010
Abhishek Mishra
 
PPTX
Introducing BugBase 1.0
Abhishek Mishra
 
PPT
Amritadhara - Issues, Challenges, and a Solution
Abhishek Mishra
 
PDF
Gibson Guitar Robot
Abhishek Mishra
 
PDF
Space Lock Web UI
Abhishek Mishra
 
PDF
Project SpaceLock - Architecture & Design
Abhishek Mishra
 
PDF
The Beginning - Jan 20 2009
Abhishek Mishra
 
PDF
SpaceLock Meetup - Plan 25 Jan 09
Abhishek Mishra
 
PDF
Identification Simplified - An Introduction to Biometrics
Abhishek Mishra
 
Paddles at pelham
Abhishek Mishra
 
All in a day
Abhishek Mishra
 
Scraping with Python for Fun and Profit - PyCon India 2010
Abhishek Mishra
 
Introducing BugBase 1.0
Abhishek Mishra
 
Amritadhara - Issues, Challenges, and a Solution
Abhishek Mishra
 
Gibson Guitar Robot
Abhishek Mishra
 
Space Lock Web UI
Abhishek Mishra
 
Project SpaceLock - Architecture & Design
Abhishek Mishra
 
The Beginning - Jan 20 2009
Abhishek Mishra
 
SpaceLock Meetup - Plan 25 Jan 09
Abhishek Mishra
 
Identification Simplified - An Introduction to Biometrics
Abhishek Mishra
 

Recently uploaded (20)

PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PPTX
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Webinar: Introduction to LF Energy EVerest
DanBrown980551
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Seamless Tech Experiences Showcasing Cross-Platform App Design.pptx
presentifyai
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"Beyond English: Navigating the Challenges of Building a Ukrainian-language R...
Fwdays
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 

Introduction to Game programming with PyGame Part 1