Your SlideShare is downloading. ×
  • Like
Introduction to Game programming with PyGame Part 1
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Introduction to Game programming with PyGame Part 1

  • 3,714 views
Published

A short intro to game programming at college :D

A short intro to game programming at college :D

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
3,714
On SlideShare
0
From Embeds
0
Number of Embeds
8

Actions

Shares
Downloads
84
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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
  • 24. Collision Detection
  • 25. Collision Detection 2D Bound checks
  • 26. Collision Detection Pixel Perfect http://wiki.allegro.cc/index.php?title=Pixel_Perfect_Collision
  • 27. Ah! So many things to do?
  • 28. Ah! So many things to do? Enter Frameworks / Engines/ Libraries & other angels
  • 29. 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
  • 30. 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# ...)
  • 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. A Basic Game Loop Start While player is alive take input find collisions draw on buffer put everything on screen
  • 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. What now? • An entertaining idea • A Programming Language • A Game programming framework • Some bells, whistles & decorations
  • 40. 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
  • 41. Python • Free • On many platforms (Unix, Linux, Windows, OS X, Symbian S60, Java, BeOS) • Lacks type declaration • Huge library of modules
  • 42. 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]
  • 43. Python Indentation if (name == ‘abc’): print “Yes” else: print “No”
  • 44. Python Strings fruit = “Apple” fruit = ‘Apple’ fruit = “““ Apple and ‘apple” ””” fruit = ‘‘‘ foo bar ’’’ message = “Hello %s. Total is %d” % (name, total)
  • 45. 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]
  • 46. Python Dictionaries Associative key => value pairs d = { ‘name’ : ‘Ram’, ‘age’:45 } print d[‘name’] print d[‘age’] d[‘salary’] = 45000
  • 47. Python Loops for (int x=0; x<10; x+=2) { // do something } for x in range(0,10,2): # do something
  • 48. Python Loops L = [1,2,4,5,3,1] for i in L: print i 1 2 4 5 3 1
  • 49. Python Functions def factorial( num ): if num==1: return 1 else: return num * factorial(num-1) print factorial(4) 24
  • 50. Python Comments # single line comment “““ multi line ”””
  • 51. Python Modules import math print math.pi
  • 52. • 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
  • 53. http://www.pygame.org/docs/ http://www.pygame.org/docs/ ref/examples.html
  • 54. 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 ...
  • 55. Code / Demo time
  • 56. To be continued ...