Thursday, July 19, 2012

Fun, Games & Physics


Have you ever wondered how to write a computer game and how does one handle the complex physics behind a game.

Well, Farseer Physics Engine makes game development simple.

Farseer Physics Engine

Farseer Physics Engine is a collision detection and Physics engine written for Windows Platforms which gives you realistic physics responses.

Farseer allows you to write realistic physics games in C# for Silverlight, XNA, Windows Phones, WPF ect.


I wrote an example game shown below with Lungi our Mascot as the main character just to demonstrate how to write a simple game.

In Expression Blend it is as simple as referencing 3 assemblies namely FarseerPhysics.dll, SpritehandFarseerHelper.dll and Spritehand.PhysicsBehaviours.dll. By doing this it exposes an array of behaviors that you can attach to your objects on your Canvas.

In the example game below you start by attaching the PhysicsControllerBehavior to the canvas, this basically sets the physical properties of the Game World that you are developing.

Thereafter for each object that you want to interact with in the game you attach a PhysicsObjectBehaviour, if you would like the object to explode when Lungi flies into it you would attach a PhysicsExplodeBehavior to the object and set up a PhysicsCollisionTrigger that basically specifies that when object A collides with object B, Object B must explode and be removed from the Game World.

Below is a list of all the objects in my game and the attached behaviors

As you can see by simply adding behaviors to your objects on your canvas and by setting the behavior properties you can create a basic computer game with very little effort.

If you would like to read up more on the Farseer Physics Engine I would recommend the following sources.

Farseer Games for Examples

Below is my little game that was written in 30min, feel free to try it out.

Till later


No comments:

Post a Comment