Book Image

Learning Windows 8 Game Development

By : Michael Quandt
Book Image

Learning Windows 8 Game Development

By: Michael Quandt

Overview of this book

With the recent success of a lot of smaller games, game development is quickly becoming a great field to get in to. Mobile and PC games are on the rise, and having a way to create a game for all types of devices without rewriting everything is a huge benefit for the new Windows 8 operating system. In this book, you will learn how to use cutting-edge technologies like DirectX and tools that will make creating a game easy. This book also allows you to make money by selling your games to the world. Learning Windows 8 Game Development teaches you how to create exciting games for tablets and PC on the Windows 8 platform. Make a game, learn the techniques, and use them to make the games you want to play. Learn about graphics, multiplayer options, how to use the Proximity + Socket APIs to add local multiplayer, how to sell the game outright, and In-App Purchases. Learning Windows 8 Game Development guides you from the start of your journey all the way to developing games for Windows by showing you how to develop a game from scratch and sell it in the store.With Learning Windows 8 Game Development, you will learn how to write the code required to set everything up, get some graphics on screen, and then jump into the fun part of adding gameplay to turn a graphics sample into a proper game. From there, you'll look at how to add awesome features to your game like networking, motion controls, and even take advantage of new Windows 8 features like live tiles and sharing to make your players want to challenge their friends and keep playing. This book wraps up by covering the only way a good game can finish development: by shipping the game on the Windows Store. You'll look at the things to remember to make certification painless and some great tips on how to market and sell your game to the public.
Table of Contents (17 chapters)
Learning Windows 8 Game Development
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

With the rising popularity of mobile platforms such as phones and tablets, the games industry has found a new market eager for more and more games. With the introduction of Windows 8, Microsoft has entered this market, bringing years of experience and widely-used game development technologies such as Direct3D. In this book, we will take a look at how you can get started making a game for Windows 8, so you can sell to both the desktop and tablet markets. Through this book you'll learn how to develop a simple side-scrolling space shooter, and enhance the game with Windows 8 features such as Share Charm integration and Live Tiles.

What this book covers

Chapter 1, Getting Started with Direct3D, looks at how we can initialize Direct3D in Windows 8 and prepare all of the resources to display something on the screen.

Chapter 2, Drawing 2D Sprites, is where we will take our first steps into drawing images on the screen. You'll learn about the different concepts involved in drawing 2D images, as well as some useful libraries to make 2D rendering even easier.

Chapter 3, Adding the Input, will teach you how to read from the touch screen, keyboard, mouse, and GamePad to implement the interactive element of your game.

Chapter 4, Adding the Play in the Gameplay, will show you how to structure your game and add the mechanics that make the game fun. We'll look at code structure and the subsystems you will need to complete the game.

Chapter 5, Tilting the World, is an introduction to the sensors on the device that will enable new gameplay genres and opportunities. You will learn about the different options available and how to easily work with them to get different types of input.

Chapter 6, Bragging Rights, will look at the Share Charm and Live Tiles in Windows 8. Here you will learn how to take advantage of these features to quickly add support for social media, and keep your players engaged outside of the game.

Chapter 7, Playing Games with Friends, looks at the networking options available in Windows 8, as well as how to add a user interface system to support this.

Chapter 8, Getting into the Store, will lift the lid on the Windows Store submission and certification process. We'll look at the important things to remember, as well as some tips and tricks to make certification painless.

Chapter 9, Monetization, investigates the different options and methods you can use to make some money from your game.

Appendix, Adding the Third Dimension, will give a light introduction to the next step in game development: 3D. You will learn the basic concepts involved so you know where to start when you want to add in another dimension to your game.

What you need for this book

You only need two pieces of software to get started with this book:

  • Windows 8

  • Visual Studio 2012 (or higher)

Visual Studio 2012 is Microsoft's development environment, and is used for all forms of Windows development, from desktop to store. There are a few editions of Visual Studio with different prices; however, a free version, named Visual Studio 2012 Express Edition, can be downloaded from:

http://www.microsoft.com/visualstudio/eng/downloads#express-win8

If you have access to higher editions of Visual Studio 2012, you can use those as well, and most functions should be in the same place.

Note

This book has been written for Visual Studio 2012 and is correct at the time of writing. Future versions of Visual Studio as well as Windows 8 may be different.

NuGet and DirectXTK

NuGet is a development package manager. If you've used package managers in POSIX environments, you'll recognise the concept, only here it's for third-party libraries. NuGet officially supports C# and C++, and will quickly become an essential tool in your Windows development toolbox.

NuGet is integrated into all versions of Visual Studio from 2012 onwards, and adding a "package" to your project is as easy as right-clicking on your project in the Solution Explorer and selecting Manage NuGet Packages. From there you can search for packages and easily install them to your project with a single click. Any dependencies will be automatically installed, and if required your project will be configured to support the new library.

MSDN

The final resource that you might want to have access to is MSDN (www.msdn.com). MSDN (Microsoft Developer Network) is the one-stop shop for documentation on all Microsoft technology. This book will contain links to MSDN pages with documentation with for further reading. If you have any questions or need to know the details on an API, make this your first stop.

Languages and other resources

Although most of the book will be developed using standard C++11, some parts will require the use of the new C++ Component Extensions (C++/CX) from Microsoft. Alongside that we will avoid going into detail about the new WinRT platform outside of the APIs you need to develop your game, so if you want to learn more about these technologies, read through the quick summary that follows, and take a look at the provided reference links for further reading.

WinRT

WinRT is the new API layer used by Windows Store applications to replace Win32. This new API provides a cleaner and easier way to work with the operating system, and also enables cross-language library development using WinRT Components.

Note

When developing a Windows Store application, you do not need to include any headers; they are all automatically included during compile tile to save you the trouble.

For a detailed look at the WinRT type system and how it works, visit:

http://blogs.microsoft.co.il/blogs/sasha/archive/2011/09/17/under-the-covers-of-winrt-using-c.aspx

Components

WinRT Components allow you to share code between the three Windows Store languages: C++, C#, and JavaScript. All public code in a component must use the ref class from C++/CX. This is because the component needs to ensure it can communicate with the other languages, which do not support pointers and other C++ specific concepts. If you want to use plain C++ within the component, you need to specify the visibility as internal.

We will look at creating a WinRT component later in the book. However, for more information, visit:

http://msdn.microsoft.com/en-us/library/windows/apps/hh441569

Threading

WinRT uses a new threading model based on the concept of asynchronous development using futures and continuations. This means that instead of creating background code in a traditional manner, you can specify code to run asynchronously, and then append the code that "continues" after the original code finishes. This is done using Tasks, which represent code that runs asynchronously, and at some point in the future may return an object (or value).

For more information on the threading and async model used in WinRT, visit:

http://msdn.microsoft.com/en-us/magazine/hh781020.aspx

C++ Component Extensions

C++ Component Extensions are a set of keywords that Microsoft has added to C++ to make it easier to work with WinRT and COM. These extensions simply enhance the language. They are required for the WinRT APIs, but can be avoided everywhere else if desired.

For more information on C++/CX, including a language reference, visit:

http://msdn.microsoft.com/en-us/library/windows/apps/hh699871

Who this book is for

This book is intended for developers who already have a good grasp of C++ development. You should know the basic programming concepts such as object-oriented programming. Knowledge of older Windows technologies such as Component Object Model (COM) will be useful but is not required.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "To compile this you'll also need to ensure that any #include statements that previously pointed to CubeRenderer.h now point to Game.h."

A block of code is set as follows:

#pragma once
#include "Direct3DBase.h"
ref class Game sealed : public Direct3DBase
{
  public:
    Game();
    virtual void Render() override;
    void Update(float totalTime, float deltaTime);
};

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: " You can find this project in the same window by navigating to New Project | Templates | Visual C++ | Windows Store".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt Publishing book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt Publishing books you have purchased from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt Publishing, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.