SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
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
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
http://www.pygame.org/docs/

http://www.pygame.org/docs/
       ref/examples.html
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 ...

Contenu connexe

Tendances

Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash CourseHaim Michael
 
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaWhat is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaEdureka!
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingSrinivas Narasegouda
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
 
Web development with Python
Web development with PythonWeb development with Python
Web development with PythonRaman Balyan
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for KidsAimee Maree Forsstrom
 

Tendances (20)

Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Python Crash Course
Python Crash CoursePython Crash Course
Python Crash Course
 
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaWhat is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
 
Python basic syntax
Python basic syntaxPython basic syntax
Python basic syntax
 
Python
PythonPython
Python
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Introduction of python
Introduction of pythonIntroduction of python
Introduction of python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Python Introduction
Python IntroductionPython Introduction
Python Introduction
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 
Beginning Python Programming
Beginning Python ProgrammingBeginning Python Programming
Beginning Python Programming
 
Introduction to Python Basics Programming
Introduction to Python Basics ProgrammingIntroduction to Python Basics Programming
Introduction to Python Basics Programming
 
Python basics
Python basicsPython basics
Python basics
 
Python introduction
Python introductionPython introduction
Python introduction
 
Web development with Python
Web development with PythonWeb development with Python
Web development with Python
 
Introduction to Python - Training for Kids
Introduction to Python - Training for KidsIntroduction to Python - Training for Kids
Introduction to Python - Training for Kids
 

En vedette

3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with PythonMartin Christen
 
Minecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UKMinecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UKRichard Donkin
 
Minecraft in 500 lines of Python with Pyglet
Minecraft in 500 lines of Python with PygletMinecraft in 500 lines of Python with Pyglet
Minecraft in 500 lines of Python with PygletRichard Donkin
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming TutorialRichard Jones
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game ProgrammingRichard Jones
 
Introduction To Facebook: Opportunities and Challenges For The Institution
Introduction To Facebook: Opportunities and Challenges For The InstitutionIntroduction To Facebook: Opportunities and Challenges For The Institution
Introduction To Facebook: Opportunities and Challenges For The Institutionlisbk
 
Python games
Python gamesPython games
Python gamesdxbeeh
 
Facebook Development for Beginners
Facebook Development for BeginnersFacebook Development for Beginners
Facebook Development for BeginnersJesse Stay
 
RDS_Photoscan_Eval_Cloud
RDS_Photoscan_Eval_CloudRDS_Photoscan_Eval_Cloud
RDS_Photoscan_Eval_CloudRaminder Singh
 
Introduction to Facebook Python API
Introduction to Facebook Python APIIntroduction to Facebook Python API
Introduction to Facebook Python APIColin Su
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scriptingAmirul Shafeeq
 
Server and Client side comparision
Server and Client side comparisionServer and Client side comparision
Server and Client side comparisionStew Duncan
 
Workshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKWorkshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKDimitar Danailov
 
Introduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDKIntroduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDKColin Su
 
Facebook Python SDK - Introduction
Facebook Python SDK - IntroductionFacebook Python SDK - Introduction
Facebook Python SDK - IntroductionColin Su
 
Facebook essay ideas
Facebook essay ideasFacebook essay ideas
Facebook essay ideasLisa Shaw
 

En vedette (20)

3D Computer Graphics with Python
3D Computer Graphics with Python3D Computer Graphics with Python
3D Computer Graphics with Python
 
Minecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UKMinecraft in 500 lines with Pyglet - PyCon UK
Minecraft in 500 lines with Pyglet - PyCon UK
 
Minecraft in 500 lines of Python with Pyglet
Minecraft in 500 lines of Python with PygletMinecraft in 500 lines of Python with Pyglet
Minecraft in 500 lines of Python with Pyglet
 
Introduction to Game Programming Tutorial
Introduction to Game Programming TutorialIntroduction to Game Programming Tutorial
Introduction to Game Programming Tutorial
 
Intro to Game Programming
Intro to Game ProgrammingIntro to Game Programming
Intro to Game Programming
 
Pygame presentation
Pygame presentationPygame presentation
Pygame presentation
 
Introduction To Facebook: Opportunities and Challenges For The Institution
Introduction To Facebook: Opportunities and Challenges For The InstitutionIntroduction To Facebook: Opportunities and Challenges For The Institution
Introduction To Facebook: Opportunities and Challenges For The Institution
 
Python games
Python gamesPython games
Python games
 
Facebook Development for Beginners
Facebook Development for BeginnersFacebook Development for Beginners
Facebook Development for Beginners
 
RDS_Photoscan_Eval_Cloud
RDS_Photoscan_Eval_CloudRDS_Photoscan_Eval_Cloud
RDS_Photoscan_Eval_Cloud
 
Introduction to Facebook Python API
Introduction to Facebook Python APIIntroduction to Facebook Python API
Introduction to Facebook Python API
 
introduction to server-side scripting
introduction to server-side scriptingintroduction to server-side scripting
introduction to server-side scripting
 
Server and Client side comparision
Server and Client side comparisionServer and Client side comparision
Server and Client side comparision
 
Workshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKWorkshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDK
 
Website vs web app
Website vs web appWebsite vs web app
Website vs web app
 
Introduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDKIntroduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDK
 
Facebook Python SDK - Introduction
Facebook Python SDK - IntroductionFacebook Python SDK - Introduction
Facebook Python SDK - Introduction
 
Mobile app Vs Web App
Mobile app Vs Web AppMobile app Vs Web App
Mobile app Vs Web App
 
Client & server side scripting
Client & server side scriptingClient & server side scripting
Client & server side scripting
 
Facebook essay ideas
Facebook essay ideasFacebook essay ideas
Facebook essay ideas
 

Similaire à Introduction to Game programming with PyGame Part 1

C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with Cgpsoft_sk
 
Programming the Raspberry Pi element14
Programming the Raspberry Pi element14Programming the Raspberry Pi element14
Programming the Raspberry Pi element14Imad Rhali
 
Intro To Java Alpharetta Meetup Day-1
Intro To Java Alpharetta Meetup Day-1Intro To Java Alpharetta Meetup Day-1
Intro To Java Alpharetta Meetup Day-1introtojava
 
[Osxdev]3.swift playgrounds
[Osxdev]3.swift playgrounds[Osxdev]3.swift playgrounds
[Osxdev]3.swift playgroundsNAVER D2
 
Pa++ern - esoteric language for embroidery (2009)
Pa++ern - esoteric language for embroidery  (2009)Pa++ern - esoteric language for embroidery  (2009)
Pa++ern - esoteric language for embroidery (2009)daitomanabe
 
놀아요 Swift Playgrounds
놀아요 Swift Playgrounds놀아요 Swift Playgrounds
놀아요 Swift PlaygroundsWooKyoung Noh
 
Python week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourPython week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourOsama Ghandour Geris
 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hdslantsixgames
 
Game design & development
Game design & developmentGame design & development
Game design & developmentHemanth Sharma
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP PerspectiveBarry Jones
 
Intro to the raspberry pi board
Intro to the raspberry pi boardIntro to the raspberry pi board
Intro to the raspberry pi boardThierry Gayet
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboyKenneth Geisshirt
 
Easy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkeyEasy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkeypprem
 

Similaire à Introduction to Game programming with PyGame Part 1 (20)

05 python.pdf
05 python.pdf05 python.pdf
05 python.pdf
 
Charming python
Charming pythonCharming python
Charming python
 
C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with C
 
Programming the Raspberry Pi element14
Programming the Raspberry Pi element14Programming the Raspberry Pi element14
Programming the Raspberry Pi element14
 
Intro To Java Alpharetta Meetup Day-1
Intro To Java Alpharetta Meetup Day-1Intro To Java Alpharetta Meetup Day-1
Intro To Java Alpharetta Meetup Day-1
 
[Osxdev]3.swift playgrounds
[Osxdev]3.swift playgrounds[Osxdev]3.swift playgrounds
[Osxdev]3.swift playgrounds
 
Pa++ern - esoteric language for embroidery (2009)
Pa++ern - esoteric language for embroidery  (2009)Pa++ern - esoteric language for embroidery  (2009)
Pa++ern - esoteric language for embroidery (2009)
 
놀아요 Swift Playgrounds
놀아요 Swift Playgrounds놀아요 Swift Playgrounds
놀아요 Swift Playgrounds
 
God Of War : post mortem
God Of War : post mortemGod Of War : post mortem
God Of War : post mortem
 
python_class.pptx
python_class.pptxpython_class.pptx
python_class.pptx
 
Python week 1 2020-2021
Python week 1 2020-2021Python week 1 2020-2021
Python week 1 2020-2021
 
Python week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandourPython week 2 2019 2020 for g10 by eng.osama ghandour
Python week 2 2019 2020 for g10 by eng.osama ghandour
 
Supersize your production pipe enjmin 2013 v1.1 hd
Supersize your production pipe    enjmin 2013 v1.1 hdSupersize your production pipe    enjmin 2013 v1.1 hd
Supersize your production pipe enjmin 2013 v1.1 hd
 
Introduction to Coding
Introduction to CodingIntroduction to Coding
Introduction to Coding
 
Game design & development
Game design & developmentGame design & development
Game design & development
 
Go from a PHP Perspective
Go from a PHP PerspectiveGo from a PHP Perspective
Go from a PHP Perspective
 
Intro to the raspberry pi board
Intro to the raspberry pi boardIntro to the raspberry pi board
Intro to the raspberry pi board
 
py4inf-01-intro.ppt
py4inf-01-intro.pptpy4inf-01-intro.ppt
py4inf-01-intro.ppt
 
Unleash your inner console cowboy
Unleash your inner console cowboyUnleash your inner console cowboy
Unleash your inner console cowboy
 
Easy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkeyEasy coding a multi device game with FireMonkey
Easy coding a multi device game with FireMonkey
 

Plus de Abhishek Mishra

Scraping with Python for Fun and Profit - PyCon India 2010
Scraping with Python for Fun and Profit - PyCon India 2010Scraping with Python for Fun and Profit - PyCon India 2010
Scraping with Python for Fun and Profit - PyCon India 2010Abhishek Mishra
 
Amritadhara - Issues, Challenges, and a Solution
Amritadhara - Issues, Challenges, and a SolutionAmritadhara - Issues, Challenges, and a Solution
Amritadhara - Issues, Challenges, and a SolutionAbhishek Mishra
 
Project SpaceLock - Architecture & Design
Project SpaceLock - Architecture & DesignProject SpaceLock - Architecture & Design
Project SpaceLock - Architecture & DesignAbhishek Mishra
 
The Beginning - Jan 20 2009
The Beginning - Jan 20 2009The Beginning - Jan 20 2009
The Beginning - Jan 20 2009Abhishek Mishra
 
SpaceLock Meetup - Plan 25 Jan 09
SpaceLock Meetup - Plan 25 Jan 09SpaceLock Meetup - Plan 25 Jan 09
SpaceLock Meetup - Plan 25 Jan 09Abhishek Mishra
 
Identification Simplified - An Introduction to Biometrics
Identification Simplified - An Introduction to BiometricsIdentification Simplified - An Introduction to Biometrics
Identification Simplified - An Introduction to BiometricsAbhishek Mishra
 

Plus de Abhishek Mishra (11)

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

Dernier

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sectoritnewsafrica
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentMahmoud Rabie
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Mark Simos
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfAarwolf Industries LLC
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...amber724300
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessWSO2
 

Dernier (20)

Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
4. Cobus Valentine- Cybersecurity Threats and Solutions for the Public Sector
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Digital Tools & AI in Career Development
Digital Tools & AI in Career DevelopmentDigital Tools & AI in Career Development
Digital Tools & AI in Career Development
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
Tampa BSides - The No BS SOC (slides from April 6, 2024 talk)
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
Landscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdfLandscape Catalogue 2024 Australia-1.pdf
Landscape Catalogue 2024 Australia-1.pdf
 
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
JET Technology Labs White Paper for Virtualized Security and Encryption Techn...
 
Accelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with PlatformlessAccelerating Enterprise Software Engineering with Platformless
Accelerating Enterprise Software Engineering with Platformless
 

Introduction to Game programming with PyGame Part 1

  • 1. Introduction to PyGame Abhishek Mishra hello@ideamonk.com
  • 2. Agenda • Games - 2d games • Basics • Python • PyGame • Examples
  • 3. Whats inside a Game? • Multidisciplinary Process • Graphics • Input Control • Game Logic / AI • Sound effects / Music • Communication • Physics, etc • Frameworks ^ Libraries ^^
  • 4. Basics - Drawing • Drawing primitives • Pixels, Square, Rect, Ellipse, etc • Provided by development env
  • 5. Basics - Animation • Draw things • Change their positon • Draw them again • Repeat
  • 6. Basics - Animation • Draw things • Change their positon • Draw them again • Repeat
  • 7. Basics - Animation • Draw things • Change their positon • Draw them again • Repeat
  • 8. Basics - Animation • Draw things • Change their positon • Draw them again • Repeat
  • 9. Basics - Animation • Draw things • Change their positon • Draw them again • Repeat
  • 10. Basics - Surfaces • Drawing primitives use algorithms • Slow for repetitive work
  • 11. Basics - Surfaces • Drawing primitives use algorithms • Slow for repetitive work
  • 12. Basics - Surfaces • How do we save time?
  • 13. Basics - Surfaces • How do we save time?
  • 14. Basics - Surfaces • How do we save time? A Surface / Bitmap
  • 15. Basics - Surfaces • How do we save time? RAM
  • 16. Basics - Surfaces • How do we save time? RAM
  • 17. Basics - Surfaces • Bitmaps • Rectangular • CPU Inexpensive • Can be layered
  • 18. Basics - Surfaces • Bitmaps • Rectangular • CPU Inexpensive • Can be layered Sky layer Trees Enemies
  • 19. 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?
  • 20. Basics - Animation Again! • Draw on a buffer surface • Wait for vertical sync • Transfer the whole buffer to screen
  • 21. Basics - Animation Again! • Draw on a buffer surface • Wait for vertical sync • Transfer the whole buffer to screen
  • 22. Basics - Animation Again! • Draw on a buffer surface • Wait for vertical sync • Transfer the whole buffer to screen
  • 23. Basics - Animation Again! • Draw on a buffer surface • Wait for vertical sync • Transfer the whole buffer to screen
  • 25. Collision Detection 2D Bound checks
  • 26. Collision Detection Pixel Perfect http://wiki.allegro.cc/index.php?title=Pixel_Perfect_Collision
  • 27.
  • 28. Ah! So many things to do?
  • 29. Ah! So many things to do? Enter Frameworks / Engines/ Libraries & other angels
  • 30. 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
  • 31. 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# ...)
  • 32. 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# ...)
  • 33. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 34. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 35. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 36. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 37. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 38. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 39. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 40. What now? • An entertaining idea • A Programming Language • A Game programming framework • Some bells, whistles & decorations
  • 41. 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
  • 42. Python • Free • On many platforms (Unix, Linux, Windows, OS X, Symbian S60, Java, BeOS) • Lacks type declaration • Huge library of modules
  • 43. 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]
  • 44. Python Indentation if (name == ‘abc’): print “Yes” else: print “No”
  • 45. Python Strings fruit = “Apple” fruit = ‘Apple’ fruit = “““ Apple and ‘apple” ””” fruit = ‘‘‘ foo bar ’’’ message = “Hello %s. Total is %d” % (name, total)
  • 46. 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]
  • 47. Python Dictionaries Associative key => value pairs d = { ‘name’ : ‘Ram’, ‘age’:45 } print d[‘name’] print d[‘age’] d[‘salary’] = 45000
  • 48. Python Loops for (int x=0; x<10; x+=2) { // do something } for x in range(0,10,2): # do something
  • 49. Python Loops L = [1,2,4,5,3,1] for i in L: print i 1 2 4 5 3 1
  • 50. Python Functions def factorial( num ): if num==1: return 1 else: return num * factorial(num-1) print factorial(4) 24
  • 51. Python Comments # single line comment “““ multi line ”””
  • 53. • 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
  • 54.
  • 56.
  • 57. 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 ...
  • 58. Code / Demo time