Farseer Physics in XNA 4.0 for Windows Phone

_In this tutorial series, we will go though some of the basics with
Farseer Physics Engine 3.3.1 to implement physics into you 2D games.
To get started, go to http://farseerphysics.codeplex.com/ and download Farseer Physics Engine 3.3.1 to your computer.
With the download comes the library itself + many cool samples you can learn from.Getting started
Start by creating a new project in Visual Studio and create a XNA 4.0
Windows Phone Game. When the new project is created, add a reference to
the FarseerPhysicsXNA library (the dll is in the folder of Farseer
Engine).

_Also, add these using statements:

using FarseerPhysics.Dynamics;

using FarseerPhysics.Factories;

Now we are ready to start implementing physics into our game!

To do this, we must create a Farseer World object that will contain our world of physics.

It’s simply done using the World class from the Farseer library:

World world;

Now, in LoadContent, we will run the constructor for the World object, giving it a gravity of 1, meaning that the objects will get a pull of 1 in the Y-axis.

Adding static and dynamic rectangle To add a box to our world that will stay still (not being pulled by gravity or affected by dynamic(moving) object, we add a Body object. We need three boxes in this example, one dynamic and two static.

Body rectangle;
Body rectangle2;
Body rectangle3;

And then in LoadContent, we say that the Body should be a rectangle, static and it’s position.

This function simply converts the physics simulator units to pixel units. We can see that we have chosen each unit in the simulator to be 100 pixels. That means that the resolution in the simulator world goes from 0 to 8 in the X-axis and 0 to 4,8 in the Y-axis.

Applying force It’s also possible to apply force using normal conditions. In this example, I added a force that will make the objects bounce.