I can’t count the number of times I’ve talked to someone who wants to be a video or computer game programmer, and the following conversation ensues:
Them: I’ve got this fantastic game idea that I want to make. It’s going to change gaming forever, and will make me rich! I just don’t know where to start. How do I start programming games?
Me: How much programming do you already know?
Them: Um… not a whole lot.
Houston, we have a problem.
Programming games requires knowing how to program. In fact, game programming is, in my opinion, among the most technically challenging types of programming. Making a game often requires 2D and 3D graphics programming, UI design, complicated algorithms and data structures, network programming, physics simulations, and even artificial intelligence. And it all has to run efficiently. It is all the toughest parts of programming, all bundled together.
Despite that–perhaps because of that–game programming is also one of the most rewarding ways to apply programming skill. When you compare what you create in a game against yet another web app that lets users create, read, update, and delete purchase orders and account transactions, well… there is no comparison. You will constantly be faced with challenges, and you will need to keep learning and growing your skills, but you will never grow bored of what you do, because there are always new challenges to solve.
This tutorial set is focused on the basics of programming in the C# language. I won’t assume you already know C#. I won’t even assume you know anything about programming. We’ll start from the very beginning and build a solid foundation. Other tutorial sets will focus on actually building games using libraries, frameworks, and game engines.
If you’re not very familiar with programming, it may come as a surprise to you to hear that there are many programming languages out there, not just one. That is, there are lots of ways you can write code. Each of them can be turned into something a computer can run, but they are as different and varied as human languages are.
It is true, however, that once you have learned one, learning others is much easier.
C# is a popular programming language for game programming. Some programming languages give you a ton of power, but are also rather tricky to use. Others are easy to learn and use, but don’t give you as much power. C# strikes a balance between the two, giving you a beautiful combination of being easy to use without sacrificing much in the power category. This makes it a great fit for game programming. (It is, of course, not the only language used for games. For example, lots of games are made with C++ and JavaScript/HTML5, and Python, or any other language out there.)
The focus of this tutorial set is to learn the basics of the C# language. We’ll generally use game-related examples as we go, since that’s probably why you’re here. (Even if it is not, game-related examples are just more interesting.)
We will really only be scratching the surface of the C# language in these tutorials. If you enjoy them and want more depth, please also check out my book, The C# Player’s Guide, for something with far more depth and detail on C#.
In this tutorial set, don’t expect to see or make shiny graphical programs.
The fancy stuff requires knowing the fundamentals. For example, I just looked at the starter code for a MonoGame project. Even just to start, it requires an understanding of classes, inheritance, polymorphism, and generics, all non-trivial concepts, and ones we’ll cover in this tutorial set.
We’ll we focused on console applications initially. Those are those text-only programs–often with the stereotypical white text on a black background.
Console applications are not the most exciting, but they’ll allow us to explore the basics of the C# language without burying us.
You won’t be making console applications forever, especially if you want to make games. But that doesn’t mean console applications can’t be interesting. Take a peek at the following games. They are all console applications (or only slightly more). And they are on Steam and doing rather well.
So while you probably won’t stick with console applications longer than you have to, don’t feel like it is a waste of time. Starting here will let us explore the fundamentals in a cleaner, simpler environment, which will allow us to move faster in time. You can’t program games if you can’t program at all.
Once you are done with this tutorial set, you’ll be prepared to move into other tutorial sets that get into the details of making games in MonoGame, Unity, or some other framework or engine.
We are only scratching the surface here. Even when you’re done with this tutorial set, there will still be lots to learn about C#. But you will be prepared with the basic tools and inventory to strike out into deeper, darker, stranger, and more exciting areas of the game programming world.
Let’s begin!