Learning C# by Programming Games, second edition
This repository contains the sample code, solutions to the exercises and game assets belonging to the book “Learning C# by Programming Games”, second edition, published by Springer.
How to Get Started
Assuming you own a copy of the book, you need to follow a couple of steps to get started with game development. Once you’ve completed these steps successfully, you’re ready to enjoy the book to its fullest!
The book was written to work with specific versions of Visual Studio (a program for writing and compiling code) and MonoGame (an open-source library that adds game-specific functionality to the C# language). Both Visual Studio and Monogame have received many updates since the book’s release. We’ll do our best to keep the samples and instructions up-to-date, so that you can keep working with the book as long as possible.
In March 2025, we’ve updated our samples to MonoGame 3.8.1.303 and Visual Studio Community 2022. If you want to use these recent versions of the software, follow the “New instructions” below. If you want to use the old software versions from when the book was released, follow the “Original instructions (2019)”.
New instructions (March 2025)
- Follow the instructions in the MonoGame Documentation to first install Visual Studio with the right components and then the MonoGame extension. At the time of writing, the instructions mention MonoGame 3.8.1.303 and Visual Studio Community 2022. If those instructions ever change, please still try to install the versions we mention here. Otherwise, you won’t be able to run our samples!
- Read Chapter 1 of the book (except Section 1.6) and follow the instructions there. This will let you run and change your first MonoGame project in Visual Studio, to verify that the installation worked. Because you’re using newer software versions, some details will be slightly different than in the book. For example, the correct project template is now called “MonoGame Windows Desktop Application” instead of “MonoGame Windows Project”.
- Download all example programs from our repository. To do this, go to our GitHub repository (github.com/egges/csharpgames), click the green ‘Clone or Download’ button near the top, and choose ‘Download ZIP’. Download the ZIP file to a location on your PC. Then extract (unpack) the ZIP file, otherwise the programs won’t work!
- Read Section 1.6 of the book and follow the instructions there. This will let you open an example project and play the first game of our book: Painter.
- Note: the “MonoGame Pipeline Tool” (introduced in Chapter 5 of the book) is now called “MGCB Editor”. It still works the same as in 2019, though.
Original instructions (2019)
- Download and install Visual Studio Community 2017. Follow the installation instructions, and make sure to (at least) include the components for C# development. You will see many more options (and you’re free to install them), but you won’t need them for this book.
- Download and install MonoGame 3.6. You’ll need the file MonoGameSetup.exe from the linked page.
- Download and install the Visual C++ 2012 Redistributable for VS2012. This is required for running any MonoGame project that has text in it. (Otherwise, you will get error pop-ups about missing files such as “freetype6.dll”.)
- Download all example programs from our GitHub repository. To get the projects for VS2017 and MonoGame 3.6, go to the specific version of our repo linked here, click the green ‘Clone or Download’ button near the top, and choose ‘Download ZIP’. Download the ZIP file to a location on your PC. Then extract (unpack) the ZIP file, otherwise the programs won’t work!
- Read Section 1.6 of the book and follow the instructions there. This will let you open an example project and play the first game of our book: Painter.
About the Book
Developing computer games is a perfect way to learn how to program in modern programming languages. This book teaches you how to program in the language C# through the creation of computer games – and without requiring any previous programming experience.
Contrary to most programming books, we do not organize the presentation according to programming language constructs, but instead use the structure and elements of computer games as a framework. For instance, there are chapters on dealing with player input, game objects, game worlds, game states, levels, animation, physics, and intelligence. The reader will be guided through the development of four games showing the various aspects of game development. Starting with a simple shooting game, we move on to puzzle games consisting of multiple levels, and conclude the book by developing a full-fledged platform game with animation, game physics, and intelligent enemies. We show a number of commonly used techniques in games, such as drawing layers of sprites, rotating, scaling and animating sprites, dealing with physics, handling interaction between game objects, and creating pleasing visual effects. At the same time, we provide a thorough introduction to C# and object-oriented programming, introducing step by step important programming concepts such as loops, methods, classes, collections, and exception handling.
The book is also designed to be used as a basis for a game-oriented programming course at university level. Supplementary materials for organizing such a course (including solutions to all exercises) are available in this repository, along with all example programs, game sprites, and sounds.
About the Second Edition
This second edition of the book includes the following improvements:
- The book and all example programs are now based on the library MonoGame 3.6, instead of the obsolete XNA Game Studio.
- Instead of explaining how the example programs work, the text now invites readers to write these programs themselves, with clearly marked reference points throughout the text.
- The book now makes a clearer distinction between general (C#) programming concepts and concepts that are specific to game development.
- The most important programming concepts are now summarized in convenient “Quick Reference” boxes, which replace the syntax diagrams of the first edition.
- The updated exercises are now grouped per chapter and can be found at the end of each chapter, allowing readers to test their knowledge more directly.
Legacy
In case you need the solutions to the exercises or the set of code samples of the first edition of the book, you can find them in the legacy folder of the GitHub repository (github.com/egges/csharpgames).
About the Authors
Wouter van Toll is a post-doctoral researcher at Inria in Rennes, France, as well as a fanatic developer of games and apps. His research focuses on simulating the behavior of human crowds. Previously, he was a lecturer at the Department of Information and Computing Sciences at Utrecht University in the Netherlands. He has taught several bachelor and master courses there, including the introductory Game programming course designed by co-author Arjan Egges.
Arjan Egges is a part-time lecturer in the Department of Information and Computing Sciences at Utrecht University in the Netherlands. He has ample teaching experience related to games and computer animation, and he designed the introductory programming course for the university’s Game Technology bachelor program. Furthermore, Arjan is has launched a platform called Quarterfall, an ICT education tool for creating assignments for students with an automatic feedback mechanism.
Jeroen D. Fokker is an assistant professor in the Software Technology group at Utrecht University. As the director of education, he is responsible for the undergraduate programs in Computer Science and Information Science. He has been teaching introductory programming courses for over 20 years, using C++, Haskell, Java, and C#, as well as courses on compiler construction.
License
The contents of this repository, including all the code and the game assets, is released under the MIT license and as such is free to use for open source and commercial applications.
The example games in this book use the following music pieces:
- Painter - Blipotron (by Kevin MacLeod)
- JewelJam - Klockworx (by Kevin MacLeod)
- PenguinPairs - Nouvelle Noel (by Kevin MacLeod)
- TickTick - Getting it Done (by Kevin MacLeod)
The music is available on Incompetech and it is licensed under Creative Commons: By Attribution 3.0.