Archive for category Xbox

Learning the (XNA) basics – part 2

XNA codeContinuing from Learning the (XNA) basics lets take a quick look at what all that XNA framework code actually does.

We write XNA code in C# (C sharp) so you should at least be familiar with the basics of C# before starting in on XNA (there are a lot of introductory tutorials for both C# and XNA on the internet).

Taking it section by section;

Using statements reference other namespaces which are typically linked libraries or assemblies within .NET. They basically enable us to use methods from within those namespaces without having to specify the namespace every time, so instead of typing Microsoft.Xna.Framework.Graphics.Effect we can just type Effect and the compiler will select the correct namespace for us because we have a using reference to Microsoft.Xna.Framework.Graphics.

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;

Here XNA has specified a namespace for our game, WindowsGame1. You may end up using multiple namespaces within your game to help seperate out functional components and to provide another level of encapsulation. You should see that code will only be able to access code within another namespace by fully qualifying the namespace or via the using method.

namespace WindowsGame1

This is the class definition and shows that our Game1 class inherits from the Microsoft.Xna.Framework.Game class, which provides all of the base functionality for our game. Within the definition XNA has provided member variables for the GraphicsDeviceManager which is our graphics device and a SpriteBatch which may be used for drawing sprites.

/// <summary>
/// This is the main type for your game
/// </summary>
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

The class constructor initialises the GraphicsDeviceManager member, graphics, and defines a root directory for the game to find it’s Content (content is also known as the game assets, or the models, textures, sounds, etc that your game will use).

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}

The Initialize method can be used to perform other initialisation actions. It is also important to call base.Initialize(); as this causes the correct creation of any other GameComponents.

/// <summary>
/// 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.
/// </summary>
protected override void Initialize()
{
// TODO: Add your initialization logic here

base.Initialize();
}

LoadContent can be used to, load your content 🙂 You will see that XNA has initialised the SpriteBatch member, spriteBatch, here.

/// <summary>
/// LoadContent will be called once per game and is the place to load
/// all of your content.
/// </summary>
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, unsurprisingly, unloads your content 🙂

/// <summary>
/// UnloadContent will be called once per game and is the place to unload
/// all content.
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
}

This is a key method, Update. Upate and Draw are (usually) called in sequence over and over providing your game loop. The Update step is usually where you would gather user input, and update your game logic. You will see that Update also takes a parameter, gameTime, which allows us to perform time-related calculations. XNA has provided minimal code here, it checks to see if a controller button has been pressed and if so exits the game loop.

Like, Initialize, the call to base.Update(); causes any other GameComponents to update as well.

/// <summary>
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input, and playing audio.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
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);
}

The other key method within your game loop, Draw. Draw, like Update, takes a gameTime parameter. Here XNA clears the window to a pretty blue, and calls base.Draw(); so that any other DrawableGameComponents can also draw themselves.

/// <summary>
/// This is called when the game should draw itself.
/// </summary>
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

// TODO: Add your drawing code here

base.Draw(gameTime);
}

As you can see XNA has provided a simple framework for a game / game loop. There is a lot more going on under the hood, but we don’t actually need to concern ourselves with how XNA does what it does.

Now its time to think about how to use that framework to start building your game.

, , , , ,

Leave a comment

Learning the (XNA) basics

I’ve been messing about with XNA3 for about a year now, and recently decided to move up to XNA4. Microsoft have obviously decided to leverage the XNA user base to provide content for the Windows Phone 7 platform, so you’d be forgiven for thinking that XNA4 is only for phone develooment as much of the tools, educational resources, etc are all re-branded and aimed squarely at Windows Phone 7. XNA still supports the PC, Xbox 360 and Zune as target platforms alongside the Windows Phone.

XNA default screenGetting started with XNA is incredibly simple. XNA4 provides us with quite a solid framework to build our game / engine upon. Much of the hard work involved in getting DirectX up and running is handled for us.

For instance, working with C++ and DirectX, the first step is usually to create a windowed application and set up a game loop rendering a blank scene. You would have to, amongst other things;

  • create a window for your application
  • provide a windows message handler
  • intialise Direct3D
  • create the Direct3D Device
  • start the message pump / game loop
  • render to the window

XNA does all of that and a bit more for us without us having to enter a single line of code. The default XNA4 template will generate a window like the image shown and provide us with the framework code listed below to give us the basics that we need to get started.

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 WindowsGame1
{
    /// <summary>
    /// This is the main type for your game
    /// </summary>
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        /// <summary>
        /// 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.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            base.Initialize();
        }

        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        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
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        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);
        }

        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            // TODO: Add your drawing code here

            base.Draw(gameTime);
        }
    }
}

Within XNA there is an underlying Game class that provides all of the basic functionality to produce the window, graphics device, the message pump / game loop, etc. All of the initial hard work that C++ programmers have to handle is done for us, and this design is mirrored throughout XNA Game Studio.

The framework above, the Game1 class, overrides the underlying Game class and provides us with the ability to write our own code over the top. We add code to the Initialize, LoadContent, Update, and Draw methods and add our own components, methods, content, etc. to build up our own game.

Related: Microsoft’s App Hub – Getting Started

, , , , ,

Leave a comment

The Saboteur (Xbox 360)

I picked up The Saboteur back in June on an impulse purchase, it was on special and it looked like it could be fun. Then I checked a few reviews and saw that the developer had gone into liquidation, there had been major problems with multi-core systems and ATI graphics cards, and reviews criticised the ‘platform mechanics’ and animation.

So, with some trepidation I booted up the Xbox and got ready to liberate a Paris under Nazi occupation during the Second World War (1940).

The Saboteur is a third-person sneaker/climber/shooter in an open world environment which gives the feel of a large area well populated with Parisien civilians, the French Resistance and the ever watchful Nazi/SS occupiers. You play a devil-may-care Irishman, Sean Devlin, working as a racing car mechanic for a French father-son team, who get on the wrong side of a Nazi colonel precipitating the key motivator for the storyline, Sean’s revenge on the Nazis.

After the introduction to the game, driving, brawling, travelling around, etc, you enter Paris where the rooftops become your avenues, affording a quick and mostly invisible path to perform your acts of sabotage on the Nazi infrastructure. Sean can climb on pretty much any building, reaching some wonderful vantage points, even the top of the Eiffel Tower itself! Sean can also disguise himself to sneak into close proximity with his targets, and when spotted a very GTA-style chase circle pops up that you have to escape from (by clearing the area, or using a hiding spot).  Perks are granted for particular acts which unlock various abilities or weapons.

Proceeding through the interesting story missions unlocks new areas (you can travel anywhere on the map before unlocking them, unlocking them gives you travel papers to enter without sneaking/running, and opens up Resistance bases to re-arm/store vehicles), and new weapons/vehicles.

One of the most interesting mechanics of the game is that the visuals start in black-and-white signifying the Nazi occupation, and as you complete story and side missions occupied areas are ‘inspired’ and become filled in with colour. You will also notice the car radios (which have a great soundtrack) play a more muted tone in occupeid areas, and the weather is usually dark/rainy, all helping provide the atmosphere, the feeling of oppression and subsequent release as you inspire more areas.

I found this game great fun, I spent a lot of time just tooling around the rooves of Paris to see how far I could climb or knocking off random Nazi’s or hitting free-play targets. With 50 story/side missions and over 1,300 ‘free-play’ targets there is a lot to do. Well worth the price that you can pick it up for now although probably better on the consoles than PC.

9 out of 10!

, , ,

Leave a comment

I’m late to the party (XNA Game Studio)

Visual Basic 6 and DirectX 8 are looking very long in the tooth now, pretty much dead, but where to go?

I dabbled briefly with an early version of XNA (Game Studio 2.0 I seem to recall) when I was looking at alternatives for game programming languages/libraries, but wasn’t particularly impressed with it. Yes, it allowed rapid development, and most of the basics were done for you, but it seemed slow, and required doing things in a particular way, and seemed more aimed at the casual 2D game market on the Xbox 360 (although it supports Windows development as well).

With the advent of XNA 4 (due later this year) I thought I’d have another look at it and so installed the latest iteration XNA Game Studio 3.1.

Install Microsoft Visual C# 2008 Express Edition

Install Microsoft XNA Game Studio 3.1

Visit the XNA Creators Club Online, in particular their Getting Started section (based upon XNA Game Studio 3.0)

The video tutorials walk you through all aspects of getting started with C#/XNA;  setting up a Creators Club account, creating your first simple 2D and then 3D game, and there are ‘Starter Kits’ that help springboard you into different projects.

Bear in mind that you don’t need to purchase the full membership to develop games for both Windows and the Xbox 360, but you will only be able to deploy your games on Windows PCs without the full membership.

Its slicker than I remember, and much more streamlined, I’m actually going to give this another go 🙂

, , , ,

Leave a comment

Gears of War 2


I’ve just finished playing Gears Of War 2 on the XBox 360.

I usually avoid FPS games on the console because I am a Keyboard/Mouse player and cannot get used to the controller but someone who recently got a 360 wanted to lend it to me, so I thought I’d give it a go.

Like similar games I’ve seen on consoles and some PC games recently, Gears 2 uses a recovery system for injuries, so if you are injured (indicated by a blood red cog symbol fading in on your screen) you duck back into cover and the cog gradually fades out to indicate that you are recovering. If you don’t take cover eventually you are incapacitated and can only crawl slowly in an attempt to reach a comrade who can revive you. If you fail to do that in a brief period you will die, game over, reload from last checkpoint. So, I had a chance at survival with my poor controller skills 🙂

The visual style is great; from gritty, city streets under siege, to deep underground tunnels, and hidden complexes, as well as outside scenes in mountains and forests.

Audio is exceptional; well voiced characters, well placed atmospheric sound effects, and some booming weapon sounds, help to get you in the mood.

The AI is good; whilst most grunt enemies use cover, and pop out to fire at you, they occasionally ‘displace’ so you can’t wait for them to pop up again at the same point and fire. Some heavier enemies just walk straight at you, but this fits the style of the semi-mindless ‘tanks’.

Gameplay is pretty good; the variety of action really helps to change this game from what could have been a ‘shooter on rails’ to a fun challenge. You operate on foot on your own, with a partner, or with a small group, at different points. There are several vehicle sections, with some quite unique ‘vehicles’ later on 🙂 The choice of weapons allows for a range of tactical choices, from up close and personal to sniper range, with the ability to pick up dropped weapons so you can chop and change as required.

All in all, I had about 20 hours of fun running through this on normal mode. I’m strongly considering buying this and the first game to go back through it at a harder level.

Overall: Gears 2 gets an 8 out of 10 from me.

, , ,

Leave a comment