About the Windows Store game sample
Before you get started, be familiar with the game and the code discussed in these tutorials. While there's quite a bit of code, we won't discuss all of it, especially the code that's part of a Visual Studio project template or common to other Direct3D samples. This topic helps you determine the difference between what's important when reviewing this code, and what's important when designing your own game.
This set of topics covers the Windows Store Direct3D shooting game sample, which demonstrates a simple 3D target shooting game. Playing the game is simple : aim the cross hairs at the targets on the screen, and shoot them before time runs out! There are six levels, with each level adding obstacles such as moving pillars. Your goal? Beat all six levels and get a high score! If you complete a level quickly, the remaining time is added to your allowed time for the next level.
There are three methods of control:
- Use the W, S, A, and D keys to move, and use the mouse to aim the cross hairs. Press the left mouse button to shoot at the targets. Press P (or snap the game) to pause.
- On a touch screen, use the lower-left rectangle of the screen to move the cross hairs by dragging your finger up, down, left, or right. Touch the lower-right rectangle to fire. Touch and drag the rest of the screen to aim the cross hairs. Touch the edge of the screen to pause.
- With a game controller, use the left analog stick to move and the right analog stick to aim the cross hairs. Press the right trigger button fire. Press the Start button to pause.
Have you had a chance to take a look at the code in the Windows Store Direct3D shooting game sample? Inside the package, you find a number of code files that were created specifically for the sample, which implement the game itself . Let's review them!
When you open the Simple3DGameDX.sln file with Microsoft Visual Studio 2012, the content of the Solution Explorer pane should like this:
The top level directory contains the code source files that define the game's overall structure and implementation.
- DirectXApp.h and DirectXApp.cpp. The files define the core Windows Store app components of the sample game, including event handling, suspend/resume, snap view, graphics adapter info, graphics overlays, user interface elements, and the DirectX swap chain. It also implements the state machine for basic user behaviors.
- Simple3DGame.h and Simple3DGame.cpp. These files define the structure of the game itself, including the state machines used for the core game loop and overlay display. It also provides the code that ties the graphics rendering to game state. Much of this walkthrough refers to the code in this pair of files.
This folder contains the code for the audio-related components of the game.
|Audio.cpp/.h||Defines the audio object used to mix and play music.|
|MediaReader.cpp/.h||Provides methods for reading the PCM audio streams.|
|SoundEffect.cpp/.h||Provides methods for the mixing and playback of sound effects.|
This folder contains the code that defines what a game level is and specifies the configuration for each of the game's six levels.
|Level.cpp/.h||Defines an abstract class containing information about game levels.|
|Level[1-6].cpp/.h||Defines the attributes and objectives for each game's six levels. This includes the time limit for completing the level, as well as the animation, timing, position, and total number of the targets and obstacles in the level.|
This folder contains the code that defines the objects used in the game world, such as the player camera and the animated targets and obstacles.
|Animate.cpp/.h||Provides the calculations for the animation of the moving targets and pillar obstacles in the game.|
|Camera.cpp/.h||Provides an implementation of a 3-D camera view of the scene, and the 2-D projection of it.|
|Cylinder.cpp/.h||Defines a specific implementation of the GameObject class for cylinders. This includes a method that determines the point of intersection between a sphere (the ammo) and cylinder.|
|Face.cpp/.h||Defines a specific implementation of the GameObject class for a rectangular flat surface (the "face"). This includes a method for determining the point of intersection between a sphere (ammo) and the surface. The class is used for targets.|
|GameConstants.h||Defines a number of common constants used throughout the game.|
|GameObject.cpp/.h||Defines the behaviors of the in-game object graphic primitives, including placement, movement, and collisions.|
|Sphere.cpp/.h||Defines a specific implementation of the GameObject class for spheres. This includes a method for determining the point of intersection between two spheres. The class is used to represent the ammunition in the game.|
This folder contains the specific controller implementation code.
|MoveLookController.cpp/.h||Provides the implementation of a move-look controller for mouse/keyboard controls, touch screen controls, and the Xbox 360 controller controls.|
This folder contains the code definitions of the mesh geometry used by the game world and objects.
|CylinderMesh.cpp/.h||Defines a specific implementation of the MeshObject class used to create the mesh for cylinder game objects.|
|FaceMesh.cpp/.h||Defines a specific implementation of the MeshObject class used to create the mesh for rectangular target game objects.|
|MeshObject.cpp/.h||Defines the general class for graphics mesh primitives. These primitives are defined by a D3D11 vertex buffer and index buffer, as well as the virtual method to render these primitives.|
|SphereMesh.cpp/.h||Defines a specific implementation of the MeshObject class used to create the mesh for spherical ammo game objects.|
|WorldMesh.cpp/.h||Defines a specific implementation of the MeshObject class used to create the meshes for the world environment.|
This folder contains the code for the graphics components of the game.
|ConstantBuffers.h||Defines the D3D 11 Constant buffers used to control the graphics rendering.|
|DirectXBase.cpp/.h||Provides a basic renderer that includes the Direct3D device and swap chain, and the Direct2D factory and device. It includes handling stereo and pre-rotation of swap chains for better rendering performance. This class is important!|
|GameHud.cpp/.h||Defines the Heads Up display for current scoring.|
|GameInfoOverlay.cpp/.h||Defines the 2D overlay that contains the heads-up display elements for the level instructions and score info.|
|GameRenderer.cpp/.h||Defines a specific implementation of DirectXBase tailored to the specific needs of this game, including methods for asynchronous creation of game and level device-specific resources.|
|Material.cpp/.h||Defines the material properties of objects. This includes the object color, specular highlight color, textures and shaders used to render the object.|
|StereoProjection.cpp/.h||Provides helper code that creates the projection matrices for the 3-D stereoscopic projection. These methods are called in Camera.cpp.|
|TargetTexture.cpp/.h||Defines the methods used to create the concentric circle bitmaps for the targets.|
This folder includes the texture DDS files, bitmap image files, and audio WAV files used by the game sample.
This folder contains the high-level shader language (HLSL) files for the game, and the specification for the constant buffers used by the HLSL methods.
|ConstantBuffers.hlsli||Defines the Direct3D 11 constant buffers used by HLSL to control graphics rendering. This file is paired with ConstantBuffers.h.|
|PixelShader.hlsl||Contains the HLSL code for the common pixel shader used for most game object rendering. It includes per pixel lighting for specular highlights.|
|PixelShaderFlat.hlsl||Contains the HLSL code for the pixel shader used for the game world objects. It does much simpler shading and doesn't include any specular light effects.|
|VertexShader.hlsl||Contains the HLSL code for the common vertex shader used for most game object rendering. It's paired with PixelShader.hlsl|
|VertexShaderFlat.hlsl||Contains the HLSL code for the vertex shader used for the game world objects. It does much simpler shading and lighting. It's paired with PixelShaderFlat.hlsl|
This folder contains various support classes and methods for the game.
|BasicLoader.cpp/.h||Provides methods for loading assets, such as textures, from disk.|
|BasicMath.h||Defines some simple types that represent vectors and matrices, and the mathematical operations that can be performed on them. This sample uses DirectXMath instead of these math functions.|
|BasicReaderWriter.cpp/.h||Provides methods for reading and writing data synchronously and asynchronously.|
|BasicShapes.h||Defines a set of basic 3-D graphic primitives, such as cubes and spheres.|
|DDSTextureLoader.cpp/.h||Provides a method for loading a DDS texture and creating a Direct3D 11 runtime resource for it.|
|DirectXSample.h||Defines an exception handling method used in the Windows Store DirectX samples.|
|GameTimer.cpp/.h||Defines a high-resolution game clock object.|
|PersistentState.cpp/.h||Provides a set of methods for saving and loading various scalar and complex type values to and from a configured storage location.|
The specific precompiled Windows libraries and headers used by this sample (and potentially by your own Windows Store DirectX game) are listed in the pch.h file, which looks like this:
#include <wrl.h> #include <d3d11_1.h> #include <d2d1_1.h> #include <d2d1effects.h> #include <dwrite_1.h> #include <wincodec.h> #include <DirectXMath.h> #include <xaudio2.h> #include <xaudio2fx.h> #include <mmreg.h> #include <mfidl.h> #include <mfapi.h> #include <mfreadwrite.h> #include <XInput.h> #include <stdio.h> #include <vector> #include <memory> #include <ppltasks.h> #include <agile.h>
These headers define the classes and methods in the Windows Runtime (wrl.h), Direct3D 11.1 (d3d11_1.h), Direct2D (d2d1_1.h, d2d1effects.h), DirectWrite (dwrite_1.h), DirectXMath, XAudio2, XInput, Parallel Patterns Library (ppltasks.h, agile.h), and various MFC header files.
Now that you're familiar with the contents of the sample, read Setting up the game project to discover how you might set up a similar project, or go directly to reviewing the game sample's structure by reading Defining the game's Windows Store app framework.