Farseer Physics in MonoGame

I really like MonoGame. I also like physics. Particularly the Farseer engine, which works very well with XNA and lets you make things bounce around very nicely. I’ve had some success putting Farseer on Windows Phone, so today I thought I’d see if I could get Farseer to work with MonoGame. So I opened up my venerable old Destruction Golf demo from ages ago and just copied across the Farseer library and the code.
And it worked. Pretty much first time. Took me fifteen minutes in total. Amazing. The only problem was with the sound effect that plays when the ball hits the house. This wouldn’t play for some reason. But everything else seemed to move very realistically. If you want to add a bit of physics to your XNA then it is well worth a look. It is the older version of Farseer, but I kind of prefer that.
You can find the sample code for MonoGame Windows 8 here. You can find my video presentation about how the code works here.

Thanks to SieNcE for pointing out that you can actually get the latest version of Farseer physics, which work with lots of other platforms, from here:
Don’t Make the Recipe Static

Today it was time to talk about static class members in the first year programming course. I always have problems with static. If you are not careful you start thinking that static means “doesn’t change much”. This is reasonable in real life, but not in C# programming. In C# programming static means “always present, part of a class and not of an instance”. At this point I thought an example would serve well, so we started talking about contexts where static would make sense.
Consider that you are implementing a system for a fast food store. You have a class called “Dish” and the system stores an instance of Dish for each of the items in the menu. A Dish instance holds the list of ingredients for the dish, the sale price, and the name of the dish. For example, there might be a dish called “Chicken and Chips” which held two ingredients (chicken and chips) and a price value (perhaps four pounds 50 pence). I asked everyone for some suggestions for static class members for the Dish class. Someone suggested that recipe would be a good candidate for a static member.
Not so. The idea of a static member is one that exists as part of the class. Which means that recipe could only be static if every dish was cooked in the same way (i.e. the recipe exists once for the entire class). Each dish needs its own recipe, so this must be a non-static member of the Dish class. However some things, for example the maximum and minimum price of dishes, the maximum number of ingredients that a dish can have all make sense as static members of the Dish class.
Simon has a sign on his office wall, “Consider the context”. When trying to work out what makes sense as static and what doesn’t, this is very good advice. And a good starting point is that “a recipe should not be static”.


Voice Music Upgrade

The slightly upgraded (i.e. more of it works than before) version of Voice Music is now in the Windows Phone marketplace. It now has improved help and full random play. If you already have a copy you will get an upgrade soon. If you have a Windows 8 device and fancy selecting your music by spoken commands (works a treat over Bluetooth) then you can find the program here.