没有合适的资源?快使用搜索试试~ 我知道了~
首页Python与Pygame入门:打造专业游戏开发之旅
"《初学者入门:Python与Pygame游戏开发》是一本专为有志于游戏开发的新手量身打造的指南,作者Will McGugan是资深的游戏行业专家,曾参与PlayStation 3游戏MotorStorm的开发。本书结合了Python编程语言和流行的Pygame库,旨在让读者深入了解并充分利用这两者的潜力,逐步提升成为创意丰富、全面的游戏开发者。 书中以实践为导向,通过创建一个现实世界的坦克战争游戏实例,带领读者一步步学习。内容涵盖了游戏设计的关键要素,如用户体验(包括对不同平台的支持),音频处理,视觉特效,以及如何实现游戏控制器(如joystick和键盘)的交互。读者不仅能够掌握如何利用Python构建基础游戏框架,还能深入理解游戏设计原则和现代游戏行业的成功要素。 Python作为开源语言,其易学性和灵活性使得它在游戏开发领域具有很大的优势。而Pygame则提供了丰富的功能,帮助开发者快速构建游戏原型,同时允许用户扩展和自定义游戏内容,增强了游戏的可玩性和创新性。 这本书适合那些对游戏开发感兴趣但缺乏经验的人,无论是想开发自己的游戏项目还是寻求在这个充满活力的行业中立足的职业发展道路,都能从中受益匪浅。无论你是编程新手还是有一定基础的程序员,都能通过本书的学习,从新手成长为专业级别的游戏开发者。版权信息和团队编辑、审校人员名单也表明了该书的专业严谨性,确保了读者能获取到最新、最实用的知识。"
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/10147225/bg10.jpg)
xxi
Introduction
I have accumulated a large collection of game development books over the years, virtually all of
which are an inch or two thicker than this book—even though they cover similar subjects and
techniques. The disparity is not because my writing is terse or I use a smaller font—it is because
traditional game development tools tend to require a large amount of technical knowledge that
the reader must first absorb before building even the simplest of games. Even seasoned game
developers find the technical requirements of starting a game to be enough of a barrier that they
are less likely to work on game ideas that are unproven or potentially not commercial-worthy.
Game development may have become easier over the years, with simplified programming inter-
faces and more programmers wishing to share their knowledge, but writing a game is still a
significant undertaking.
When I discovered Python, it lowered a number of barriers to writing software, because
Icould 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 it makes the various tasks in creating a game (setting up a display,
drawing to the screen, playing sound, etc.) only as complicated as they need to be—and it turns
out that’s not particularly complicated at all! Many one-liners in Pygame would take dozens of
lines in C++, the traditional tool of game developers.
Although Python and Pygame are superb tools for rapid game development, there is little
in the way of books or web tutorials for Python game programmers, who often have no choice
but to mentally translate from another language to Python when researching a new topic in
game development. This book was conceived to fill that gap and allow the beginner game pro-
grammer to get up to speed with Python and learn the fundamentals of game programming
without having to first learn C++, C#, Java, or another language first. It was also my opportunity
to explain 3D game programming in a way that is accessible to nonmathematicians—some-
thing that is not easy to find in other books.
In short, this is the book I would have wanted to have when I started out in game development!
Who This Book Is For
This book is for anyone who has thought about creating a computer game, or wants to learn
about the technology behind game development. Although Python is the tool of choice for this
book, many of the techniques covered are equally applicable to other languages.
8725.book Page xxi Wednesday, September 26, 2007 8:08 PM
![](https://csdnimg.cn/release/download_crawler_static/10147225/bg11.jpg)
xxii
■INTRODUCTION
How This Book Is Structured
Beginning Game Development with Python and Pygame is divided into 12 chapters, each of
which builds on the previous chapter—with a few notable exceptions. I’ve structured it so that
you can get results quickly and see something on screen, which you may appreciate if you are
as impatient as I am. Virtually all the listings are self-contained, and hopefully entertaining, lit-
tle projects that run independently. Since experimentation is the best way to learn, you are
encouraged to play with the sample code and modify it to produce different effects. You can
also use any of the code in your own projects—with my blessing!
The first two chapters introduce the Python language in a fairly conversational manner.
If you read them with a Python prompt in front of you, you should find you can quickly pick up
the language. These two chapters don’t make a complete language tutorial, but will cover
enough for you to be able to understand the Python code in the book and write some of your
own. Occasionally, new syntaxes and language features are introduced in the rest of the book,
but I explain them where they are first used. If you are proficient in Python, you can skip
straight to Chapter 3.
Chapter 3 is your first introduction to Pygame and covers its history and capabilities. It also
explains the basics of setting up a graphical display and handling events, skills that are essential
for any game. You will become intimately familiar with the code introduced in this chapter, as
it is used in all the sample code for the rest of the book.
Chapter 4 dives straight into creating visuals and the various ways in which you can draw
to the screen with Pygame. Chapter 5 explores the techniques that game programmers use to
make those images move. You should find the discussion on time-based movement to be par-
ticularly valuable, as it is essential for any kind of animation in a game.
Chapter 6 tells you all you need to know to interface your game with virtually any gaming
device. The sample code in this chapter will have you moving a character around with the key-
board, mouse, and joystick.
Chapter 7 is a little unusual in that it is more self-contained than the others and doesn’t
depend as much on previous chapters. It covers the subject of artificial intelligence and
includes a fully working simulation of an ant’s nest, but the techniques I explain in this chapter
can be used to add seemingly intelligent characters to any game.
Chapters 8 and 9 are a gentle introduction to working with three-dimensional graphics in
Pygame, which is an essential topic since most games have 3D elements these days—even if
they are not full 3D games. I explain the math in visual terms that make it easier to grasp, and
you should find that it is not as an intimidating a subject as it first appears.
Chapter 10 takes a break from 3D graphics to discuss how to use Pygame to add sound
effects and music, and even includes a fully working jukebox application.
The final two chapters build on Chapters 8 and 9 to advance your knowledge of 3D graph-
ics, and explain how to take advantage of the dedicated game hardware on your graphics card.
By the end of Chapter 11 you will have enough knowledge to render and manipulate a three-
dimensional object on the screen. Chapter 12 explores several techniques you can use to create
even more impressive 3D visuals and generate special effects.
In addition to the 12 chapters, there are two appendixes: Appendix A is a reference to the
Game Objects library that is used throughout this book, and Appendix B explains how you can
package your game and send it to others.
8725.book Page xxii Wednesday, September 26, 2007 8:08 PM
![](https://csdnimg.cn/release/download_crawler_static/10147225/bg12.jpg)
■INTRODUCTION
xxiii
Prerequisites
To run the code in this book, you will need at least version 2.4 of Python and version 1.7.1 of
Pygame, which you can download from www.python.org and www.pygame.org, respectively. If
you want to run the 3D sample code, you will also need PyOpenGL, which you can download
from pyopengl.sourceforge.net. All are free software, and this book contains instructions on
how to install them and get started.
Downloading the Code
The source code for this book is available to readers at www.apress.c om in the Source Code
section of this book’s home page. Please feel free to visit the book’s home page on the Apress
web site and download all the code there. You can also check for errata and find related titles
from Apress.
Contacting the Author
I am happy to respond to any questions regarding this book’s content and source code. Feel
free to e-mail me at will@willmcgugan.com, or alternatively post a comment on my blog:
www.willmcgugan.com.
I hope you find this book informative and that you enjoy reading it! If it inspires you to
write a game, I would be more than happy to be one of your play-testers.
8725.book Page xxiii Wednesday, September 26, 2007 8:08 PM
![](https://csdnimg.cn/release/download_crawler_static/10147225/bg13.jpg)
1
■ ■ ■
CHAPTER 1
Introducing Python
The language we are going to use to make games is Python, so called because the original
author of the language was a fan of the UK television series Monty Python. Python is popular in
game development, but it is also used to create everything from applications to web sites. Even
NASA and Google rely heavily on Python.
There are plenty of alternative languages that can be used to create games, but I have
chosen Python because it has the tendency to take care of the details and leave you—the pro-
grammer—to concentrate on solving problems. For our purposes, solving problems means
displaying game characters on the screen, making them look great, and having them interact
with a virtual environment.
This chapter is a friendly introduction to Python; it will get you up to speed with the lan-
guage so that you can read the sample code and start writing code of your own. If you are
familiar with Python, then feel free to skip the first two chapters. Read on if you are completely
new to Python or if you would like a refresher course.
To start working with Python, you will first need to install a Python interpreter for your
computer. There are versions for PC, Linux, and Mac. We will be using version 2.4 of Python,
which is not quite the most recent version but is supported by all the code libraries we will
be using.
■Note By the time this book is published, it is likely that all the libraries used in this book will support a
more recent version of Python. You don’t have to get the latest version, but if you do want to try out the new
features then you can because new versions will run files created for older versions.
Your First Look at Python
The usual way of running Python code is to save it to a file and then run it. We will be doing this
soon, but for now we are going to use Python in interactive mode, which lets us enter code a line
at a time and receive immediate feedback. You will find this to be one of Python’s strengths. It
is an excellent aid to learning the language, but even experienced Python programmers often
return to interactive mode to do the odd experiment.
8725.book Page 1 Friday, August 24, 2007 5:20 PM
![](https://csdnimg.cn/release/download_crawler_static/10147225/bg14.jpg)
2
CHAPTER 1
■ INTRODUCING PYTHON
Once you have installed Python on your system, you can run it like any other program. If you
have Windows, it is simply a matter of double-clicking the icon or selecting it in the Start menu.
For other systems with a command line, just type python to launch Python in interactive mode.
When you first run the Python interpreter, you will see something like the following:
ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69, Apr 11 2006, 15:32:42) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> _
The text may vary depending on the version of Python you are running and the platform (Win-
dows, Mac, Linux, etc.) you are running it on. But the important part is the three chevrons
(>>>), which is the Python prompt—it is your invitation to type in some code, which Python will
then attempt to run.
A long-standing tradition in computer language tutorials is that the first program you
write displays the text “Hello, World!” on the screen—and who am I to break with tradition! So
take a deep breath and type print 'Hello, World!' after the prompt. The Python window will
now display this on the prompt line:
>>> print 'Hello, World!'
If you hit the Enter key, Python will run the line of code you just entered, and if all goes well
you will see this on the screen:
>>> print 'Hello, World!'
Hello, World!
>>> _
Python has executed your line of code, displayed the result, and given you a new prompt to
enter more code. So how exactly does our line of code work? The word print is a statement that
tells Python to print what follows to the screen. Following the print statement is a string, which
is simply a collection of letters and/or digits. Python treats anything between quotes (') as a
string. Try entering your own text between the quote marks and you should find that Python
will print it to the screen just as before.
Numbers
We will come back to strings later, but for now let’s start with the most simple piece of informa-
tion that Python can work with: numbers. Python is so good at working with numbers that you
can use it almost like a calculator. To see it in action, type the following into Python (you don’t
need to type the prompt, since Python displays it for you):
>>> 2+2
Take a guess at what Python will make of this line and hit Enter. If you guessed 4, help yourself
to a cookie—that is exactly what it does. Python has evaluated 2+2, which in Python terms is
known as an expression, and displayed the result. You can also use – for subtract, * for multiply,
8725.book Page 2 Friday, August 24, 2007 5:20 PM
剩余329页未读,继续阅读
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/32650c996b1a4a9eb9209fb7a4d32094_mosci.jpg!1)
mosci
- 粉丝: 2
- 资源: 5
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- 岩石滑动与断层冲击地压:声发射特征分析
- 新时代煤炭工业八大战略新取向剖析
- 开采强度对华亭矿区冲击地压危险性的影响分析
- 新安煤矿探采对比:影响安全生产的关键因素与技术支撑
- 210MW循环流化床锅炉引风机变频改造优化与节能效果
- 浅埋煤层开采沉陷预测:方法应用与影响分析
- 优化巷道过陷落柱支护方案:数值模拟与现场试验
- 坚硬顶板定向断裂爆破技术:安全高效采煤新方案
- 北航2019算法课作业解析:投资策略与凸子多边形优化
- 断层破碎带垮冒下堆积体边界抗力分布关键影响因素
- 哈拉沟选煤厂优化末煤系统提高效率与处理能力
- 瓦斯涌出影响下采动煤体蠕变失稳研究
- 提升煤矿装载效率的可控箕斗定量装载设备设计
- 水分调控下烟煤瓦斯吸附特性对比研究
- 重介质悬浮液密度控制硬件设计与选型探讨
- 坚硬顶板巷道支护参数设计:现场测试与数值分析
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)