GM Riscvul here! Another week another post! Before I dive into the topic for today, lets give a brief update on progress...

GM Riscvul: Buried in vicious homework assigned by his Algorithms and Complexity Class, recently has dived into documentation for the Lidgren Networking Library in order to implement LAN gaming and the networking screens.

Corndog: Too embarrassed about the lack of sprites to show off his rapidly developing character objects. Currently implementing camera movement.

Now on to Game State Management. This has been my department since the beginning of the project. State management is not unique to games as it is based off the idea of a state machine which has existed from the beginning of computer engineering. I will spare the wordy definition and call a state machine a collection of states with a starting state and at least one final state. Each state itself is related functionality which loops unless a transition occurs.

Okay so that was boring, now lets apply this to games. A game is easily defined as a state machine or collection of states. What states you ask? Well lets look at the average game... When the game starts we see a start screen waiting for us to push start to continue. Once we push start we move into a menu where it waits for us to select an option. From the menu we move into the game and play around for a bit. We push pause and transition into the pause menu. The pause menu waits for us to push buttons and so on... Each one of those screens is a separate state which loops and waits for specific inputs to transition to a new screen (state). A key aspect in game design is managing these states and making them play nice with each other. The picture below known as a flow chart illustrates relationships between game states.

How is this done in Gunslingers? Well I started out with some help. The XNA site has downloadable code for game state management. This provides a great starting point as it is easily expanded to contain more screens and functionality.

Three classes make up the management in this code: InputState, GameScreen, and ScreenManager. InputState handles all cross-screen input or input required to access other screens and trigger transitions (i.e. the escape key). GameScreen provides an inheritable bunch of essential functions for any screen in the game. ScreenManager does the hard work. It shifts screens around, triggers transitions, closes screens that should no longer be up, and in short helps the programmer out alot. Any new screens you wish to add simply need to inherit from GameScreen and be added to the ScreenManager's screenList.

Adding functionality is also easy. Editing ScreenManager allows one to change tranistions and timing. Editing InputState allows you to add new cross-screen inputs. I implemented mouse movement and picking as well as a console command.

Another nice thing about the GameStateManagement code is it gives you a menuScreen class that makes it easy to build menus. Simply inherit from MenuScreen instead of GameScreen and add menuEntries to the screen. InputState takes care of menu navigation.

Once the network screens are ready I will present a video tour of the menu system to give a visual idea of how state management works. Anyways so much more networking and homework to tackle.
I know, I know. you have been saying: "Corndog! whats the deal?! I already know how to set up the debug view for Farseer, thats not what my problem was. I would just like a straight forward guide to how to make it do stuff!!"
Well, maby thats not what you were thinking of. but I sure was...anyway.

Well here you go, the moment you have been waiting for. this is where the fun begins. the how and why of the Farseer Physics Engine.

The How:

After you have succeeded at getting it all set up. now the question is what code to use to get stuff to start bouncing around the screen?

to start off you need to make a physics body. or as the most recent version of Farseer calls it: a "fixture."
in the loadContent method of your XNA game add the following line (or something like it.)

rectangleFixture = FixtureFactory.CreateRectangle(world, 4, 4 , 1, new Vector2(0, 0));

This will create a physics fixture in the shape of a "rectangle." actually this one will be a square because we have set the height and width to: '4'
The First parameter if the CreateRectangle Method takes a "world" object that is created as a private member variable of the game class. (for more info on this see the previous post labeled "Physics engine woes part 2.")

The next to parameters are the width and height, (in that order.) You should be aware that in the new version of Farseer the values are in the metric system. this means that our previously determined size is 4 meters by 4 meters. Why the Farseer programmers decided to do this is beyond me. If you figure that out please let me know. because I thought pixels were a much better convention.

Next is the mass of the fixture. this will affect how the object behaves in the world based on the forces applied to it. currently it is set to '1' as far what values to use in your game, you will have to mess around with the values until you see the behavior you are looking for.

the last parameter is a Vector2 that contains the


Well that was a mouth full. NEXT!!

to make this more interesting we will need to set a few more variables on this fixture to make it more interesting. add the following lines (or ones like them.)

rectangleFixture.Body.BodyType = BodyType.Dynamic;
rectangleFixture.Friction = 2.0f;
rectangleFixture.Restitution = 0;

The common types of body are Dynamic and Static. A static Body will not move from where it is placed. (that Vector2 from earlier.)
If its Dynamic then it will be affected by gravity and any other forces you see fit to subject it to.

Friction should be kind of obvious but in case someone missed that day of science class because you were out on the town with your pet chinchilla...*cough*
Friction determins how "slippy" the surface is when it comes in contact with other surfaces.

Restitution is, simply, how bouncy it is.


And thats how to create a physics Fixture.

here after you can make it do things by applying various forces such as linear velocity, angular velocity, etc. if you need to know the how to on those I suggest you look at the farseer Documentation but mostly just use visual studios auto complete function. that is honestly the way that I figured out most of what I know about Farseer.

Happy coding.

CornDog
Well, we're back. and this time we have friends...not really. but anyway...*Cough*
and on with the useful info.

Today's post is a continuation of last weeks post...*cough!*...and it will be about how to implement the "Debug View" in your Farseer enabled XNA game.

First you need to copy the Debug View XNA folder into the main folder for your project. This can be found as part of the "Hello World" download from the farseer website. Be sure you are using Farseer 3.0 or better.

In your project right click on the title of your project in the solution explorer. select "Add" > Add an Existing Project. Navigate to where your copy of the Debug View is located and select the DebugView 3.0 XNA.csproj file. this will add the Debug data to your project. you will then need to add the following to your code:


public class Game1 : Microsoft.Xna.Framework.Game
{
private World world = new World(new Vector2(0, -60));
private DebugViewXNA debugView;

public Game1()
{
debugView = new DebugViewXNA(world);
}

protected override void LoadContent()
{
DebugViewXNA.LoadContent(graphics.GraphicsDevice, Content);
}

protected override void Draw(GameTime gameTime)
{
debugView.RenderDebugData(ref proj, ref view);
}
}
}

In the above code the lines you will need to add are listed in the methods they must be placed in. this is of course based on using the default XNA game setup.
one thing to mention is that the line:

private World world = new World(new Vector2(0, -60));

Is listed Because the farseer World variable is needed for the "DebugViewXNA(world);" call. you would need the world line even if you do not use the Debug View.

And if you do that you should then see all kinds of pretty shapes were all your Farseer Fixtures are.

I hope this helped. Next time I will go over some of the basics of how to use the Farseer Physics engine in your XNA game. until then, have fun tweaking.

CornDog