Archive for the ‘Game Development’ category

Console Games: Why do we have to press start?

January 5th, 2010

Interesting question came up on Twitter the other day:

“Press Start” screens?  Why can’t I just go straight to the main menu?

If you’re a gamer, especially on consoles, you’ve seen this screen more often than you’d care to.  It’s a little annoyance.  However, there is a very good reason for having this screen in place.

Imagine you’re running four controller on your Xbox, and all four of them are turned on.  Then you put in a single player game, and it comes up to that annoying “Press Start” screen.  Which controller do you use to press start with?  The answer is easy: any of them!

The “Press Start” screen is designed to determine which controller the game should poll for input.  During this screen, the game is polling all connected controllers for input.  If any of them register a “start” button push, the game makes that controller the “default” controller.  The use-case for this scenario is that the player should be able to use any connected controller to play the game, and not be forced to use controller #1.  This is considered a best practice.

The More You Know

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Richmond Code Camp 2009.1

April 3rd, 2009

Richmond Code Camp 2009.1 is Saturday, April 25th.

What is a code camp?  A code camp is an all day event for developers by developers.  The easiest way to think of a code camp is to think about a great developer conference (TechEd, DevConnections, etc) and take away the entry fee.  Almost all the speakers are locals (or within a few hours drive).  This means you’re learning straight from your peers, not some highly paid professional speaker.  All the speakers are passionate about what they do and what they present on.  A day at code camp is a day not wasted!

If you’ve never been to a code camp before, Richmond is the place to get started.  There is a great speaker line up (including me).  I will be giving my intro to WPF talk again.  There will a lot of great people to meet and hang out with.  Hope you all can make it!

Register At https://www.clicktoattend.com/invitation.aspx?code=136238 or go to http://www.richmondcodecamp.org for more information!

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Anatomy of an XNA Application

January 4th, 2009

So you have your environment set up, and you create your first XNA project.  XNA Game Studio sets up your project, and gives you a great skeleton for developing your game.  Below is the complete “Game1.cs” file you’re given.  I recommend renaming this file and class to something a bit more meaningful.

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
 
namespace LastAgent
{
    ///
    /// This is the main type for your game
    ///
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
 
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
 
        ///
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        ///
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
 
            base.Initialize();
        }
 
        ///
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        ///
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
 
            // TODO: use this.Content to load your game content here
        }
 
        ///
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        ///
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }
 
        ///
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        ///
        /// Provides a snapshot of timing values.
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
 
            // TODO: Add your update logic here
 
            base.Update(gameTime);
        }
 
        ///
        /// This is called when the game should draw itself.
        ///
        /// Provides a snapshot of timing values.
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
 
            // TODO: Add your drawing code here
 
            base.Draw(gameTime);
        }
    }
}

Let’s evaluate the various parts of this code. We’ll ignore the using statements, and get right into the meat of the class. Below is a snippet of the code. We’re given two objects, GraphicsDeviceManager and SpriteBatch. The GraphicsDeviceManager helps us determine the type of device we’re going to be outputting to. This can range from various PC graphics cards to the Zune or Xbox 360. We’ll use this class later to alter our output based on users environment. Next is the SpriteBatch. Think of this as a List<> of images you want to draw to the screen. This will be covered a little bit later in the Draw() method.

Next is the game class constructor, which sets up the GraphicsDeviceManager and sets our Content pipeline. The content pipeline is a post all in itself, so don’t worry too much about it now. The Initialize() method provides you a place to do anything you need to do before the game runs. I’m at a loss for a good example of what you would put here, but if I ever think of one, I’ll be sure to let you know.

GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
 
        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }
 
        ///
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        ///
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
 
            base.Initialize();
        }

Next are our Load and Unload content methods. The purpose of these methods are to load all the content you need to start the game. The comment says “load all your content”, but realistically you don’t want to do that. For demos, this is ok. For commercial games, you want to load as little as possible to get the user going and load as necessary. That’s what loading screens are for!

        ///
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        ///
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
 
            // TODO: use this.Content to load your game content here
        }
 
        ///
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        ///
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

The last two methods are the meat of your XNA application. The Update() method is provided to you as a way to update the state of your game. As the comment says, you use this method to update your world, check for collisions, gather input, play audio, etc. By default, you’re given code that will detect a button press from an Xbox 360 controller. Keep in mind when designing your games if you are going to accept input from just a 360 controller, keyboard, mouse, or all of the above.

Finally, there is the Draw method, and this is where all your content makes it onto the screen. The first line clears the screen. This is a very necessary step. Failing to clear the screen would lead to some wacky results. Think of the screen as a canvas. You can’t simply redraw on top of what you’ve already drawn. Calling the clear method results in a new canvas. This screen is where our friend SpriteBatch will come in handy.

        ///
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        ///
        /// Provides a snapshot of timing values.
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();
 
            // TODO: Add your update logic here
 
            base.Update(gameTime);
        }
 
        ///
        /// This is called when the game should draw itself.
        ///
        /// Provides a snapshot of timing values.
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);
 
            // TODO: Add your drawing code here
 
            base.Draw(gameTime);
        }

And that’s about it! Press Ctrl-F5 to build and run your first XNA application. You should be greeted with a pretty, Cornflower Blue screen. What you’re not seeing is your Update and Draw methods being called continuously.

What’s next for our little application? For starters, we need to get some stuff on the screen. For my game, I’m going to be using a tile based game, so my next entry will revolve around loading tile sets and drawing them to the screen.

Happy developing!

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

XNA: Setting up your development environment

January 1st, 2009

Getting started with XNA is real easy, but like with any framework, you need to have your development environment configured correctly.  All my development is done using Visual Studio 2008.  However, if you’re not able to own a license for VS2008, you can use the express versions of Visual Studio.  Here are the two most current links to download what you need.

Download Visual C# 2008 Express
http://www.microsoft.com/eXPress/download/

Download XNA Studio 3.0
http://www.microsoft.com/downloads/details.aspx?familyid=7d70d6ed-1edd-4852-9883-9a33c0ad8fee&displaylang=en

First, install Visual C# 2008 Express and then install XNA Studio 3.0.  Both installs should be pretty straight forward.  XNA Studio 3.0 might ask you if it can forward ports in the firewall for Xbox 360 development.  I would do it if you’re planning on porting your game over to Xbox 360.

In order to test the installation, open up Visual Studio.  Go to File, New, New Project.

If you have the XNA Game Studio 3.0 project type, then you have a successful installation!  As you can see, we have several options for games we can build.  The best part about XNA is that we can build a Windows game, and then use the same code to build 360 or Zune games.  For my purposes, I’ll start out by developing a Windows game.  The major reason behind this is that you need to purchase a Creators Club subscription ($99) in order to test, debug, and deploy games to the Xbox 360.  PC games are free to develop, and have no deployment issues.

Have fun with your own projects!


Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Writing Some Games

January 1st, 2009

I’m a big advocate of programming for fun.  In fact, one of the major reasons I got into software development was because I wanted to write games.  However, there is this time in your career (right around college) when you discover developing games is only for a select few people, and the real software development (and money) is found in business applications.

But business apps are no fun!  People use them because they have to, and because they help get stuff done.  Nobody comes home and wants to sit down in front of a business app to relax.  Video games are fun, and also major developmental challenges!

I’ve been watching XNA Studio since the 1.0 release.  Easy to use, powerful, and fun!  XNA is now in its 3rd release with XNA Studio 3.0.  What’s so great about XNA Studio 3.0?  Community Games!  Develop your game, and release your game on Xbox 360 for all the world to see (and pay for).  My experience with XNA has been limited: basic graphics output and control.  I’m ready to take that experience the next step forward, and build a real, functional, FUN game.  Stay tuned!  Hopefully you’ll learn something, because I know I’m going to learn tons.

Digg This
Reddit This
Stumble Now!
Buzz This
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Kick It on DotNetKicks.com
Shout it
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)