Instant ebooks textbook Beginning Game Programming with Pygame Zero: Coding Interactive Games on Raspberry Pi Using Python 1st Edition Stewart Watkiss download all chapters
Instant ebooks textbook Beginning Game Programming with Pygame Zero: Coding Interactive Games on Raspberry Pi Using Python 1st Edition Stewart Watkiss download all chapters
com
https://ebookmeta.com/product/beginning-game-programming-
with-pygame-zero-coding-interactive-games-on-raspberry-pi-
using-python-1st-edition-stewart-watkiss/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmeta.com/product/python-pygame-and-raspberry-pi-game-
development-sloan-kelly/
ebookmeta.com
https://ebookmeta.com/product/python-pygame-and-raspberry-pi-game-
development-1st-edition-sloan-kelly/
ebookmeta.com
https://ebookmeta.com/product/beginning-robotics-with-raspberry-pi-
and-arduino-using-python-and-opencv-pdfdrive-com-1st-edition-jeff-
cicolani/
ebookmeta.com
https://ebookmeta.com/product/the-lioness-in-bloom-modern-thai-
fiction-about-women-susan-fulop-kepner/
ebookmeta.com
The City of Zirdai 1st Edition Maria V Snyder Snyder Maria
V
https://ebookmeta.com/product/the-city-of-zirdai-1st-edition-maria-v-
snyder-snyder-maria-v/
ebookmeta.com
https://ebookmeta.com/product/patient-reported-outcomes-an-
overview-1st-edition-annabel-nixon-diane-wild-muehlhausen-willie/
ebookmeta.com
https://ebookmeta.com/product/dangerous-fun-the-social-lives-of-big-
wave-surfers-1st-edition-ugo-corte/
ebookmeta.com
https://ebookmeta.com/product/small-steps-to-big-reading-converting-
non-readers-into-readers-1st-edition-hozefa-a-bhinderwala/
ebookmeta.com
https://ebookmeta.com/product/the-role-of-the-supreme-court-in-
american-government-and-politics-1835-1864-charles-grove-haines/
ebookmeta.com
Contents
1. Cover
2. Front Matter
3. 1. Creating Computer Games
4. 2. Getting Started with Python
5. 3. Pygame Zero
6. 4. Game Design
7. 5. Graphic Design
8. 6. Colors
9. 7. Tank Game Zero
10. 8. Sound
11. 9. Object-Oriented Programming
12. 10. Artificial Intelligence
13. 11. Improvements and Debugging
14. Back Matter
Landmarks
1. Cover
2. Table of Contents
3. Body Matter
Stewart Watkiss
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.
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
Chapter 1:Creating Computer Games
Inspiration Rather Than Imitation
Playing Games
Create the Resources
Development Cycle
Making Programming Enjoyable
Python and Pygame Zero
Compiled vs.Interpreted
Choosing a Programming Environment
Summary
Chapter 2:Getting Started with Python
Using the Mu Editor
Python Programming
Variables
Strings and Format
Lists
Dictionaries
Tuples
Conditional Statements (if, elif, else)
Simple Quiz Game
Loops – While, For
While Loop
For Loop
Forever Loop – while True
Changing Loop Flow – break and continue
Functions
Variable Scope
Refactoring the Code
Further Improvements
Summary
Chapter 3:Pygame Zero
Pygame Zero Development
Compass Game
Required Files
Running Mu in Pygame Zero Mode
Adding a Background Image
Adding an Actor
Moving the Sprite Around the Screen
Making the Movements More Realistic
Keeping Game State
Detecting Collisions
Change in Direction
Keeping Score
Adding a Countdown Timer
Final Code for Compass Game Version 0.1
Summary
Chapter 4:Game Design
What Makes a Game Enjoyable?
Challenging but Achievable
Choices and Consequences
Rewards and Progress
Likeable Characters
Storyline/Historical Relevance
Educational
Takes an Appropriate Level of Time to Play
Inclusivity
Age Appropriate
Improving Compass Game
Updated Timer
Adding Obstacles
Adding a High Score
Try and Except
Summary
Chapter 5:Graphic Design
Creating a Theme
File Formats
Bitmap Images
Vector Images
Useful Tools
LibreOffice Draw
Inkscape
GIMP
Blender
Create Using Code
Other Sources
Summary
Chapter 6:Colors
Color Mixing
Bouncing Ball
Background Color Selector
Handling Mouse Events
Creating the Color Selector
Summary
Chapter 7:Tank Game Zero
Vector Image of Tank
Creating a Dynamic Landscape
Calculating the Trajectory
Detecting a Collision
Complete Game Code
Improving the Game
Summary
Chapter 8:Sound
Recording Sound Effects
Creating Artificial Sound Effects
Recording Audio on the Raspberry Pi
Connecting a USB Microphone
Using arecord
Audacity
Recording Sounds with Audacity
Creating Music with Sonic Pi
Downloading Free Sounds and Music
Adding Sound Effects in Pygame Zero
Playing Music in Pygame Zero
Piano Game Created with Tones
Summary
Chapter 9:Object-Oriented Programming
What Is Object-Oriented Programming?
OOP Classes and Objects
Creating a Class, Attributes, and Methods
Creating an Instance of a Class (Object)
Accessing Attributes of an Object
Terminology
Encapsulation and Data Abstraction
Inheritance
Design for Object-Oriented Programming
Matching Pairs Memory Game
Creating the Classes
Program File
Summary
Chapter 10:Artificial Intelligence
Memory Game with AI
A Good Memory
Battleships
Summary
Chapter 11:Improvements and Debugging
Additional Techniques
More About Pygame Zero
More About Pygame
Adding Fonts
Scrolling Screen
Reading from a CSV config file
Joysticks and Gamepads
Creating Arcade Games for Picade
RetroPie
Debugging
Error Messages
Check for Variable Names
Print Statements
IDE Debugging Tools
Rubber Duck Debugging
Performance
Space Shooter Game
Summary
Where Next?
Appendix A:Quick Reference
Pygame Zero
Useful Keywords
Actor (Sprite)
Background Image or Color
Sound Effects
Mouse Events
Keyboard Events
Displaying Text
Python 3
Lists
Dictionaries
Conditional Statements (if, elif, else)
Loops
Python 3 Modules
Random
Math
Time
DateTime
Appendix B:More Information
Python
Pygame Zero
Pygame
Index
About the Author and About the Technical
Reviewer
About the Author
Stewart Watkiss
Illustrator: Temple
Language: English
by DAVID MASON
Illustrated by TEMPLE
Grady did not say he was sorry. It would have been of no use
whatever. Nor did he point out that the sun came out so infrequently
that his mistake was one which could be excused. Among the Kya
there are very few mistakes which can be excused, and stepping on
the shadow of a chief is not one of them.
Neither did Anla make any reference to the long friendship between
them, because there would have been no point in doing so. Anla's
eyes grew darker, and the wrinkles at their corners deepened, but
his words were calm, the correct words for such a time.
"Your name was Shassa," Anla said. "You have broken the ghost-
cloak of the Chief, and your name cannot be Shassa. From this
place and this time I take back your name, Shassa, and you have no
name."
Grady did not say anything, because a Kya cannot hear the words of
a man without a name; besides, there was nothing to say, though a
great deal to think about. The Berenice was due in four days. Four
days during which a man without a name would have to avoid the
custom which decreed that such a man must be killed. Killed as soon
as possible, because each day he continued to live was a day which
must be removed from the calendar, a day on which no man's birth
date might be celebrated, or any animal killed for food, or any root
taken from a garden.
Grady turned, and walked slowly, with a stiff back, down the path
away from the Chief's house. To run, or to show fear, would be fatal;
the Kya were themselves in a state of shock at the thing which had
happened, and it would be an hour or more before they began to
prepare for what they had to do. Therefore, Grady held his spine
straight, feeling a cold spot between his shoulderblades where the
first iron-headed arrow might strike in.
Ahead of him, through the village, the silent children ran on light feet,
darting into the houses and out again—the children, who were the
bearers of news. He saw three of them dash toward the agency, and
enter it; and in a moment, as he came up the path, Shallra came out
on the porch, carrying a clay pot in her hands.
"You who were Kotasa," she said, "take this, and drink it to free me
of your name."
It was the standard form of divorce among the Kya, and if the eyes of
Shallra had not been bright with tears, Grady might have slipped. He
took the clay pot, but he did not drink, because he could smell the
faint and bitter odor about it, which was not the odor of the fruit wine
that it should have held.
"Why?" he asked her, quietly.
"Because it is an easier death than the knife and the arrow," she
said, and added, "When you were Kotasa, you were—a good man
for me. Drink the wine." She said it pleadingly. He shook his head.
"I am sorry," Shallra said, and there is nothing harder for a Kya to
say. But she added something even harder for a Kya woman to say;
his name, his proper name, which she had always known but could
never use. Then she walked away, and out of Grady's life, because
he was now a man without a name.
He set the pot down carefully on the agency's steps and went inside.
As he closed the door, there was a high, whistling noise, and a sharp
thud against the door planks. He did not need to look to know that an
arrow stood in its wooden panels.
Grady closed the heavy wooden shutters carefully, not even jumping
when a second arrow whickered through the last shutter as it swung.
He lit a table lamp and took the heavy, seldom-used rifle from the
wall. He did not need to check it; he had oiled and cleaned it once a
week for two years. Instead, he laid it on the table and took a book
down from a shelf.
"General Code of the Federation Authority," Grady read the words on
the spine, and opened it. "Extent of responsibilities of individuals on
mandated planets...."
Under the circumstances, Grady discovered, he could kill any
number of Kya if he were so inclined. The Authority would require a
full report, in quadruplicate, of the circumstances—and as another
arrow struck the door, Grady wondered wryly who would make out
that report.
Also, Grady was not in the least inclined to kill any Kya. If doing so
would have saved his life, he would have shot any number of them
without any particular qualms. But there were no reasons at all to
think that killing any of them would do Grady any good. And Grady
thoroughly understood why it was that they had to kill him. He was
no more angry with the Kya than he had been with the Imperial
Guards, five years before, when they had come up Kanno Hill with
their band playing and their bayonets gleaming. He could remember
how military and colorful they had looked, in comparison to the
overalled, grimy rabble who stood beside him; and how they had
come up that hill again and again, fewer of them each time, and the
band losing a bit of verve on the last. Grady's anger then had been
at the damned fool, whoever he was, who ordered those useless
charges; and his anger now was with himself, because it had been
his own mistake.
There was a growing murmur outside the agency. The villagers were
gathering in the street, and in the yards behind the building. There
was no way out now, and nowhere to go if there had been a way out.
Grady got up, and walked to the door. He opened the sliding panel a
crack and peered out.
The rain had begun again, and through its thin gray curtain he could
see the ranks of villagers, silent, standing around the house, along
the railings, and watching. The men stood in front, each holding his
weapons, his bow bent in his hands. There was Lahrsha, who had
been brother in the Lodge to Grady, and whose blood had been
mixed with his to seal the tribal bond. There was Ahl, whose small
son Grady had nursed through a bad week. There were Grady's
friends and neighbors and brothers, each with an arrow on the nock
for Grady.
"It's a queer thing to happen," Grady said to himself, aloud. The
sound of his own voice startled him; he had become so much a Kya
that to him a man without a name should not have a voice.
The arrows struck oftener now. Grady saw a small group of men
move away, and then return, carrying a short log.
The door, Grady thought. They'll break it down, and come in, with
their grave faces and their polite ways, and they'll cut my throat. And
it won't matter if I kill one or two or ten of them; they'll do it anyway.
They won't hear an argument, because they can't hear me at all,
without a name; they won't even hear any noise I make when they
finish me off.
The log had begun to beat against the door, with a steady thunder.
Grady opened a cabinet, and took out a jar of brown liquid. Quickly
he drank it and sat down, his face graying. His head fell forward on
his arms, and the book of regulations fell to the floor, atop the unfired
rifle.
The Berenice swung outward, riding home to port with an empty
hold. The Mallor Company would not be pleased, but there were
other jobs. And the mate, sitting across the messroom table from
James Grady, put the matter in its simplest terms.
"Just one of those things," the mate said. "You can't be blamed.
They'll take another agent without any fuss, I imagine."
"No doubt of it," Grady said. "Can't say I'm glad to leave, though. It
was a good place."
"I still don't get it," the mate said. "We came in and found you in the
agency, out cold with coca. The door was down, and arrows all over
the place. Why didn't they come in and dig a knife into you?"
"Customs and taboos," Grady said. "I took a chance on it, but I was
pretty sure I was right. Common sense—by their standards. Man's
asleep—his ghost is walking around. If you kill him in his sleep, you
free his ghost, which is very bad, very strong magic. So you have to
wake him up to kill him. And they couldn't wake me up; I was full of
that coca leaf, enough for a week."
*** END OF THE PROJECT GUTENBERG EBOOK ROCKABYE,
GRADY ***
Updated editions will replace the previous one—the old editions will
be renamed.
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the terms
of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.