Stewart Watkiss

Beginning Game Programming with Pygame Zero

Coding Interactive Games on Raspberry Pi Using Python

Stewart Watkiss
Redditch, UK
ISBN 978-1-4842-5649-7e-ISBN 978-1-4842-5650-3
Apress standard
© Stewart Watkiss 2020
This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of 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.
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-mail [email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation.

For my children Oliver and Amelia.

You are the inspiration in my life.

Introduction

This book is designed for anyone wanting to learn programming through making fun games. It will also be useful for someone who has already learned the basics of programming and wants to learn how to add fun graphics and create their own games.

It is focused on making the games rather than teaching programming theory. In this book, you're more likely to see code on how gravity affects a missile’s trajectory rather than the most efficient way to search through data. Even then the code is kept simple as games should be more about playability rather than complex physics.

The book starts with a simple text-based game to cover the basics of programming in Python. It then quickly moves on to creating simple graphical games in Pygame Zero. The book introduces object-oriented programming to make it easier to make more complex games. It also explains how you can create your own graphics and sounds.

Throughout the book, you will get to apply the new techniques in a variety of 2D games. As well as some new games, there are some variations on class games including a space shooter game and battleships.

The games are designed to run on the Raspberry Pi, although they can be used on other platforms that support Python 3 with Pygame Zero .

The games you make will be playable and hopefully fun to play. They are only the beginning. If all you ever do is copy the code from this book, then you are only going to learn so much, but by adapting and improving these games, they can become more enjoyable as well as helping you learn more than you ever will from just typing out code that's written down for you. For each of the games, there is a list of suggestions for you to develop the games further.

All the code and resource files used in the book are available from the page to accompany the book at https://www.apress.com/gb/book/9781484256497 .

Acknowledgments

My family has been very supportive in my maker activities and while writing this book. Thank you to my wife Sarah for her support and to my children Oliver and Amelia who have been a source of inspiration and help while writing the book. Oliver has been particularly helpful in testing the games and giving me feedback, and my daughter’s knowledge of music was a great help while writing about making sounds.

I’d also like to thank the team behind the Raspberry Pi including the Raspberry Pi Foundation and the community that has grown around it. I’ve also been inspired by the work of Nicholas Tollervey who created the Mu editor that is used throughout the book and Daniel Pope who created Pygame Zero, without which the book wouldn’t have been possible.

I’m also grateful to all the support from the team at Apress, to Jessica Vakili for her support in putting the book together, and to Sai Yamanoor for the technical review. There are also many other people who helped to contribute through reviews and getting the book production ready.

Table of Contents
Lists 334
Loops 335
Random 336
Math 336
Time 337
Python 339
Pygame 340
Index 341
About the Author and About the Technical Reviewer
About the Author
Stewart Watkiss
../images/488486_1_En_BookFrontmatter_Figb_HTML.jpg

is a keen maker and programmer. He has a master’s degree in electronic engineering from the University of Hull and a master’s degree in computer science from Georgia Institute of Technology.

He has over 20 years of experience in the IT industry, working in computer networking, Linux system administration, technical support, and cyber security. While working toward Linux certification, he created the web site www.penguintutor.com . The web site originally provided information for those studying toward certification but has since added information on electronics, projects, and learning computer programming.

Stewart often gives talks and runs workshops at local Raspberry Pi events. He is also a STEM Ambassador and Code Club volunteer, helping to support teachers and children learning programming.

 
About the Technical Reviewer
Sai Yamanoor

is an embedded systems engineer working for an industrial gases company in Buffalo, NY. His interests, deeply rooted in DIY and open source hardware, include developing gadgets that aid behavior modification. He has published two books with his brother, and in his spare time, he likes to contribute to build things that improve quality of life. You can find his project portfolio at http://saiyamanoor.com .

 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.211.87