Book Image

Windows Phone 8 Game Development

By : Marcin Jamro
Book Image

Windows Phone 8 Game Development

By: Marcin Jamro

Overview of this book

<p>Currently almost everyone has a mobile phone that is used not only for calling, texting, and browsing the Internet, but also as an entertainment and social platform. Developers can create advanced 3D games with outstanding functionality that allow the player to enjoy the game directly on the mobile phone and cooperate with other players via the Internet!<br /><br />Windows Phone 8 Game Development is a practical, hands-on guide that will show you how to create a 3D game for the Windows Phone 8 platform. From setting up the environment to publishing your game, you will first learn how to implement 3D and 2D graphics with Direct3D, XAML, C++, and C#. We will then look at the game logic, steering with sensors, detecting collisions, as well as using maps, geolocation, augmented reality, social networks, and web services to share data between players. Featuring many code examples, images, and diagrams you should find the content both engaging and easy to understand.</p>
Table of Contents (22 chapters)
Windows Phone 8 Game Development
Credits
About the Author
Acknowledgments
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

How many of your friends do not have a mobile phone? Do you know anyone who does not use it? Currently, almost everyone has a mobile phone, and many people use more than one to communicate with family, friends, and colleagues from work. Such a fact is also confirmed by statistics. According to results presented by the International Telecommunication Union, about 6.8 billion mobile-cellular subscriptions are used (http://www.itu.int/ITU-D/ict/facts/material/ICTFactsFigures2013.pdf, 2013). That is almost the same as the number of people all over the world!

Nowadays, mobile phones can be used not only for calling and texting, but also for performing some tasks that a few years ago had been dedicated only to desktops and notebooks. They include browsing the Internet, accessing e-mail accounts, sharing files, or even performing time-consuming complex calculations. Apart from business applications, mobile devices can be used for entertainment, especially by integration with social networks and mobile games.

With the ever increasing possibilities of mobile devices, mobile games became more similar to their desktop or console versions and provide the user with similar gaming experience. Thus, a lot of people play games on their mobile phones, almost everywhere, for instance, while they are going to the workplace by bus or train, during breaks, as well as at home. As shown by SponsorPay (http://blog.sponsorpay.com/2013/02/infographic-mobile-gaming-on-the-rise, 2013), there are about 211 million mobile and social gamers in USA. What is even more surprising is that the majority of them play for more than an hour each day! The statistics presented by Geekaphone (http://geekaphone.com/blog/mobile-games-by-the-numbers, 2011) indicate that the mobile gaming industry is currently really important and may reach $11.4 billion by 2014.

The games installed on a small device that can be, almost all the time, in the pocket, can contain a complex logic, use three-dimensional graphics (3D), and have a rich user interface. They are very often equipped with a user-friendly steering mechanism that uses embedded sensors, such as an accelerometer or a gyroscope. The new mobile phones can also support the GPS (Global Positioning System) for geolocation, as well as Bluetooth for wireless communication. All of them make it possible to create a solution with really outstanding functionalities that allow the user to enjoy games directly on the mobile phone. With the usage of connectivity features, such as cellular data transmission or connection to WLAN (Wireless Local Area Network), applications can benefit from the content stored on the Internet and provide multiplayer modes. Therefore, the mobile phone can be used as a powerful game environment, even allowing cooperating with other players over the Internet.

You can also create your own games for various mobile platforms, including Windows Phone, iOS, Android, BlackBerry, or Symbian OS. Each of them has some specific features regarding available functionalities, supported sensors, used languages and technologies, as well as user interface concepts.

The Windows Phone 8 is a platform that is described in this book. As you will see, it allows creating various applications and games that can be then downloaded and used in many countries all over the world. Have you ever thought about developing your own mobile game? If so, let's start reading and writing its code!

What this book covers

Chapter 1, Getting Started, introduces the Windows Phone platform, and especially its newest version named Windows Phone 8, as well as managed, native, and hybrid development approaches. You will get to know how to install necessary software, as well as create the developer account, and register the phone. Then, a concept, rules, screens, and architecture of the exemplary game is described.

Chapter 2, Game User Interface, presents the XAML (Extensible Application Markup Language) language, as a way of creating the user interface. You will get to know the application lifecycle, controls, resources, styles, and data binding mechanism, as well as learn how to run and debug Windows Phone 8 applications.

Chapter 3, MVVM Design Pattern, covers implementation of the MVVM (Model-View-View Model) design pattern to improve the code quality. Such an approach is really useful while developing Windows Phone 8 applications.

Chapter 4, 3D Graphics Basics, introduces basic topics regarding three-dimensional graphics, such as vertices, transformations, and matrices. You will also get to know the automatically generated native part of the project, which uses Direct3D.

Chapter 5, 3D Game World, presents development of the simple 3D game world with Direct3D. You will learn how to create a simple model, load it, and place it in a particular location inside the game world.

Chapter 6, Steering, Sensors, and Collision Detection, explains how to obtain data from sensors, such as an accelerometer, gyroscope, and compass. You will also learn how to use these data to move objects in the game world, as well as how to detect collisions between them, and support multiple game levels.

Chapter 7, 2D User Interface in 3D Game, deals with using 2D graphics and fonts in the 3D game, with the DirectXTK library. You will get to know how to configure this tool, place textures, write text, as well as create menus with localized strings.

Chapter 8, Maps, Geolocation, and Augmented Reality, describes the maps, geolocation, and augmented reality features, which can be included in Windows Phone 8 applications and games. You will also learn how to start a navigation mechanism to particular GPS coordinates.

Chapter 9, Exchanging Data via Web Services, introduces the Windows Communication Foundation Service project as a way of exchanging data between players. You will get to know how to create a simple web service, deploy it locally, as well as allow the game to consume it.

Chapter 10, Social Networks, Feeds, Settings, and Local Rank, describes how you can easily integrate Windows Phone 8 applications and games with social networks, such as Facebook and Twitter. You will also learn how to read data from RSS feeds, implement game settings, as well as create the local rank.

Chapter 11, Improving Game Experience, covers many topics that improve the overall quality of the game, including saving and loading the current state, as well as supporting background music, sounds, video clips, and vibrations. You will also get to know how to recognize and synthesize speech.

Chapter 12, Game Publishing, explains a process of testing Windows Phone 8 applications and games, as well as their submission to the Windows Phone Store. You will learn how to test various aspects of the project, including performance and working in real-world conditions, as well as prepare the final version, and submit it to the store.

Appendix A, Useful Resources, suggests additional resources regarding the content of all chapters. It presents addresses of many websites, where you can find more information about topics presented in the book.

Appendix B, Languages and Technologies, introduces programming languages and technologies used in the exemplary game. You will get to know some basic information regarding C#, C++, XAML, Direct3D, WCF, and .NET Framework.

Windows Phone 8 Game Development book is a practical, hands-on guide that shows a step-by-step description of how to create a 3D game for the Windows Phone 8 platform. It presents the whole process of game development, from setting the environment to publishing the game. Thus, it gives a good grounding for the further game development adventure!

The game will combine the native and managed development approaches, and use a few languages and technologies, including C# and C++, as well as XAML and Direct3D. It will not be just a simple game. You will create a complex application that presents many interesting functionalities, including 2D and 3D graphics, audio and video support, maps, geolocation, augmented reality, speech recognition and synthesis, and even exchanging data via external services, and sharing data with social networks.

What you need for this book

This book presents a development of the game for the Windows Phone 8 platform. Thus, you need a set of tools that make it possible to create the game, test it, as well as run it on the emulator and the phone. Fortunately, the Windows Phone SDK 8.0, together with the Microsoft Visual Studio Express 2012 for Windows Phone as the Integrated Development Environment (IDE), should be sufficient at the beginning. A process of its installation is described in the first chapter of the book.

To use the IDE together with emulators, the computer has to run under the 64-bit Windows 8 operating system in Professional edition or greater, with the Hyper-V enabled. What is more, the processor has to support the hardware-assisted virtualization, the Second Level Address Translation (SLAT), as well as the hardware-based Data Execution Prevention (DEP). More details and other requirements are mentioned at http://msdn.microsoft.com/library/ff626524.

It is assumed that you will create the developer account, as well as register the Windows Phone 8 device. Such steps are mandatory to test the software on a real phone and to publish the solution. If you do not have the developer account, you will not be able to run the application on the phone and to submit it to the Windows Phone Store. However, you can still develop it in the IDE and run it on the emulator.

Who this book is for

This book is dedicated to beginners in the field of game development and the Windows Phone 8 platform, who want to learn how to create their first game!

No prior experience regarding 2D and 3D games development, the mobile platform, as well as XAML and Direct3D technologies, is necessary. However, some basic knowledge of object-oriented programming (OOP) (especially in case of C# and C++ languages) is required to understand parts of code described in the book.

The book content, together with the exemplary game, aims to present many interesting features of applications and games created for the Windows Phone 8 platform. However, to keep it simple, described examples may differ from "best practices", as well as may have limited security checks and functionalities. Before publishing your game, you should always test it precisely to ensure that it works correctly in normal, special, and erroneous scenarios.

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: Every call of the Geolocator_StatusChanged method causes translation of the status into a text message and assigning it to the GeolocatorStatus property.

A block of code is set as follows:

public class PlayerData
{
  public string Name { get; set; }
  public GeoCoordinate Location { get; set; }
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public class PlayerData
{
  public string Name { get; set; }
  public GeoCoordinate Location { get; set; }
}

If a part of a code block is deleted to improve legibility, remove repetition, or simplify the content, the relevant parts are replaced with (…):

<phone:PhoneApplicationPage
  x:Class="SpaceAim3D.Views.MenuPage" (...)
  FontFamily="{StaticResource PhoneFontFamilyNormal}" (...)> (...)
</phone:PhoneApplicationPage>

Any command-line input or output is written as follows:

ISETool.exe EnumerateDevices

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: Choose the Add and New Folder options from the context menu of the project in the Solution Explorer window.

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 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 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, 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.