You are previewing Beginning Python Games Development : With Pygame, Second Edition.
O'Reilly logo
Beginning Python Games Development : With Pygame, Second Edition

Book Description

Beginning Python Games Development, Second Edition teaches you how to create compelling games using Python and the PyGame games development library. It will teach you how to create visuals, do event handling, create 3D games, add media elements, and integrate OpenGL into your Python game.

In this update to the first ever book to cover the popular open source PyGame games development library, you'll stand to gain valuable technical insights and follow along with the creation of a real-world, freely downloadable video game. Written by industry veterans and Python experts Will McGugan and Harrison Kinsley, this is a comprehensive, practical introduction to games development in Python. You can also capitalize upon numerous tips and tricks the authors have accumulated over their careers creating games for some of the world's largest game developers.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Authors
  8. About the Technical Reviewer
  9. Introduction
  10. Chapter 1: Introducing Python
    1. Your First Look at Python
      1. Numbers
      2. Strings
      3. Lists and Tuples
      4. Unpacking
      5. Loops
    2. Python in Practice
    3. Summary
  11. Chapter 2: Exploring Python
    1. Creating Scripts
    2. Working with Logic
      1. Understanding Booleans
      2. if Statement
      3. and Operator
      4. Or Operator
      5. Not Operator
      6. else Statement
      7. elif Statement
    3. Understanding Functions
      1. Defining Functions
      2. Default Values
    4. Introducing Object-Oriented Programming
      1. Using Classes
      2. Creating an Object
      3. Adding to our Class
    5. Python in Practice
    6. Using the Standard Library
      1. Introducing import
      2. Useful Modules for Games
      3. Math Module
    7. Summary
  12. Chapter 3: Introducing Pygame
    1. History of Pygame
    2. Installing Pygame
    3. Using Pygame
    4. Hello World Revisited
    5. Understanding Events
      1. Retrieving Events
      2. Handling Mouse Motion Events
      3. Handling Mouse Button Events
      4. Handling Keyboard Events
      5. Filtering Events
      6. Posting Events
    6. Opening a Display
      1. Full-Screen Displays
      2. Windows with No Borders
      3. Additional Display Flags
    7. Using the Font Module
    8. Pygame in Action
    9. Summary
  13. Chapter 4: Creating Visuals
    1. Using Pixel Power
    2. Working with Color
      1. Representing Color in Pygame
      2. Scaling Colors
      3. Blending Colors
    3. Using Images
      1. Creating Images with an Alpha Channel
      2. Storing Images
    4. Working with Surface Objects
      1. Creating Surfaces
      2. Filling Surfaces
      3. Getting Pixels in a Surface
      4. Blitting
    5. Drawing with Pygame
      1. pygame.draw.rect
      2. pygame.draw.polygon
      3. pygame.draw.circle
      4. pygame.draw.ellipse
      5. pygame.draw.arc
      6. pygame.draw.line
      7. pygame.draw.lines
      8. pygame.draw.aaline
      9. pygame.draw.aalines
    6. Summary
  14. Chapter 5: Making Things Move
    1. Understanding Frame Rate
    2. Moving in a Straight Line
      1. It’s About Time
      2. Diagonal Movement
    3. Exploring Vectors
      1. Creating Vectors
      2. Storing Vectors
      3. Vector Magnitude
      4. Unit Vectors
      5. Vector Addition
      6. Vector Subtraction
      7. Vector Negation
      8. Vector Multiplication and Division
    4. Using Vectors to Create Movement
      1. Diagonal Movement
      2. Game Objects Vector Class
    5. Summary
  15. Chapter 6: Accepting User Input
    1. Controlling the Game
    2. Understanding Keyboard Control
      1. Detecting Key Presses
      2. Directional Movement with Keys
      3. Rotational Movement with Keys
    3. Implementing Mouse Control
      1. Rotational Movement with the Mouse
      2. Mouse Gameplay
    4. Implementing Joystick Control
      1. Joystick Basics
      2. Joystick Buttons
      3. Joystick Direction Controls
      4. Joystick Objects
    5. Seeing Joysticks in Action
    6. Summary
  16. Chapter 7: Take Me to Your Leader
    1. Creating Ar?tificial Intelligence for Games
      1. What Is Intelligence?
      2. Exploring AI
    2. Implementing State Machines
      1. Game Entities
      2. Building Worlds
      3. Ant Entity Class
      4. Building the Brains
    3. Summary
  17. Chapter 8: Moving into the Third Dimension
    1. Creating the Illusion of Depth
    2. Understanding 3D Space
      1. Using 3D Vectors
      2. Time-Based Movement in 3D
    3. Projecting 3D Points
      1. Parallel Projections
      2. Perspective Projections
      3. Field of View
    4. A 3D World
    5. Summary
  18. Chapter 9: Exploring the Third Dimension
    1. What Is a Matrix?
      1. Using the Matrix Class
      2. Matrix Components
      3. Translation Matrix
      4. Scale Matrix
      5. Rotation Matrix
      6. Matrix Multiplication
    2. Matrices in Action
    3. Introducing OpenGL
      1. Installing PyOpenGL
      2. Initializing OpenGL
      3. OpenGL Primer
    4. Seeing OpenGL in Action
    5. Summary
  19. Chapter 10: Making Things Go Boom
    1. What Is Sound?
    2. Storing Sound
      1. Sound Formats
    3. Creating Sound Effects
    4. Stock Sound Effects
    5. Playing Sounds with Pygame
      1. Sound Objects
      2. Sound Channels
      3. Mixer Functions
      4. Hearing the Mixer in Action
    6. Playing Music with Pygame
      1. Obtaining Music
      2. Playing Music
      3. Hearing Music in Action
    7. Summary
  20. Chapter 11: Lights, Camera, Action!
    1. Working with Textures
      1. Uploading Textures with OpenGL
      2. Texture Coordinates
      3. Rendering Textures
      4. Deleting Textures
      5. Seeing Textures in Action
      6. Mip Mapping
      7. Texture Parameters
      8. Min and Max Filters
      9. Texture Wrapping
    2. Working with Models
      1. Storing Models
      2. OBJ Format for 3D Models
      3. Parsing OBJ Files
      4. Material Library Files
      5. Seeing Models in Action
      6. Using the Model3D Class
    3. Summary
  21. Chapter 12: Setting the Scene with OpenGL
    1. Understanding Lighting
    2. Enabling Lighting
      1. Setting Light Parameters
      2. Working with Materials
      3. Tweaking Parameters
      4. Managing Lights
    3. Understanding Blending
      1. Using Blending
      2. Alpha Blending
      3. Additive Blending
      4. Subtractive Blending
      5. Seeing Blending in Action
      6. Blending Issues
    4. Understanding Fog
      1. Fog Parameters
      2. Seeing Fog in Action
    5. Rendering the Backdrop
      1. Skyboxes
      2. Seeing Skyboxes in Action
      3. Skybox Enhancements
    6. Where to Go for Help
    7. Summary
  22. Appendix A: Game Object Reference
    1. Importing
    2. Contributing
    3. gameobjects.color.Color
      1. Constructor
      2. Attributes
      3. Methods
      4. Class Methods
    4. gameobjects.matrix44.Matrix44
      1. Constructor
      2. Attributes
      3. Methods
      4. Class Methods
    5. gameobjects.vector2.Vector2
      1. Constructor
      2. Attributes
      3. Methods
      4. Class Methods
    6. gameobjects.vector3.Vector3
      1. Constructor
      2. Attributes
      3. Methods
      4. Class Methods
  23. Appendix B: Packaging Your Game
    1. Creating Windows Packages
      1. Using cx_Freeze
      2. Building the Installer
    2. Creating Packages for Linux
    3. Creating Packages for the Mac
  24. Index