"Marvelous Maze: A 3D Windows Phone Game"

I know Halloween, and all the mazes that seem to accompany it might be closing down, but that doesn't mean you can't still get yourself lost in one. Yet this time you don't have to leave the warmth of your house (and you get all the code to check out too!)

Marvelous Maze: A 3D Windows Phone Game

This sample code is associated with a series of articles that shows how to write a simple three-dimensional game for Windows Phone 7. The articles are titled Building 3D Games for Windows Phone [GD: This seems to be the actual/correct link, Building 3D Games for Windows Phone]. The final Marvelous Maze game lets the user explore a simple maze looking for treasures and overcoming obstacles to reach a final goal. This article explains how to create objects in three-dimensional space. It explains how to transform those objects and use projections to display them in a Windows Phone 7 game. It explains a simple 3-D example and how culling lets XNA draw closed solids more efficiently.

Building the Sample

This article is intended for .NET developers who are familiar with the C# programming language and the basics of Windows Phone 7 application development. It assumes you have the necessary hardware to run the Windows Phone 7 emulator, that you have installed Visual Studio 2010 Express for Windows Phone (or some more powerful version), and that you have installed Microsoft XNA Game Studio 4.0.

This article also assumes you have basic knowledge of displaying two-dimensional objects in Windows Phone. You can still read the articles and learn about the three-dimensional aspects of that information without knowing how to display two-dimensional objects but a few of the display features will not make as much sense. For an introduction to displaying two-dimensional objects in Windows Phone, see “How to: Create Your First XNA Framework Application for Windows Phone” at http://msdn.microsoft.com/library/ff472340.aspx.

There's a nice in-depth article on this project here;

Building 3D Games for Windows Phone - Marvelous Maze

This article explains the Marvelous Maze game that brings together many of the techniques you have learned in this series of articles. It explains how the game loads a model created with MilkShape 3D, displays different avatar points of view, tracks the avatar’s position, allows the avatar to climb stairs and fall, and lets the player collect gems and remove obstacles.

Introduction to Marvelous Maze


At this point, you have a lot of 3-D game programming tools at your disposal. You can now do the following:

  • Display basic shapes
  • Implement the game’s Update and Draw methods
  • Draw shaded or textured objects
  • Draw two-dimensional objects in front of or behind a three-dimensional scene
  • Respond to the player’s screen taps
  • Load models created in other tools such as MilkShape 3D and Blender
  • Detect collisions to know when two objects touch
  • Simulate ballistic
  • Play simple sound effects and songs

The Marvelous Maze example program combines these techniques to build a simple maze search game. This article briefly describes these techniques and how the game uses them. It also explains a couple other features of the game and how they are implemented.

Unfortunately, there is not enough space to display all (or even the majority) of the code and walk through it a line at a time. The sections that follow describe the key pieces of code and new techniques that have not been covered in the previous articles. Download the example to see the complete source code.

...

Lets see it run...

SNAGHTML85e111bSNAGHTML8605a0d

SNAGHTML97a7984

Here's a snap of the solution;

image

And a code snip where all the resources are loaded, which kind of provide a nice snapshot of the project;

protected override void LoadContent()
{
    device = graphics.GraphicsDevice;

    // Create a new SpriteBatch for 2D drawing.
    spriteBatch = new SpriteBatch(GraphicsDevice);
    noteFont = Content.Load<SpriteFont>("NoteFont");
    wheelTexture = Content.Load<Texture2D>("ShipsWheel");
    mazeTextures = Content.Load<Texture2D>("MazeTextures");
    gemTexture = Content.Load<Texture2D>("Gem");

    // Load sounds.
    collisionSound = Content.Load<SoundEffect>("Collision");
    prizeSound = Content.Load<SoundEffect>("Prize");
    tadaSound = Content.Load<SoundEffect>("Tada");
    noSoundUntil = DateTime.Now;

    // Set texture sampling state.
    GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp;

    // Load the maze model.
    mazeModel = Content.Load<Model>("Maze");

    // Create objects.

    // Make gems.
    MakeGem(redIndex, 30, 40, -31, Color.Red, "Red Gem");
    MakeGem(greenIndex, 15, 48, -95, Color.Green, "Green Gem");
    MakeGem(blueIndex, -15, 48, -95, Color.Blue, "Blue Gem");

    // For debugging:
    //prizes[redIndex].IsFound = true;
    //prizes[greenIndex].IsFound = true;
    //prizes[blueIndex].IsFound = true;

    // Make corresponding barriers.
    MakeBarrier(redIndex, 0, 29, 38, 80, -122, -120,
        0.26f, 0.49f, 0.51f, 0.74f, "You must have the red gem to pass.");
    MakeBarrier(greenIndex, -29, 0, 38, 80, -122, -120,
        0.51f, 0.74f, 0.51f, 0.74f, "You must have the green gem to pass.");
    MakeBarrier(blueIndex, -20, 20, 0, 38, -82, -80,
        0.00f, 0.24f, 0.51f, 0.74f, "You must have the blue gem to pass.");

    // Add obstacles.
    MakeObstacles();

    // Add the globe.
    Globe globe = new Globe(GraphicsDevice, mazeTextures, new Vector3(0, 13.5f, -161));
    drawables.Add(globe);


    // Make the signs.
    MakeSign();

    // Create the player's avatar.
    avatar = new DrawableSkelton(GraphicsDevice, true,
        1, 8, 8, 1.5f,  // Head and neck.
        4.25f, 0.25f,   // Spine.
        6, 0.25f, 6,    // Eyes.
        0.5f, 0.13f, 6, // Nose.
        0.255f, 6, 8,   // Joints.
        2.5f, 2,        // Shoulders and hips.
        1.5f, 1.5f,     // Arms.
        2, 2            // Legs.
    );
    avatar.Prepare();
    drawables.Add(avatar);

    // Set up the camera and projection matrices.
    SetUpCamera();
    SetProjection();

    // Position the 2D textures.
    PositionTextures();

    // Start with an identity world transformation.
    worldMatrix = Matrix.Identity;
}

Did you catch that cool WP7 Emulator skin I'm using?

Welcome Nokia Lumia WP7 Emulator Skin

...And yes, our team is excited about the new addition to the Windows Phone family and all the new development opportunities opening up. So excited actually, that we created a Nokia Lumia skin for our WP7 emulator just for fun. And then we thought that you might have fun skinning your emulator in the smoking hot black or white Nokia Lumia skin too.

Download for free our Nokia Lumia WP7 Emulator Skin and dress up your WP7 emulator.

[GD: Found via: MicrosoftFeed, Download Nokia Lumia WP7 Emulator Skin and Scott Lovegrove]

In the end if you're thinking about building a 3D type application for Windows Phone 7, you should check out this fairly simple, yet complex and cool example. And make sure you check out both resources, the code and the accompanying article...

Follow the discussion

  • Oops, something didn't work.

    Getting subscription
    Subscribe to this conversation
    Unsubscribing
    Subscribing

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.