Gain the basics of Python and use PyGame to create fast-paced video games with great graphics and sounds. You'll also learn about object oriented programming (OOP) as well as design patterns like model-view-controller (MVC) and finite state machines (FSMs). Python, PyGame and Raspberry Pi Game Development teaches you how to use Python and PyGame on your computer. Whether you use Windows, macOS, Linux, or a Raspberry Pi you can unleash the power of Python and PyGame to create great looking games. Included in the text are complete code listings and explanations for "Bricks," "Snake" and "Invaders"— three fully-working games. These allow you to get started making your own great games. Modify them or build your own exciting titles. What You'll Learn Gain the basics of Python and employ it for game development Design your game Build games using game projects as templates like Bricks, Snake, and Invaders Work with user defined functions, inheritance, composition, and aggregation Add sound to your games Implement finite state machines Who This Book Is For Experienced coders or game developers new to Python, PyGame and Raspberry Pi. This book is also for makers interested in getting into game development. Contents at a Glance......Page 4 Contents......Page 6 About the Author......Page 14 About the Technical Reviewer......Page 15 Introduction......Page 16 Chapter 1: What Is a Programming Language?......Page 18 Imperative......Page 20 Object-Oriented......Page 21 Conclusion......Page 22 Chapter 3: Introducing Python......Page 23 Python as a Calculator......Page 24 Keywords......Page 26 Printing......Page 27 String Formatting......Page 29 Naming Variables......Page 31 Python as a Calculator, Part II......Page 32 Arithmetic Operators......Page 34 Data Types......Page 35 String Formatting Again......Page 37 Starting a New File......Page 38 Chapter 5: Making Decisions......Page 41 A Note about Blocks......Page 43 Testing for Equality......Page 44 And......Page 46 Not......Page 47 Nesting Ifs......Page 48 A Note on Switch......Page 49 The for Loop......Page 50 The range() function......Page 51 While Loops......Page 52 Tuples......Page 55 Changing Element Values......Page 56 Deconstructing Tuples......Page 57 List Creation......Page 58 Removing Values from a List......Page 59 Doctor’s Waiting Room Program......Page 60 Iterating Through Dictionaries......Page 62 Conclusion......Page 63 Starting Pixel......Page 64 Creating a New File to Edit a Program......Page 66 Running Your Program......Page 67 Conclusion......Page 68 Initializing PyGame......Page 69 The Main Loop......Page 70 Images and Surfaces......Page 72 Screen Coordinates and Resolution......Page 73 Sprite Sheets......Page 75 Requirement Gathering......Page 76 Program Design......Page 77 Coding......Page 78 Testing......Page 79 Conclusion......Page 80 Chapter 11: Game Project: Bricks......Page 81 The Main Framework......Page 82 Bat Initialization......Page 83 Drawing the Bat......Page 84 Quit Event......Page 85 Ball Initialization......Page 86 Ball Movement......Page 87 Bat and Ball Collision......Page 89 Serving the Ball......Page 90 Brick and Ball Collision......Page 91 Out of Bounds......Page 92 Conclusion......Page 93 Functions as a Menial Task / Mnemonic Device......Page 94 Sending Parameters......Page 96 Named Parameters......Page 97 Accessing Global Variables......Page 98 Real-World Example of a Function......Page 99 Chapter 13: File Input and Output......Page 102 Writing Data to a File......Page 103 Conclusion......Page 104 Chapter 14: Introducing Object-Oriented Programming......Page 105 The Ball Class......Page 106 The ball update() method......Page 108 Constructors......Page 109 SOLID......Page 110 Interface Segregation......Page 111 Dependency Inversion......Page 112 Conclusion......Page 113 Inheritance......Page 115 Base and Child Classes......Page 116 A Note about Constructors and Base Classes......Page 118 Composition......Page 119 Aggregation......Page 121 Conclusion......Page 122 Chapter 16: Game Project: Snake......Page 123 Functions......Page 124 Snake Framework......Page 125 Images......Page 130 The Game Map......Page 131 Drawing the ‘Game Over’ Screen......Page 132 Drawing the Game......Page 134 Drawing the Walls......Page 135 Drawing the Player Data......Page 136 Drawing the Snake......Page 137 Updating the Game......Page 139 The updateGame() method......Page 140 Snake Movement......Page 141 Collision Detection......Page 142 Repositioning the Berry......Page 143 Testing Snake Body Hits......Page 144 Conclusion......Page 145 Chapter 17: Model View Controller......Page 146 Why Use MVC?......Page 147 RobotModel......Page 148 The Model......Page 149 The Robot View......Page 150 The Radar View......Page 151 The Robot Controller......Page 152 The Main Robot Program......Page 154 Conclusion......Page 156 Playing a Sound......Page 157 Non-Player Artificial Intelligence......Page 159 A Finite State Machine Example......Page 160 Finite State Machine Manager......Page 161 Conclusion: The Goal of FSMs......Page 165 Chapter 20: Invaders......Page 167 The Classes......Page 168 The Finite State Machine......Page 169 The Framework......Page 170 Bitmap Font......Page 173 Cutting Up the Image......Page 174 Interstitial Screens......Page 176 The Main Menu......Page 177 The Bullet Classes......Page 179 The Player Classes......Page 181 Testing Player......Page 183 The Alien Swarm Classes......Page 184 Explosions......Page 189 Collision Controller......Page 191 The Main Program......Page 193 The Main Game State......Page 194 Chapter 21: Conclusion......Page 196 Index......Page 197 Gain the basics of Python and use PyGame to create fast-paced video games with great graphics and sounds. You'll also learn about object oriented programming (OOP) as well as design patterns like model-view-controller (MVC) and finite state machines (FSMs).__Python, PyGame and Raspberry Pi Game Development__**What You'll Learn**Gain the basics of Python and employ it for game developmentDesign your gameBuild games using game projects as templates like Bricks, Snake, and InvadersWork with user defined functions, inheritance, composition, and aggregationAdd sound to your gamesImplement finite state machines**Who This Book Is For**Experienced coders or game developers new to Python, PyGame and Raspberry Pi. This book is also for makers interested in getting into game development. "This compact book takes you through the basics of the Python language and lets you experience first hand PyGame, a Python module that allows you to create fast-paced games with great graphics and sounds. You'll also learn about object oriented programming (OOP) as well as design patterns like Module View Controller (MVC) and Finite State Machines (FSM). Learn how to use Python and PyGame on your computer. Whether you have a PC, a Mac, Linux machine or a Raspberry Pi, you can unleash the power of Python and PyGame to create great looking games."--Back cover