Archive for the ‘Tutorials’ category

Genetics for Games: Part 1

November 10th, 2008

One of the biggest features lacking in most small games and even larger games is some form of intelligent computer player. This article series is aimed to get you, the developer, to start thinking outside of the box when it comes to creating your game’s AI players. We will eventually be discussing what a genetic algorithm is as well as neural networks but for now, we need to start with the basics.

» Read more: Genetics for Games: Part 1

Blur and Glow

November 3rd, 2008

Having trouble with your blurring and/or glowing? Well have I got a sample for you! The Blur and Glow Sample (2218) shows you how to do both with great results. An Xbox 360 version is included as well and the code is written for the XNA 3.0 Framework.

Blur

Blur and Glow

A Closer Look at Profile Management

October 16th, 2008

Soon after making the decision to get started on Galactic Wars [3] 2.0, I ran into the problem of managing users and their profiles in a way that was not going to limit what I could do with the game. This article gives you a closer look at how I am handling users in the game. » Read more: A Closer Look at Profile Management

Building an Xml Serialization Provider

October 13th, 2008

While building Galactic Wars 3 version 2.0, I quickly ran into a serious problem with Xml serialization and more specifically deserialization. A few months ago I rolled my own solution for serializing data to and from Xml because the built in classes were bloated and yet not feature rich. A week or two ago I managed to get my class (XmlProvider) to compile for the Zune and Xbox 360. But there was still a problem…

  1. References

    The first problem (the reason for the creation of XmlProvider) was that the built-in classes could not handle references. Every object had to be serialized straight through from top to bottom. Thus if you had an object with two properties that referenced the same object (in memory), the object would be serialized twice.
  2. Inheritance

    The new problem is that with XmlProvider, deserialization was based on the information given by property attributes in your code. This is limiting because you may not know at compile time what exact type of object your property will be holding a reference to. In Galactic Wars 3 this is a problem when I am saving the profile of the user and want to save his specific ship.

So what is the solution? Start from scratch of course and solve these two problems at once! The first one is easy: provide a mechanism with which to uniquely identify any objects in memory and in Xml. We can then build a cache which we can reference from as we find objects with references. The solution to the second problem is also simple: rely on the type name in the Xml rather than the type on the property’s attributes. » Read more: Building an Xml Serialization Provider

Thrust v1.2

October 4th, 2008

Before people start reporting problems with Thrust v1.1, let me say that version 1.2 is already on its way. I have caught a few bugs in the InputManager that are demanding a quick release. I will also be including some new GUI functionality.

In the meantime, catch up on the tutorials and samples about using the Focused Games Framework.

Advanced State System: Queues and Removal

October 1st, 2008

During the last part of this little article series I mentioned how I used a queue in each state object to allow for continuous transitioning to occur. The reason for this is to allow for complex transitioning to occur. One example for this is a logo screen where it needs to fade in, stay on screen and then fade out again. Rather than relying on managing the states manually, we can add states on to a queue so they occur automatically.

» Read more: Advanced State System: Queues and Removal

Advanced State System: Concept and Base

October 1st, 2008

There comes a time when simple state management just will not cut it anymore. I found this out while building up the code base for Thrust’s GUI library. As the objects on the screen became more complex, so did their states. This article covers a new way of thinking about an object’s state, a design that has been proven in Thrust (v1.x). The goals of this state system include the following:

» Read more: Advanced State System: Concept and Base

How To: Take a Screen Capture of a Zune Game

September 16th, 2008

This one is incredibly simple.

  1. Connect Zune to computer.
  2. Deploy / Run a game.
  3. Open Device Center (in Start Menu)
  4. Right click on Zune and select Take Screen Capture

And there you go!

Restoring Application.LocalUserAppDataPath Functionality in .NET 3.5 / WPF

August 29th, 2008

With the arrival of .NET 3.5 and consequently WPF applications, Microsoft has done away with the old Application WinForms class. No longer can you call Application.LocalUserAppDataPath to get where the user’s files are stored. To restore this functionality as well as add a bit more, I have tapped into an uncommon resource: extension methods. Let’s dig a little deeper, shall we?

The first thing we need to do is be able to get the Company Name from the assembly. Inside of a blank static class, add the following functions. I have named my class ApplicationExtensions.

Fortunately the company name is kept in an attribute:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
public static string GetCompanyName(this Assembly assembly)
{
    string name = string.Empty;
 
    object[] attributes = assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true);
 
    if (attributes != null && attributes.Length > 0)
    {
        AssemblyCompanyAttribute aca = attributes[0] as AssemblyCompanyAttribute;
 
        if (aca != null)
        {
            name = aca.Company;
        }
    }
 
    return name;
}

Note my lack of any formal error handling. I will leave this up to you to handle. For now, returning an empty string will do. Next up, we need to be able to format the version number:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static string GetFormattedVersion(this Assembly assembly)
{
    string version = string.Empty;
 
    try{
        Version assemblyVersion = assembly.GetName().Version;
 
        version = string.Format("{0}.{1}.{2}.{3}",
            assemblyVersion.Major,
            assemblyVersion.Minor,
            assemblyVersion.Build,
            assemblyVersion.Revision);
    }
    catch{}
 
    return version;
}

And finally, the LocalUserDataPath:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
public static string GetLocalUserAppDataPath(this Application application)
{
    string path = string.Empty;
 
    Assembly assembly = Assembly.GetEntryAssembly();
 
    if (assembly != null)
    {
        path = Path.Combine(
            Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
            Path.Combine(
                Path.Combine(
                    assembly.GetCompanyName(),
                    assembly.GetName().Name),
                assembly.GetFormattedVersion()
                )
            );
    }
 
    return path;
}

MGS: Pong (Pages 4-6)

July 4th, 2008

In this fourth [page, second post] installment of the MGS: Pong article series, I am going to cover how to draw a background for the game. Before I start, I should tell you that there will be two more articles: one for creating the menu system and one for pulling all the classes together. Okay, let’s begin! The background class (Background.cs) is incredibly easy to create. First we need some private members to draw the background.

» Read more: MGS: Pong (Pages 4-6)