Book Image

3D Game Development with Microsoft Silverlight 3: Beginner's Guide

By : Gaston C. Hillar
Book Image

3D Game Development with Microsoft Silverlight 3: Beginner's Guide

By: Gaston C. Hillar

Overview of this book

Microsoft Silverlight is a programmable web browser plug-in that enables the animation, vector graphics, and audio-video playback features that characterize Rich Internet Applications. Silverlight is a great (and growing) RIA platform and games are the next level to exploit in it. But it doesn't offer 3D capabilities out of the box and integrating a 3D engine can involve lot of complex mathematics and matrix algebra. This book will help C# developers to get their fingers on the pulse of 3D in Silverlight. This book uses Balder, an open source 3D engine offering 3D capabilities for Silverlight 3. It leaves out boring matrix algebra and complex 3D mathematics. By the end of the book you will have explored the entire engine, and will be able to design and program your own 3D games with ease! The book begins by introducing you to the fundamental concepts of 2D games and then drives you into the 3D world, using easy-to-follow, step-by-step examples. The book employs amazing graphics and impressive performance, and increasingly adds more features to a 3D game giving you a rich interactive experience. By following the practical examples in this book, you will learn the important concepts, from the creation of the initial models, up to the addition of physics and artificial intelligence. The book helps you to provide realistic behaviors for 3D characters by enveloping models with different textures, using lights to create effects, animating multiple 3D characters using a physics engine (Farseer Physics Engine), and simulating real-life physics. Videos, music, and sounds associated with specific events offer the final touches to the 3D game development learning experience.
Table of Contents (21 chapters)
3D Game Development with Microsoft Silverlight 3
Credits
About the Author
Acknowledgement
About the Reviewer
Preface
Pop quiz—Answers

Time for action—creating the raster digital content


This prehistoric game used a 256X192 pixels screen (49,152 pixels). We are going to prepare raster digital assets for the game optimized for a 1680X1050 pixels screen (1,764,000 pixels). The game should look nice when compared to the older version.

The old version used 8X8 pixels raster digital assets. In this new version, we can use 50X50 pixels raster digital assets.

Note

The creation of raster digital assets for a 2D game is very complex and requires professional skills. Digital artists and graphic designers are very important members of a professional game development team. They provide great quality digital assets to the programming team.

As you do not have access to professional digital artists yet, you must download some freeware icons and then prepare them to be a part of a game demonstration. Luckily, you will find some nice space and zoom-eyed creatures in PNG (Portable Network Graphics) format that are free to download from Turbomilk (a professional visual interface design company, http://turbomilk.com). They are ideal to use in the game.

Note

PNG is an open, extensible image format with lossless compression. Silverlight 3 works great with PNG images. I recommend not using the JPEG (Joint Photographic Experts Group) format for foreground digital assets or iconic graphics because it uses a lossy compression method that removes some information from the image.

First, we are going to download, manipulate, resize, and finally save the new versions of the new raster digital content for the game:

  1. 1. Download the PNG images for the green, blue, and red aliens, the tents, and the ship. You can take some nice images from http://turbomilk.com/downloads/.

  2. 2. Save all the original PNG images in a new folder (C:\Silverlight3D\Invaders\GAME_PNGS), as shown in the following picture:

  3. 3. Open the images for the aliens, ship, and tents using an image-manipulation tool. You can use a free and open source software such as GIMP (the GNU Image Manipulation Program) that is available at http://www.gimp.org, or a commercial software such as Adobe Photoshop available at http://www.adobe.com, or free software such as Picasa available at http://picasa.google.com.

  4. 4. Remove the shadows from the images because we are not going to use them as icons. You can select the shadows and delete them using the magic wand tool (fuzzy select tool). It requires high precision in the selection to avoid deleting the original drawing. Shadows have to be removed because we want to use them as raster content for the game, as shown in the following picture:

  5. 5. Remove the transparent pixels from the images (that is, erase the selection).

  6. 6. Resize the images for the aliens and the ship to 50X50 pixels square, while keeping proportions. Save them in a PNG format using the following names:

    • ALIEN_01_01.png—the blue alien, the octopus

    • ALIEN_02_01.png—the red alien, the gothic cherry

    • ALIEN_03_01.png—the green alien, the eye

    • SHIP_01_01.png—the ship

  7. 7. Resize the image for the tents to 100X100 pixels square, while keeping proportions. Save it in a PNG format using the name TENT_01_01.png.

  8. 8. Now, copy the newly manipulated and resized images in a new folder (C:\Silverlight3D\Invaders\GAME_PNGS_RESIZED), as shown in the following picture:

What just happened?

We created raster digital content for the game optimized for a 1680X1050 pixels screen. We downloaded some images, and manipulated them to remove the shadows and prepare them for the game's main scene. We used a naming convention for the images as we want to keep everything well organized for the game.

The game will look nice using these modern raster digital art assets.

Digital Content Creation tools

The Digital Content Creation tools (DCC) are very important partners for game designers and developers. They allow digital artists and graphic designers to concentrate on the creation of different kinds of digital art assets, which are then used in the applications.

Note

We can also use everything we are learning in developing the applications that have intensive graphical resources. However, we will call them games in the rest of the book.

It is very easy to understand their purpose using an example. If you want to show a sky with stars as an application's background, the easiest way to do it is by loading a bitmap (PNG, BMP, JPG, and so on) using the procedures or controls provided by the programming language.

A digital artist will create and manipulate the sky bitmap using an image manipulation tool such as GIMP, Photoshop, or Picasa.

Developing games requires the usage of a great number of resources; it is not just programming tasks. We are going to use many popular DCC tools during our journey to create Silverlight 3D games. As many of these tools are very expensive, we will use some open source and free alternatives to carry out the most important tasks.

A good practice before beginning 2D and 3D game development is to research the tools used to create the 2D and 3D digital content. This way, we will have a better idea of how to create the different scenes and the most common techniques. Later, we will learn the programming techniques used to give life to these graphics-related operations. We will be able to provide great real-time interaction to all these digital content assets, as shown in the following diagram:

Basic elements of a 2D and/or 3D real-time game

A modern 2D and/or 3D real-time game uses the basic elements shown in the previous diagram. Let's go through them in the following list:

  • 2D images: These can be raster bitmaps as used in our previous example, or vector graphics—also known as vector-based illustrations. In some cases, they are useful as a background made of a starry sky, or a cloudy sky. In other cases, they are used as textures to envelope different 3D objects. For example, a 2D brick's image is used as a texture to envelope a 3D object representing a wall.

  • 3D models: These contain information about the representations of primitive elements (point, lines, triangles, and polygons) to create great meshes, similar to a wire mesh that describes a 3D model. Their different parts can be enveloped by textures. Then everything renders in a representation in the 2D space shown by the players' screens.

  • Effects definitions: These can be applied to 3D models to offer more realism in the production of many scenes. To simplify the development process, there are many specific programming languages used to define the behavior of effects.

  • Maps: It is easier to create real-time digital content using different kinds of maps and diverse proprietary formats. Maps can specify the location of the different kinds of houses and trees in a game that involves driving a car in a city. It is possible to create many levels based on the same logic and behavior programmed for a game, but by using many different maps.

Many specialized DCC tools help in creating the basic elements explained in the aforementioned list. For example, using GIMP you can see the alpha channel for the ship's PNG image, as shown in the following picture:

Programming responsibilities

We do not have to write lines of code dedicated to creating an image. Instead, modern game programming focuses on the following tasks:

  • Loading: We must load 2D images, 3D models, textures, effects definitions, and maps using different kinds of content loaders, parsers, import techniques, and translators. They are going to help us in transforming the original file formats to the ones supported by the programming language and the framework used to develop the game.

  • Drawing: A game's main goal is to show real-time graphics content in a screen. One of the main problems is that 3D scenes have to be shown in a screen capable of showing just two of these three dimensions.

  • Logic and control: While the content is being loaded and shown, it is necessary to apply some AI (Artificial Intelligence) to logic operations, and to provide feedback according to the controls offered to the user for certain game actors and aspects. In order to achieve this goal, it is necessary to develop accurate time-management techniques coordinated with the information obtained from the hardware applied to control the game—the keyboard, mouse, racing wheel, gamepad, or the Wiimote (Wii Remote), among others. All of these tasks must be done while managing many heterogeneous pieces and showing a very complex audiovisual production. Thus, we must take into account everything related to the execution speed and issues of performance.

Programming games requires more knowledge about the underlying hardware on which the game will be run. We must establish performance baselines and minimum requisites to achieve a desirable performance for the game. Besides, we must specify the recommended input devices to take full advantage of the game. These tasks could seem pretty trivial, but they are very important because some games are very complex and demand many difficult optimizations to be able to run on the mainstream hardware available.

This is a simple summary of a game's programming responsibilities. We will work through them all throughout this book.