Introduction

Welcome to Learn 2D Game Development with C#. Because you have picked up this book, you are likely interested in creating your own games with the C# programming language. This book teaches you how to develop 2D games with C# and MonoGame by giving you background and conceptual information so you can play, examine, and develop 2D games.

This book identifies and presents relevant concepts from software engineering, computer graphics, mathematics, physics, and game development—all in the context of building 2D games. The projects you’ll develop in this book are based on MonoGame, the open source implementation of of the popular XNA Framework discontinued by Microsoft. The presentations are tightly integrated with the analysis and development of source code; you’ll spend much of the book building gamelike concept projects that demonstrate game principles and components. By building on concepts introduced early on, the book leads you on a journey through which you will master the basic concepts behind game development while simultaneously gaining hands-on experience developing simple but working 2D games.

By the end of the book, you will be familiar with the implementation details of 2D games, and you should feel competent in implementing commonly encountered 2D game behaviors using MonoGame.

Who should read this book

This book is targeted toward programmers who are familiar with basic object-oriented programming concepts and have a basic to intermediate knowledge of an object-oriented programming language like C# or Java. For example, if you are a student who has taken a few introductory programming courses, an experienced developer who is new to games and graphics programming, or a self-taught programming enthusiast, you will be able to follow the concepts and code presented in this book with little trouble. If you’re new to programming in general, it is suggested that you first become comfortable with the C# programming language before tackling the content provided in this book.

Assumptions

You should be experienced with programming in an object-oriented programming language, such as C# or Java. The examples in this book were created with the assumption that readers understand data encapsulation and inheritance. In addition, you should also be familiar with basic data structures such as linked lists and dictionaries and be comfortable working with the fundamentals of algebra and geometry, particularly linear equations and coordinate systems.

Who should not read this book

This book is not designed to teach readers how to program, nor does it attempt to explain intricate details of C# or MonoGame. If you have no prior experience developing software with an object-oriented `programming language, you will probably find the examples in this book difficult to follow.

On the other hand, if you have an extensive background in game development for other platforms and with other programming languages, the content here will be too basic; this is a book intended for developers without 2D game development experience.

Organization of this book

This book divides the process of building 2D games into essential topic areas: tools, graphics, special effects, math and physics, and logic and behavior. These topics are organized into chapters. Each topic area (chapter) is then subdivided into essential concepts; for example, concepts related to computer graphics include coordinate spaces and camera abstraction. The book introduces each concept via a gamelike example organized as a section in a chapter. Each has an associated step-by-step project workflow. In this way, each section in the book corresponds to a single project or concept.

The first section begins with a simple project that you will build from scratch. Throughout the text, each subsequent section builds upon the sections that precede it. While this makes it a bit difficult to skip around in the book, it will give you practical experience and a solid understanding of how the different concepts relate to one another. In addition, rather than always working with new and minimalistic projects, you gain experience with building larger and more interesting projects.

The projects themselves start with simple concepts, such as creating objects and moving them across the screen, but quickly move to more complex concepts, such as implementing pixel-accurate collision detection and working with user-defined coordinate systems. In this way, while the concepts are presented in simple 2D gamelike examples, by the end of the book, your code base for the projects will include all the essential concepts covered.

That final code base, which you will have developed incrementally over the course of the entire book, serves as a great platform on which you can begin building your own 2D games. This is exactly what the very last chapter of the book does, leading you from conceptualization, to design, to implementation of a not-so-simple casual 2D game.

Finding your best starting point in this book

As a reader, there are several ways for you to follow along with this book. The first and most obvious is to enter the code into your project as you follow through each step in the book. From a learning perspective, this is probably the most effective way to absorb the information presented; however, we understand that it may not be the most realistic, due to the amount of code or debugging that approach may require. To help ameliorate this, each of the sections and projects in this book has two corresponding source code folders: the starter project in a 1.Starting folder, and the completed project in a 2.Completed folder. You can see an example of this structure in Figure 1. The starter projects allow you to follow along in the corresponding section by entering the code as you encounter it in the book, while the completed project lets you run and see the project in its completed state.

9781430266044_unFM-01.jpg

Figure 1-1. The folder structure for the book projects

We recommend that you refer to the completed project when you begin a new section. Doing so lets you preview the current section’s project, giving you a clear idea of the end goal, and letting you see what the project is trying to achieve. You may also find the completed project code useful when you have problems while building the code yourself, because you can compare your code with the completed project’s code during difficult debugging situations.

image Note  We have found the WinMerge program (http://winmerge.org/) to be an excellent tool for comparing source code files and folder.

Finally, after completing a project, we recommend that you compare the behavior of your implementation with the completed-project implementation provided. By doing so, you can observe whether your code is behaving as expected.

Conventions and features in this book

This book presents information using conventions designed to make the information readable and easy to follow:

  • Each example is built on top of prior ones; however, complete source code is provided for each exercise, so you can use that to skip sections you don’t need.
  • A screen shot and an outlined overview of the steps involved precede each step-by-step procedure, so that you will know what to expect.
  • When necessary, we provide relevant background information before beginning the analysis of how to implement the concept. For example, the book discusses differences between pixel and user-defined spaces before analyzing how to implement a user-defined coordinate system.
  • Source code analysis is divided into distinct steps, where each step contributes to the eventual implementation of the concept.
  • Items that you should type (excepting source code) appear in bold text.
  • Programming-related items, such as class names, variable names, namespaces, and so on, appear in italics.
  • When you need to press two keys at once, such as holding the Control key while pressing the A key, this book shows the two keys separated by a plus (+) sign—for example, Ctrl+A.

System requirements

You will need the following hardware and software in order to follow the examples in this book:

  • Windows 7 or higher
  • Microsoft Visual Studio 2010 or higher, any edition
  • MonoGame V3.0 or higher
  • A computer that has a 1.6 GHz or faster processor (2 GHz is recommended)
  • More than 1 GB of RAM
  • 1 GB of available hard disk space
  • A Microsoft DirectX 9–capable video card that supports at least OpenGL 3 and can run at a resolution of 1,024×768 or higher
  • An Internet connection, for downloading software or chapter examples

All of the projects in this book were built to use either your keyboard or a Microsoft Xbox 360 controller for Windows. You should be able to work with any wired Xbox 360 controller by plugging it into a USB port on your computer; however, wireless Xbox 360 controllers require an Xbox 360 wireless receiver for Windows to function on the PC. If you instead want to use a mouse with your Windows-based projects, you will need to make some code modifications. The types of changes you’ll need to make are addressed near the end of the Draw and Control project in Chapter 2.

You can find details on how to download, install, and configure Visual Studio and MonoGame in Chapter 1, “Introducing 2D Game Development in C#.”

Code samples

With the exception of the first chapter, all the chapters in this book include examples that let you interactively experiment with and learn the new materials. You can download all the code for all the projects, including the associated assets (images, audio clips, or fonts) in both their pre-example and completed states from the following page:

http://www.apress.com/9781430266044

Follow the instructions to download the source code file labeled 9781430266044.zip. To install the code samples, unzip the source code file. You should see the folder structure shown previously in Figure 1. As described previously, the starter project is in the 1.Starting folder, and the corresponding completed project is in the 2.Completed folder. With Visual Studio properly installed, you can double-click the corresponding solution (.sln) file to begin working with any of the provided projects.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset