Acknowledgments |
|
xxi | |
Introduction |
|
xxiii | |
Why Python |
|
xxiv | |
How to Learn to Code |
|
xxiv | |
Who Should Read This Book |
|
xxv | |
What's in This Book |
|
xxvi | |
Python for Kids Website |
|
xxvii | |
Have Fun! |
|
xxvii | |
|
PART I LEARNING TO PROGRAM |
|
|
1 | (170) |
|
|
3 | (12) |
|
A Few Words About Language |
|
|
4 | (1) |
|
|
5 | (5) |
|
Installing Python on Windows |
|
|
5 | (1) |
|
Installing Python on macOS |
|
|
6 | (1) |
|
Installing Python on Ubuntu |
|
|
7 | (1) |
|
Installing Python on Raspberry Pi (Raspberry Pi OS or Raspbian) |
|
|
8 | (2) |
|
Once You've Installed Python |
|
|
10 | (2) |
|
Saving Your Python Programs |
|
|
12 | (1) |
|
|
13 | (2) |
|
2 Calculations And Variables |
|
|
15 | (10) |
|
|
16 | (1) |
|
|
17 | (1) |
|
|
18 | (1) |
|
Variables Are Like Labels |
|
|
19 | (1) |
|
|
20 | (3) |
|
|
23 | (2) |
|
3 Strings, Lists, Tuples, And Dictionaries |
|
|
25 | (18) |
|
|
26 | (1) |
|
|
26 | (1) |
|
Handling Problems with Strings |
|
|
27 | (2) |
|
Embedding Values in Strings |
|
|
29 | (1) |
|
|
30 | (2) |
|
Lists Are More Powerful than Strings |
|
|
32 | (2) |
|
|
34 | (1) |
|
Removing Items from a List |
|
|
35 | (1) |
|
|
35 | (2) |
|
|
37 | (1) |
|
|
38 | (3) |
|
|
41 | (1) |
|
|
41 | (2) |
|
|
41 | (1) |
|
|
41 | (1) |
|
|
41 | (1) |
|
|
41 | (2) |
|
|
43 | (12) |
|
Using Python's Turtle Module |
|
|
44 | (1) |
|
|
44 | (1) |
|
|
45 | (6) |
|
|
51 | (1) |
|
|
51 | (4) |
|
|
52 | (1) |
|
|
52 | (1) |
|
|
52 | (1) |
|
#4 A Tilted Box Without Corners |
|
|
52 | (3) |
|
5 Asking Questions With If And Else |
|
|
55 | (14) |
|
|
56 | (1) |
|
A Block Is a Group of Programming Statements |
|
|
56 | (3) |
|
Conditions Help Us Compare Things |
|
|
59 | (1) |
|
|
60 | (1) |
|
|
61 | (1) |
|
|
62 | (1) |
|
Variables with No Value--None |
|
|
63 | (1) |
|
The Difference Between Strings and Numbers |
|
|
64 | (3) |
|
|
67 | (1) |
|
|
67 | (2) |
|
|
67 | (1) |
|
|
67 | (1) |
|
|
68 | (1) |
|
#4 I Can Fight Those Ninjas |
|
|
68 | (1) |
|
|
69 | (14) |
|
|
70 | (7) |
|
While We're Talking About Looping |
|
|
77 | (3) |
|
|
80 | (1) |
|
|
80 | (3) |
|
|
80 | (1) |
|
|
80 | (1) |
|
#3 My Five Favorite Ingredients |
|
|
81 | (1) |
|
#4 Your Weight on the Moon |
|
|
81 | (2) |
|
7 Recycling Your Code With Functions And Modules |
|
|
83 | (12) |
|
|
84 | (1) |
|
|
85 | (1) |
|
|
86 | (3) |
|
|
89 | (3) |
|
|
92 | (1) |
|
|
92 | (1) |
|
|
93 | (2) |
|
#1 Basic Moon Weight Function |
|
|
93 | (1) |
|
#2 Moon Weight Function and Years |
|
|
93 | (1) |
|
|
93 | (1) |
|
|
94 | (1) |
|
8 How To Use Classes And Objects |
|
|
95 | (20) |
|
Breaking Things into Classes |
|
|
96 | (1) |
|
|
97 | (1) |
|
Adding Objects to Classes |
|
|
98 | (1) |
|
Defining Functions of Classes |
|
|
99 | (1) |
|
Adding Class Characteristics |
|
|
99 | (2) |
|
Why Use Classes and Objects? |
|
|
101 | (2) |
|
Objects and Classes in Pictures |
|
|
103 | (3) |
|
Other Useful Features of Objects and Classes |
|
|
106 | (1) |
|
|
106 | (2) |
|
Functions Calling Other Functions |
|
|
108 | (1) |
|
|
109 | (2) |
|
|
111 | (1) |
|
|
111 | (4) |
|
|
111 | (1) |
|
|
112 | (1) |
|
|
112 | (1) |
|
|
113 | (2) |
|
|
115 | (20) |
|
Starting with the Basic Square |
|
|
115 | (2) |
|
|
117 | (4) |
|
|
121 | (2) |
|
|
123 | (1) |
|
A Function to Draw a Filled Circle |
|
|
124 | (2) |
|
Creating Pure Black and White |
|
|
126 | (1) |
|
A Square-Drawing Function |
|
|
127 | (1) |
|
|
128 | (2) |
|
|
130 | (2) |
|
|
132 | (1) |
|
|
132 | (3) |
|
|
133 | (1) |
|
#2 Drawing a Filled Octagon |
|
|
133 | (1) |
|
#3 Another Star-Drawing Function |
|
|
134 | (1) |
|
#4 Four Spirals Revisited |
|
|
134 | (1) |
|
10 Using Tkinter For Better Graphics |
|
|
135 | (36) |
|
Creating a Clickable Button |
|
|
137 | (2) |
|
|
139 | (1) |
|
Creating a Canvas for Drawing |
|
|
139 | (1) |
|
|
140 | (2) |
|
|
142 | (3) |
|
Drawing a Lot of Rectangles |
|
|
145 | (2) |
|
|
147 | (4) |
|
|
151 | (2) |
|
|
153 | (2) |
|
|
155 | (2) |
|
|
157 | (2) |
|
|
159 | (3) |
|
Making an Object React to Something |
|
|
162 | (3) |
|
More Ways to Use the Identifier |
|
|
165 | (2) |
|
|
167 | (1) |
|
|
167 | (4) |
|
#1 Fill the Screen with Triangles |
|
|
167 | (1) |
|
|
167 | (1) |
|
|
167 | (1) |
|
#4 Fill the Screen with Photos |
|
|
167 | (4) |
|
|
|
11 Beginning Your First Game: Bounce! |
|
|
171 | (14) |
|
|
172 | (1) |
|
|
172 | (2) |
|
|
174 | (2) |
|
|
176 | (7) |
|
|
176 | (3) |
|
|
179 | (1) |
|
Changing the Ball's Starting Direction |
|
|
180 | (3) |
|
|
183 | (1) |
|
|
183 | (2) |
|
|
183 | (1) |
|
|
183 | (1) |
|
|
183 | (1) |
|
|
184 | (1) |
|
12 Finishing Your First Game: Bounce! |
|
|
185 | (16) |
|
|
186 | (1) |
|
|
187 | (2) |
|
Finding Out When the Ball Hits the Paddle |
|
|
189 | (3) |
|
Adding an Element of Chance |
|
|
192 | (4) |
|
|
196 | (1) |
|
|
197 | (4) |
|
|
197 | (1) |
|
|
197 | (1) |
|
|
197 | (1) |
|
#4 Record the Player's Score |
|
|
198 | (3) |
|
PART III MR. STICK MAN RACES FOR THE EXIT |
|
|
|
13 Creating Graphics For The MR. Stick Man Game |
|
|
201 | (12) |
|
|
202 | (1) |
|
|
202 | (2) |
|
Creating the Game Elements |
|
|
204 | (1) |
|
Preparing a Transparent Image |
|
|
205 | (1) |
|
|
206 | (2) |
|
Mr. Stick Man Running to the Right |
|
|
207 | (1) |
|
Mr. Stick Man Running to the Left |
|
|
207 | (1) |
|
|
208 | (1) |
|
|
209 | (1) |
|
|
210 | (1) |
|
|
211 | (1) |
|
|
212 | (1) |
|
14 Developing The Mr. Stick Man Game |
|
|
213 | (20) |
|
|
214 | (1) |
|
Setting the Window Title and Creating the Canvas |
|
|
214 | (1) |
|
Finishing the ___init___ Function |
|
|
215 | (1) |
|
Creating the mainloop Function |
|
|
216 | (2) |
|
Creating the Coords Class |
|
|
218 | (1) |
|
|
219 | (1) |
|
Sprites Colliding Horizontally |
|
|
220 | (2) |
|
Sprites Colliding Vertically |
|
|
222 | (1) |
|
Putting It All Together: Our Final Collision-Detection Code |
|
|
223 | (2) |
|
The collidedjeft Function |
|
|
223 | (1) |
|
The collided right Function |
|
|
224 | (1) |
|
The collided top Function |
|
|
224 | (1) |
|
The collided bottom Function |
|
|
225 | (1) |
|
Creating the Sprite Class |
|
|
225 | (2) |
|
|
227 | (1) |
|
|
228 | (1) |
|
Adding a Bunch of Platforms |
|
|
229 | (1) |
|
|
230 | (1) |
|
|
231 | (2) |
|
|
231 | (1) |
|
#2 Two-Image Checkerboard |
|
|
231 | (1) |
|
|
231 | (1) |
|
|
232 | (1) |
|
15 Creating Mr. Stick Man |
|
|
233 | (10) |
|
Initializing the Stick Figure |
|
|
234 | (1) |
|
Loading the Stick Figure Images |
|
|
234 | (1) |
|
|
235 | (2) |
|
|
237 | (1) |
|
Turning the Stick Figure Left and Right |
|
|
237 | (1) |
|
Making the Stick Figure Jump |
|
|
238 | (1) |
|
|
239 | (2) |
|
|
241 | (2) |
|
16 Completing The Mr. Stick Man Game |
|
|
243 | (28) |
|
Animating the Stick Figure |
|
|
244 | (1) |
|
Creating the Animate Function |
|
|
244 | (3) |
|
|
244 | (2) |
|
|
246 | (1) |
|
Getting the Stick Figure's Position |
|
|
247 | (2) |
|
Making the Stick Figure Move |
|
|
249 | (8) |
|
Starting the move Function |
|
|
249 | (1) |
|
Has the Stick Figure Hit the Bottom or Top of the Canvas? |
|
|
250 | (1) |
|
Has the Stick Figure Hit the Side of the Canvas? |
|
|
251 | (1) |
|
Colliding with Other Sprites |
|
|
252 | (1) |
|
|
253 | (2) |
|
|
255 | (2) |
|
Testing Our Stick Figure Sprite |
|
|
257 | (1) |
|
|
257 | (1) |
|
Creating the DoorSprite Class |
|
|
257 | (1) |
|
|
258 | (1) |
|
|
259 | (1) |
|
|
260 | (7) |
|
|
267 | (1) |
|
|
268 | (3) |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
268 | (3) |
|
AFTERWORD: WHERE TO GO FROM HERE |
|
|
271 | (12) |
|
Installing Python pip on Windows |
|
|
272 | (1) |
|
Installing Python pip on Ubuntu |
|
|
273 | (1) |
|
Installing Python pip on Raspberry Pi |
|
|
273 | (1) |
|
Installing Python pip on macOS |
|
|
274 | (1) |
|
|
275 | (1) |
|
Other Games and Graphics Programming |
|
|
276 | (1) |
|
Other Programming Languages |
|
|
277 | (3) |
|
|
277 | (1) |
|
|
278 | (1) |
|
|
278 | (1) |
|
|
278 | (1) |
|
|
279 | (1) |
|
|
279 | (1) |
|
|
280 | (1) |
|
|
280 | (1) |
|
|
280 | (3) |
A Python Keywords |
|
283 | (16) |
B Python's Built-In Functions |
|
299 | (24) |
C Troubleshooting |
|
323 | (4) |
Index |
|
327 | |