The Road Ahead
Welcome to this series of lessons on the Python programming language and creating 2D video games with pygame. When I started to learn how to code at the ripe old age of 11, my earliest programs were simple games and animations. This started a passion for coding that I’ve continued pursuing my whole life and I am very pleased to share with you in these notes!
Game programming provides all of the same challenges as other kinds of programming, but games are also visual and interactive which I think helps to motivate students new to the field. Learning to program games is even more fun than playing them because you can design and create your own worlds. Even though games are fun, they are also a serious business; in fact, game development is a multi-billion dollar industry employing thousands of computer science graduates. To become a game developer requires a solid foundation in the principles of computer science and a drive for life-long learning.
In this first set of lessons, we’ll cover the basics of computer hardware and the magic that makes programming work (behind the scenes). From there we’ll dive into Python programming and learn how to write simple programs that take input, perform calculations, and display an output. We’ll end by talking about how to better organize our code into functions, and discuss different types of errors in programming.
What Will You Learn?
The ultimate goal of this course is to teach you enough to be able to create a 2D video game. To achieve that we’ll learn:
-
- Computer Science Fundamentals: You’ll get a gentle but thorough introduction to key concepts in computer science, such as problem-solving techniques, and basic algorithms and data structures. We’ll also emphasize proper terminology for these concepts.
- The Python Language: You’ll learn about the Python language and its most important features. You’ll learn how to write and debug programs and how Python implements many of the “big ideas” of programming. Once you master Python, you can adapt the skills learned to other languages without too much trouble.
- Object-Oriented Programming (OOP): This approach to software development lends itself very well to game development. You’ll learn how to use existing objects, and design your own. Again, most of the concepts covered here will apply to other object-oriented languages such as Java and C++.
- 2D Graphics System: You’ll learn about 2D graphics, including how objects are drawn to the screen, how collisions are detected, and what an animation loop is all about.
Sound interesting? Don’t worry if you don’t understand what some of the terms above mean, that’s what you’re here to learn!
How To Be Successful
A lot of people think that to write computer programs you need to be a math genius or to write games that you need to be a great graphic artist — both of these assertions are false. Learning to code requires similar learning skills as learning mathematics. Most importantly, you need to be persistent and not give up easily when solving a problem. In terms of graphic design skills, it can certainly be an asset if you can create your own game graphics, but there are many free sprite libraries that you can use if you are not.
Having experienced many Computer Science courses both as a student myself and as a teacher, here are the most important things you can do to be successful:
-
- Read the notes carefully! I have yet to find the perfect computer science textbook for high school students, and even if one were written it would be out-of-date within a year or two. Instead of purchasing printed textbooks, I spend a considerable amount of time putting together online notes (like this one) that can be specifically tailored for learners like you and regularly updated. I do this for you! By the way, I love it when students find errors in my notes. This tells me that you’re reading carefully and also helps me improve them for future students. Please let me know if you find any mistakes or topics that you feel could be improved.
- Maintain a Learning Journal! We’ll be covering a lot of material, please don’t just skim over the notes. After reading each section, and trying any example code, record the key ideas (bullet points are fine) so that you have a condensed summary you can refer back to in the future as a quick reference or study aid.
- Practice! Like math, learning to program takes consistent effort and practice. Programming is about doing and you won’t learn if you don’t do as many of the practice exercises as possible.
- Don’t be afraid to experiment! In addition to the points above, I’ve found that the most successful students are naturally curious learners and not afraid to try out new ideas or go beyond what is covered in the notes.
Keep these points in mind as you go through this course.
Why Python?
In any trade, it’s important to learn how to use more than one tool. Programming languages are just the “tools” of computer scientists, and it’s very beneficial for you to learn more than one language. Just as a carpenter has different tools for different jobs, a computer scientist uses different languages to solve different kinds of problems. There are dozens of modern programming languages, and each one has its strengths (and weaknesses).
So, with so many languages to choose from, why Python?
-
- It’s free: The price is right! Guido van Rossum invented Python in the early 1990s and he has generously given his creation away to anyone who wants to use it. There are also many free online communities and resources available to those who want to learn.
- It’s “easy” to learn: Compared to languages like Java and C++, equivalent programs in Python tend to be 3-5 times shorter. In theory, this lighter syntax should make Python easier to learn — but I’ll let you be the judge of that.
- It’s relevant: Not only is Python a good teaching/learning language, but it’s also used by hundreds of thousands of programmers around the world at companies and organizations such as NASA, Google, YouTube, Instagram, Spotify, and Electronic Arts to solve real-world problems.
- It’s powerful: Python has a vast (and growing) set of libraries for networking, GUIs, graphics, games and much more. In this tutorial, we’ll be using a free Python library called pygame to help us write interactive 2D games. The beauty of pygame is that it simplifies the various tasks in creating a game such as setting up the display, drawing to the screen, playing sound etc… Many one-liners in pygame would take dozens of lines in C++, the traditional tool of game developers.
- It’s platform-independent: This means that you can run the same Python program (without having to change any code) on a variety of operating systems, including Windows, Mac OS X, and Linux.
- Universities love it: Many universities (like UofT) teach Python in many first-year programs, so you will have a big advantage if you learn Python before you get to post-secondary.
So, why did Guido van Rossum call his language Python? It turns out that Guido is a big fan of the British comedy troupe “Monty Python’s Flying Circus” and named his language in their honour. Strange but true!
Required Tools
In my beginner tutorial on p5.js, we used a completely web-based editor that required no software installation, just a modern web browser. Python is a more industrial-strength language than p5.js and we will need to install some software for the lessons that follow.
On your home computer, I recommend that you download and install one of the best Python code editors for beginners called Mu. Mu is free, works on Windows, Mac, and Linux, and it includes everything we will need in one download package — a nice code editor, the python interpreter, and the pygame module.
Having taught both in-class and 100% virtually I have found Mu to be the most trouble-free for students to install and use and I highly recommend it to you. However, if you are a little more tech-savvy and have your own IDE, python v3, and pygame v2 module installed and working you are welcome to use that — but you’ll be on your own for “tech support”. 😉
BTW: Using a Chromebook is not ideal for Python/pygame programming but there is a web-based option available called Online Python. You are much better off using Mu if at all possible!
You Try!
-
- A very important part of the learning process is recording and reflecting on what you are learning! Create a new Google doc named “Learning Journal“. Be sure to add today’s date and the title “1-1 Tools for Success” at the top of your entry. Carefully read the notes above and answer the following questions in your Learning Journal:
- What are the four best ways to be successful in learning to program? Which do you think will be the most important for you?
- There are many reasons why Python is considered an ideal first (or second) language to learn. One of the main drivers for Python’s success is its platform independence. Explain what this means and why it’s so important.
- Visit the pygame site to see hundreds of example games created with Python and pygame!
- Please download and install Mu on your home computer.
- A very important part of the learning process is recording and reflecting on what you are learning! Create a new Google doc named “Learning Journal“. Be sure to add today’s date and the title “1-1 Tools for Success” at the top of your entry. Carefully read the notes above and answer the following questions in your Learning Journal: