Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf

所需积分/C币:9 2019-05-26 17:33:36 5.87MB PDF
26
收藏 收藏
举报

2019年 Apress出版 This book is intended for anyone who wants to learn how to program games. It is ideally suited to students who want to learn Python and PyGame on their Raspberry Pi. While not necessary, this book has been oriented toward the Raspberry Pi computer. The Python programming language is ideally suited to beginners and experts alike. The skills you will learn in this book are easily transferable to other computer languages too. If you are unfamiliar with the Raspberry Pi, there are several good eBook guides on getting started including mine called A Slice of Raspberry Pi, available from all good eBook retailers. This book assumes that you are familiar with the Raspberry Pi computer and that you have the Raspberry Pi Foundation’s recommended Raspbian operating system installed. Raspbian is a distribution of the Debian Linux operating system built specifically for the Raspberry Pi. This distribution contains all the Software Development Kits (SDKs) including one for Python that includes PyGame. If you don’t have Raspbian installed, you will have to ensure that you have Python and PyGame installed on your system. Don’t have a Raspberry Pi? Not to worry, you can still learn Python and PyGame. The code in this book will work on other OSs with Python and PyGame installed; Python is a platform-independent language. You can obtain more information and download versions of Python from www.python.org. PyGame can be obtained from www.pygame.org/. Sprites from Ari Feldman’s SpriteLib have been used for the projects contained in this book.
Python, PyGame, and Raspberry pi Game Development Sloan Kelly Niagara Falls, ON, Canada ISBN-13(pbk):978-1-48424532-3 ISBN-13( (electronic):978-1-4842-4533-0 https://doi.org/10.1007/978-1-4842-4533-0 Copyright o 2019 by Sloan Kelly part of the material is concerned, specifically the rights of translation, reprinting, reuse or a This work is subject to copyright All rights are reserved by the publisher, whether the whole or illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way and transmission or information storage and retrieval, electronic adaptation, computer software or by similar or dissimilar methodology now known or hereafter developed Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Spandana Chatterjee Development Editor: James Markham Coordinating editor: Divya Modi Cover designed by eStudio Calamar CoverimagedesignedbyFreepik(www.freepik.com) Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax(201)348-4505 e-mailorders-ny@springer-sbm.com,orvisitwww.springeronline.com.ApressMedia,Llcisa California LLC and the sole member (owner )is Springer Science+ Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation Forinformationontranslationspleasee-mailrights@apress.com,orvisithttp://www.apress.com/ rights-permissions Apress titles may be purchased in bulk for academic, corporate, or promotional use eBook versions and licenses are also available for most titles for more information reference our print andebooKbulksaleswebpageathttp://www.apress.com/bulk-sales Any source code or other supplementary material referenced by the author in this book is available toreadersonGithubviathebooksproductpagelocatedatwww.apress.com/978-1-4842-4532-3 Formoredetailedinformationpleasevisithttp://www.apress.com/source-code Printed on acid-free paper www.allitebooks.com For annamarie www.allitebooks.com Table of contents About the author mmm xvii About the technical reviewer ■■■■■■■■■■■■■■■ XIX Acknowledgments Introduction…xi Chapter 1: What is a Programming Language? amann What does a computer program do? 123 Conclusion Chapter 2: What Is Python? Programming Styles 重■重DD重日重重D object-Oriented 578 Functional What Is Pygame? Conclusion Chapter 3: Introducing Python.mmmmmmmmmam 11 The terminal window Running the Python Interpreter Python Is Interpreted Python As a Calculator…… Keywords Printing,,,,,,,,,,,,,,,, String Formatting….,.,……19 www.allitebooks.com TABLE OF CONTENTS Variables…22 Naming variables…22 Python As a Calculator, Part ll Arithmetic Operators 26 Data Types…...........,27 Numeric Types…….27 String Formatting Again Conclusion 重■重■面D■口重■重■目面DD■重■D重面DD■重■重■面DD■重■重面DD重■重面DD重■重面D重■重面DD重■重面DB Chapter 4: Breaking Free from the Interpreter a33 What is idle? 33 Starting IDLE…… Starting a New file. mmmmmmmmmmmmmmmmmmmmmmmmmm 34 Hello, World 6 Running from the command Line. Running from Inside IDLe. .mmmm.m..mmmm..m. 38 Conclusion Chapter 5: Making Decisions.m mm m mmammaama 41 A Note about blocks ummmm. 44 Testing for Equality 45 Using Boolean Logic 50 And…50 Not 重■D,重夏■重,重 52 Nesting Ifs 52 A Note on switch54 Conclusion…54 TABLE OF CONTENTS Chapter 6: Making the Raspberry Pi Repeat Itself ■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 55 The for Loop The range0 Function . While Loops……58 Counting ■重重■面重D面重■重,■面重D,面重夏重,■ 58 Sentinel……60 Conditionalooggmg. 62 Conc|uson…62 Chapter 7: Containers 63 Container nomenclature Tuples 64 Removing Elements from a tuple.mmmn.nannn.m.m.m...m......... 64 Changing Element Values 重重重D目日D重DD重重D日重D目目面重重重B 65 Tuples in Printing Deconstructing Tuples 67 Lists ■■■ 67 List creation 68 Adding values to the List 重重DD■重面D日面重重重D日D重D重重D重重 Removing values from a list n69 Doctor' s Waiting Room Progran.,,,,,……70 Dictionaries Iterating Through Dictionaries 74 Adding New Items to Dictionaries. Removing Entries from a Dictionary 74 Conclusion ,75 TABLE OF CONTENTS Chapter 8: Putting It Together: Tic-Tac-Toe mmmmmam 77 The rules 77 Program Layout..,,,,,………79 Variables…79 The game Save and run 85 Conclusion mmmm. 85 Chapter 9: Basic Introduction to Py Gamemmmammmmmanna.87 Importing the Py Game Framework Initializing PyGame The Main Loop .. Images and Surfaces… Creating Images 93 Loading Images..mmemmaeememamemaemeemmmeemmnat Drawing Images.mm.. nnnmnnmmmmmm 94 Screen Coordinates and resolution 94 Sprite Sheets 95 Fu‖ Listing 重■重DD重重重 重■重DD重DD图重重D重重D目 Conclusion Chapter 10: Designing Your Game ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■口■■口■■■■口 99 Initial Concept… Prototyping…… 100 Functional Specification 101 eapon Firing…… 101 Program Design ...mmmemmememmmemmemmaemmnnnmnnn 101 Coding 102 TABLE OF CONTENTS Testing,……104 teration…105 Conclusion… …105 Chapter 11: Game Project: Bricks nmmmmmmmmmmmmmmmmmmmmm 107 The main framework…108 Images 109 Moving the Bat.… 110 Bat initialization m 111 Drawing the bat....mmmmmmmm.112 Moving the bat mmmmmmmm 112 Moving the bi 4 Ball initializati0n…………………14 Ball movement. Bat and ball collision Serving the Ball 120 Brick Wall mmmm. 121 Brick and ball collision 122 Out of bounds 124 Conclusion 125 Chapter 12: User-Defined Functions mmmmmammmmmamammmmmmmmmmmmmmmmmm 127 What is a function Format of a function ,127 Functions as a menial task Sending Parameters 29 Default argument values n131 Named TABLE OF CONTENTS Returning values Returning Tuples Accessing Global Variables 135 Real-World Example of a Function n136 Conclusion……139 Chapter 13: File Input and output mamaaammmmmmmmn 141 Reading a File from Disk...m.mmmm......... 141 Writing data to a File .ssns. 143 Reading and Writing Containers to a File..…,…144 Writing Your Own Serializer...................... 145 Writing Your Own Deserializer∴… JSON 148 JsoN Serialization 148 JS0NDeseriaizZer..149 Handling Errors…,,.,.,.,.,.,.,.,.,.,,,10 Conclusion 151 Chapter 14: Introducing Object-Oriented Programming mmmmmmmmm 153 Classes and Objects 154 Encapsulation .mmmmm Abstraction.…n 155 nheritance…155 Polymorphism ,155 Why should You Use 00P? 156 Data Hiding 156 Reusable ,156 Easier to Code and Test Separately.

...展开详情
试读 127P Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf
立即下载
限时抽奖 低至0.43元/次
身份认证后 购VIP低至7折
一个资源只可评论一次,评论内容不能少于5个字
您会向同学/朋友/同事推荐我们的CSDN下载吗?
谢谢参与!您的真实评价是我们改进的动力~
上传资源赚钱or赚积分
最新推荐
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf 9积分/C币 立即下载
1/127
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第1页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第2页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第3页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第4页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第5页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第6页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第7页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第8页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第9页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第10页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第11页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第12页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第13页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第14页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第15页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第16页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第17页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第18页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第19页
Python, PyGame, and Raspberry Pi Game Development, 2nd Edition.pdf第20页

试读结束, 可继续阅读

9积分/C币 立即下载