2D First - XNA Tetris Xbox 360 Game

In an attempt to dive right into 3d XNA I had to take a step back.  I decided to write a 2d game just to get familiar with the framework.  I made tetris in about 2 days.  Its not complete yet but its a good start.  I have implemented this game before in C++ years ago.

Heres a tasty screen shot and I'll post the game when I finish it.   The board and pieces are blended with the BG image which is loaded randomly at startup.

 

XNA Texture Utility - Paint.NET

Obviously there are hard-core photoshop people out there.  But you are looking for something more light-weight that is very capable of creating textures and graphics for 2D and 3D games.  The actual program was started by some dude's final project for school....nice.

If you like this program definately contribute

 

Get Paint.NET!

Tetris 360 - My XNA 1.0 Creation

I'm not going to go into a lot of detail in this post but I have completed my remake of tetris in XNA in 3 days.  It still has a few bugs (mostly with shape rotation), but the real purpose was more to play with XNA rather than make a perfect game.  I'll likely improve on some of the rendering techniques and experiment with additional features.  If you have a unique feature you'd like to see, drop me a line.  I will post a reply to existing and additional comments in the near future.

Download XNA Tetris 360 beta 1.0

 

Merry Christmas!

Loading random, dynamic content in XNA

Here are two brief samples of loading random content in XNA

1) Loading a random texture
2) Loading a random object

Random Texture

Using the XNA content pipeline in GSE 1.0, it is simple to generate random textures.  In my first game, I only require one background image per game.  The following code sample randomly selects the "background0" or "background1" asset names with the same path.

// Load random background texture
Random random = new Random();
int randomNum = random.Next(1,3);
string randomBackgroundAssetName = string.Concat("Content\\background", randomNum.ToString());
Texture2D background = _content.Load<Texture2D>(randomBackgroundAssetName) as Texture2D;

This sample demonstrates how to randomly select a texture within a set of pre-loaded textures, again, using the content pipeline.  Using an array of Texture2D values we can store all the textures and access them randomly.

// Load all textures
int numberOfBackgrounds = 2;
Texture2D[] textures = new Texture2D[numberOfBackgrounds];
for (int i = 0; i < numberOfBackgrounds; i++)
{
    string randomBackgroundAssetName = string.Concat("Content\\background", i);
    textures[i] = _content.Load<Texture2D>(randomBackgroundAssetName) as Texture2D;
}

// Randomly select texture
Random random = new Random();
int randomNum = random.Next(1, 3);
Texture2D randomTexture = textures[randomNum];

Creating random objects

In my Tetris sample game I have a method called GetRandomShape().  It returns a randomized Shape base object.  Formally this would fall into a Factory pattern but you get the idea.

/// <summary>
///
This method returns a random shape
///
</summary>
/// <param name="position">Position of the new shape
</param>
/// <returns>A base shape object
</returns>
private Shape GetRandomShape(Vector2 position)
{
   Shape myShape = null;
   Random random = new Random();
   int randomNum = random.Next(0, _numberOfShapes);
   switch (System.Enum.GetName(typeof(Shapes), randomNum))
   {
         case "Bar":
            myShape = new Bar(position);
            break;
         case "Square":
            myShape = new Square(position);
            break;
         case "ThreeOne":
            myShape = new ThreeOne(position);
            break;
         case "OneThree":
            myShape = new OneThree(position);
            break;
         case "TwoUpTwoDown":
            myShape = new TwoUpTwoDown(position);
            break;
        case "TwoDownTwoUp":
            myShape = new TwoDownTwoUp(position);
            break;
        case "OneTwoOne":
            myShape = new OneTwoOne(position);
            break;
    }
    return myShape;
}

Hopefully this resource will help you add dynamic content to your XNA game.

 

Beginning XNA

So the new XNA framework 1.0 has been released.  You've heard all about it from your friends who clearly play too many video games.  Its easy to get started, especially if your C# 2.0 skills are strong.  The concept is basically a framework to support the creation of XBox 360 and PC (Windows) games. 

XBox 360 games can be deployed to your console with the correct licensing.  The same framework can be used to debug the games in a Windows environment.  Input data is facilitated by the USB-wired controller, which was plug & play with Vista, or the keyboard/mouse.

Here are a few things I'll cover to get you started

  1. Preparation
  2. Links to download
  3. XNA is not supported under Windows Vista, but there is a work around.
  4. Documentation and tutorials get you fired up with a simple model render.
  5. Distribution

Preparation

When getting started I found it useful to understand some math and configuration concepts through experience with OpenGL.  However, the basic nature of the XNA framework is pretty easy to pick up and I think anyone who is motivated could do it.   So I think Microsoft really hit a homerun there.

Links

MSDN Forums - http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=882&SiteID=1

XNA GSE Download - http://www.microsoft.com/downloads/details.aspx?FamilyID=a73a7e71-ff41-432d-a0eb-043e904a1905&DisplayLang=en

Learn XNA - http://learnxna.com/

XNA TUTORIAL VIDEOS - http://msdn.microsoft.com/directx/xna/videos/

XNA TEAM BLOG -
http://blogs.msdn.com/xna/
 

 

Vista, Vista

Through links I found at the MSDN XNA GSE forum and the Connect site, I obtained Visual C# Express SP1 Beta:

http://www.microsoft.com/downloads/results.aspx?pocId=&freetext=Visual%20Studio%202005%20Service%20Pack%201&DisplayLang=en

Download and install Visual C# Express and SP1 Beta (Final SP1 has an expected release in December).

Open Visual C# Express and register it.

Documentation & Tutorials

Check the links section and follow the 3 video sequence to get started.

Distribution

One major con of the existing XNA framework is to distribute an Xbox 360 game you need to send off your source code to your buddy, have him compile and deploy to run the game.  Kind of ridiculous, but many people are expecting that to change in the near future.

In the mean time...there is plenty of things to try out.  Once I completed the tutorials I began working with the controller to get the space ship to fly around better.   I will be releasing some code on this blog as I make different games.