1. Trang chủ
  2. » Tất cả

Beginning Game Development with Python and Pygame_ From Novice to Professional [McGugan 2007-10-19]

342 2 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Cấu trúc

  • Beginning Game Development with Python and Pygame: From Novice to Professional

  • Contents at a Glance

  • Contents

  • About the Author

  • About the Technical Reviewer

  • Acknowledgments

  • Introduction

    • Who This Book Is For

    • How This Book Is Structured

    • Prerequisites

    • Downloading the Code

    • Contacting the Author

  • Introducing Python

    • Your First Look at Python

      • Numbers

      • Strings

        • Concatenating Strings

        • Parsing Strings

        • Slicing Strings

        • String Methods

      • Lists and Tuples

        • Modifying List Items

        • Removing List Items

        • List Methods

        • Tuples

        • Unpacking

        • Dictionaries

      • Loops

    • Python in Practice

    • Summary

  • Exploring Python

    • Creating Scripts

    • Working with Logic

      • Understanding Booleans

        • If Statement

        • And Operator

        • Or Operator

        • Not Operator

        • Else Statement

        • Elif Statement

    • Understanding Functions

      • Defining Functions

        • Default Values

    • Introducing Object-Oriented Programming

      • Using Classes

    • Python in Practice

    • Using the Standard Library

      • Introducing import

      • Useful Modules for Games

        • Math Module

        • Datetime Module

        • Random Module

    • Summary

  • Introducing Pygame

    • History of Pygame

    • Installing Pygame

    • Using Pygame

    • Hello World Revisited

    • Understanding Events

      • Retrieving Events

      • Handling Mouse Motion Events

      • Handling Mouse Button Events

      • Handling Keyboard Events

      • Filtering Events

      • Posting Events

    • Opening a Display

      • Full-Screen Displays

      • Resizable Pygame Windows

      • Windows with No Borders

      • Additional Display Flags

    • Using the Font Module

    • When Pygame Goes Wrong

    • Pygame in Action

    • Summary

  • Creating Visuals

    • Using Pixel Power

    • Working with Color

      • Representing Color in Pygame

      • Scaling Colors

      • Blending Colors

    • Using Images

      • Storing Images

      • Working with Surface Objects

        • Creating Surfaces

        • Converting Surfaces

        • Rectangle Objects

        • Clipping

        • Subsurfaces

        • Filling Surfaces

        • Setting Pixels in a Surface

        • Getting Pixels in a Surface

        • Locking Surfaces

        • Blitting

    • Drawing with Pygame

      • pygame.draw.rect

      • pygame.draw.polygon

      • pygame.draw.circle

      • pygame.draw.ellipse

      • pygame.draw.arc

      • pygame.draw.line

      • pgame.draw.lines

      • pygame.draw.aaline

      • pygame.draw.aalines

    • Summary

  • Making Things Move

    • Understanding Frame Rate

    • Moving in a Straight Line

      • It’s About Time

      • Diagonal Movement

    • Exploring Vectors

      • Creating Vectors

      • Storing Vectors

      • Vector Magnitude

      • Unit Vectors

      • Vector Addition

      • Vector Subtraction

      • Vector Negation

      • Vector Multiplication and Division

      • Game Objects Vector Class

    • Using Vectors to Create Movement

      • Diagonal Movement

    • Summary

  • Accepting User Input

    • Controlling the Game

    • Understanding Keyboard Control

      • Detecting Key Presses

      • Directional Movement with Keys

      • Rotational Movement with Keys

    • Implementing Mouse Control

      • Rotational Movement with the Mouse

      • Mouse Gameplay

    • Implementing Joystick Control

      • Joystick Basics

        • Joystick Buttons

      • Joystick Direction Controls

        • D-pads

        • Analog Sticks

      • Joystick Objects

    • Seeing Joysticks in Action

    • Summary

  • Take Me to Your Leader

    • Creating Artificial Intelligence for Games

    • What Is Intelligence?

    • Exploring AI

    • Implementing State Machines

      • Game Entities

      • Building Worlds

      • Ant Entity Class

      • Building the Brains

    • Summary

  • Moving into the Third Dimension

    • Creating the Illusion of Depth

    • Understanding 3D Space

    • Using 3D Vectors

      • Time-Based Movement in 3D

    • Projecting 3D Points

      • Parallel Projections

      • Perspective Projections

        • Field of View

    • A 3D World

    • Summary

  • Exploring the Third Dimension

    • What Is a Matrix?

      • Using the Matrix Class

        • Matrix Components

        • Translation Matrix

        • Scale Matrix

        • Rotation Matrix

        • Matrix Multiplication

        • Matrices in Action

    • Introducing OpenGL

      • Installing PyOpenGL

      • Initializing OpenGL

      • OpenGL Primer

        • Resizing the Display

        • Initializing OpenGL Features

        • Drawing in Three Dimensions

        • Normals

        • Display Lists

        • Storing a 3D Model

    • Seeing OpenGL in Action

    • Summary

  • Making Things Go Boom

    • What Is Sound?

    • Storing Sound

      • Sound Formats

    • Creating Sound Effects

    • Stock Sound Effects

    • Playing Sounds with Pygame

      • Sound Objects

      • Sound Channels

      • Mixer Functions

      • Hearing the Mixer in Action

    • Playing Music with Pygame

      • Obtaining Music

      • Playing Music

      • Hearing Music in Action

    • Summary

  • Lights, Camera, Action!

    • Working with Textures

      • Uploading Textures with OpenGL

      • Texture Coordinates

      • Rendering Textures

      • Deleting Textures

      • Seeing Textures in Action

      • Mip Mapping

      • Texture Parameters

        • Min and Max Filters

        • Texture Wrapping

    • Working with Models

      • Storing Models

      • OBJ Format for 3D Models

        • Parsing OBJ Files

        • Material Library Files

      • Seeing Models in Action

        • Using the Model3D Class

    • Summary

  • Setting the Scene with OpenGL

    • Understanding Lighting

      • Enabling Lighting

      • Setting Light Parameters

      • Working with Materials

      • Tweaking Parameters

      • Managing Lights

    • Understanding Blending

      • Using Blending

        • Alpha Blending

        • Additive Blending

        • Subtractive Blending

      • Seeing Blending in Action

      • Blending Issues

    • Understanding Fog

      • Fog Parameters

      • Seeing Fog in Action

    • Rendering the Backdrop

      • Skyboxes

        • Creating Skyboxes

        • Rendering Skyboxes

        • Seeing Skyboxes in Action

        • Skybox Enhancements

    • Where to Go for Help

    • Summary

  • Game Object Reference

    • Importing

    • Contributing

    • gameobjects.color.Color

      • Constructor

      • Attributes

      • Methods

      • Class Methods

    • gameobjects.matrix44.Matrix44

      • Constructor

      • Attributes

      • Methods

      • Class Methods

    • gameobjects.vector2.Vector2

      • Constructor

      • Attributes

      • Methods

      • Class Methods

    • gameobjects.vector3.Vector3

      • Constructor

      • Attributes

      • Methods

      • Class Methods

  • Packaging Your Game

    • Creating Windows Packages

      • Using py2exe

      • Building the Installer

    • Creating Packages for Linux

    • Creating Packages for the Mac

  • Index

Nội dung

 CYAN   MAGENTA  YELLOW   BLACK  PANTONE 123 C Books for professionals by professionals ® Beginning Game Development with Python and Pygame: From Novice to Professional Creating computer games is a fascinating combination of an art and a science, and can make a rewarding career or hobby Do you know you can write cutting-edge games that run on Windows, Linux, and Mac OS X with open source technologies and freely available tools? In this book, I introduce you to Python—a powerful, dynamic language— and explain how to use the Pygame library to quickly develop compelling games I also explain how to create three-dimensional graphics using OpenGL, the technology behind many commercial games, such as the Quake series My aim for Beginning Game Development with Python and Pygame is to make game development accessible to as wide an audience as possible Previous programming experience is useful but not essential, because the first two chapters introduce the Python programming language—or serve as a refresher course if you are already familiar with Python Further chapters cover how to use Pygame to set up a graphical display, draw to the screen, handle events, and read input devices I also talk you through essential topics such as creating game characters with artificial intelligence and playing sound (including music) Four chapters are devoted to the topic of three-dimensional graphics in games, and show you how to manipulate objects in a virtual world and render impressive visuals with lighting and special effects The math involved in programming a game with three-dimensional graphics can be intimidating, but I explain it in visual terms rather than the more traditional pure mathematical approach you find in textbooks I also share with you a few of the tips and tricks I have picked up over the years in my career as a professional game developer I hope to be playing one of your Pygame creations in the future! Will McGugan Companion eBook THE APRESS ROADMAP See last page for details on $10 eBook version Beginning Python: From Novice to Professional Foundations of Python Network Programming Beginning Game Development with Python and Pygame The Definitive Guide to Django: Web Development Done Right www.apress.com ISBN-13: 978-1-59059-872-6 ISBN-10: 1-59059-872-5 53999 US $39.99 Beginning McGugan SOURCE CODE ONLINE Companion eBook Available Game Development with Python and Pygame Dear Reader, The EXPERT’s VOIce ® in Open Source Beginning Game Development with Python and Pygame From Novice to Professional Create stunning video games using popular open source technologies! Will McGugan Shelve in Python User level: Beginner–Intermediate 781590 598726 this print for content only—size & color not accurate spine = 0.802" 344 page count 8725.book Page i Wednesday, September 26, 2007 8:08 PM Beginning Game Development with Python and Pygame From Novice to Professional ■■■ Will McGugan 8725.book Page ii Wednesday, September 26, 2007 8:08 PM Beginning Game Development with Python and Pygame: From Novice to Professional Copyright © 2007 by Will McGugan All rights reserved No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher ISBN-13 (pbk): 978-1-59059-872-6 ISBN-10 (pbk): 1-59059-872-5 Printed and bound in the United States of America Trademarked names may appear in this book Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark Lead Editor: Jason Gilmore Technical Reviewer: Richard Jones Editorial Board: Steve Anglin, Ewan Buckingham, Tony Campbell, Gary Cornell, Jonathan Gennick, Jason Gilmore, Kevin Goff, Jonathan Hassell, Matthew Moodie, Joseph Ottinger, Jeffrey Pepper, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Project Manager: Kylie Johnston Copy Editor: Liz Welch Assistant Production Director: Kari Brooks-Copony Production Editor: Kelly Winquist Compositor: Pat Christenson Proofreader: Erin Poe Indexer: Becky Hornyak Cover Designer: Kurt Krames Manufacturing Director: Tom Debolski Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013 Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders-ny@springer-sbm.com, or visit http://www.springeronline.com For information on translations, please contact Apress directly at 2855 Telegraph Avenue, Suite 600, Berkeley, CA 94705 Phone 510-549-5930, fax 510-549-5939, e-mail info@apress.com, or visit http:// www.apress.com The information in this book is distributed on an “as is” basis, without warranty Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work The source code for this book is available to readers at http://www.apress.com in the Source Code/ Download section 8725.book Page iii Wednesday, September 26, 2007 8:08 PM For Maria 8725.book Page iv Wednesday, September 26, 2007 8:08 PM 8725.book Page v Wednesday, September 26, 2007 8:08 PM Contents at a Glance About the Author xv About the Technical Reviewer xvii Acknowledgments xix Introduction xxi ■CHAPTER Introducing Python ■CHAPTER Exploring Python 19 ■CHAPTER Introducing Pygame 41 ■CHAPTER Creating Visuals 67 ■CHAPTER Making Things Move 91 ■CHAPTER Accepting User Input 111 ■CHAPTER Take Me to Your Leader 139 ■CHAPTER Moving into the Third Dimension 165 ■CHAPTER Exploring the Third Dimension 181 ■CHAPTER 10 Making Things Go Boom 211 ■CHAPTER 11 Lights, Camera, Action! 235 ■CHAPTER 12 Setting the Scene with OpenGL 263 ■APPENDIX A Game Object Reference 285 ■APPENDIX B Packaging Your Game 293 ■INDEX 297 v 8725.book Page vi Wednesday, September 26, 2007 8:08 PM 8725.book Page vii Wednesday, September 26, 2007 8:08 PM Contents About the Author xv About the Technical Reviewer xvii Acknowledgments xix Introduction xxi ■CHAPTER Introducing Python Your First Look at Python Numbers Strings Lists and Tuples 11 Loops 16 Python in Practice 18 Summary 18 ■CHAPTER ■CHAPTER Exploring Python 19 Creating Scripts Working with Logic Understanding Booleans Understanding Functions Defining Functions Introducing Object-Oriented Programming Using Classes Python in Practice Using the Standard Library Introducing import Useful Modules for Games Summary 19 20 20 23 24 26 27 31 35 35 36 39 Introducing Pygame 41 History of Pygame 42 Installing Pygame 42 Using Pygame 42 vii 8725.book Page viii Wednesday, September 26, 2007 8:08 PM viii ■C O N T E N T S ■CHAPTER Hello World Revisited Understanding Events Retrieving Events Handling Mouse Motion Events Handling Mouse Button Events Handling Keyboard Events Filtering Events Posting Events Opening a Display Full-Screen Displays Resizable Pygame Windows Windows with No Borders Additional Display Flags Using the Font Module When Pygame Goes Wrong Pygame in Action Summary 44 50 50 53 53 54 56 56 57 57 59 61 61 62 63 64 65 Creating Visuals 67 Using Pixel Power Working with Color Representing Color in Pygame Scaling Colors Blending Colors Using Images Storing Images Working with Surface Objects Drawing with Pygame pygame.draw.rect pygame.draw.polygon pygame.draw.circle pygame.draw.ellipse pygame.draw.arc pygame.draw.line pgame.draw.lines pygame.draw.aaline pygame.draw.aalines Summary 67 68 69 71 73 75 76 76 83 83 84 85 86 87 87 88 89 89 89 ... Beginning Game Development with Python and Pygame From Novice to Professional ■■■ Will McGugan 8725.book Page ii Wednesday, September 26, 2007 8:08 PM Beginning Game Development with Python and. .. work faster and accomplish more with less effort, and when combined with Pygame I could experiment with game ideas and build a complete game from scratch in record time The beauty of Pygame is that... This book was conceived to fill that gap and allow the beginner game programmer to get up to speed with Python and learn the fundamentals of game programming without having to first learn C++, C#,

Ngày đăng: 17/04/2017, 08:30

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN