|Comments on Tuesday 22 July 2008:|
|I've rebooted myself again, starting on another new game project. This time I'm starting with physics, because physics is fun (not to program, but it makes for fun games). I was originally considering making jelly-physics versions of classic games (bouncy squashy asteroids, Pacman bloating up the more he eats and having to squeeze along the corridors), then I swung towards making a pack of puzzle-type two-player games along the lines of Tetris Attack (and less puzzly ones like Tron Light-Cycles variants), but I looked at what gets published on XBox Live Arcade, my chosen target platform today, and decided that individual polished small games is a better way to go than packs of less-polished smaller games, both for ease of publishing and reduction of work.|
So, I started work on the physics of Secret New Project X, wrestled with getting my head round it for two days, and now, suddenly, it has all fallen into place, and it's beautiful. I'm using Verlet Integration (this is a good article, and I was also guided by this paper), for 2D physics. Each body is a triangle of three points with an arbitrary-shaped blob wrapped around it. The three points are joined by firm sticks. The result of this is that if you push on any piece of a body, the force is distributed appropriately amongst the points, leading to spin if there should be spin, and no spin if there should be no spin, pretty much completely effortlessly. The collision detection (on the blob not the triangle) is still a bit of a bear, but that's always been the case.
But that's not the beautiful thing. The first beautiful thing is that when two objects are joined, like, say, a person and an arm, all I have to do is add a new 'arm' body, and pin one end of it to the 'body' body's triangle, and it's acting appropriately already, swinging freely. (Also need to make it ignore collisions with the body it's attached to, but we're not talking about collisions just now.)
But that's still not the really beautiful thing. The really beautiful thing is that the constraints between points are arbitrary and I can extend their behaviour however I please. The upshot of this is that, for example, I can make a weak join, which, if a force is pulling against it more than (arbitrary amount), separates the join and the pieces come apart. Perfect for, for example, the join between a person and their weapon, or a horse and rider. Pushing down on the rider wouldn't separate them, but up or sideways hard enough and pow, they're dismounted.
But wait! That's still not the truly beautiful thing. The truly beautiful realisation is that I can make joins with timers that are caused by events. What do I mean by that? Well, again using the horses and riders for example's sake, imagine a lance charging into the chest of a rider. Pow! The rider is dismounted. But is that all? How about if, in addition, the lance sticks in for a few seconds, carrying the rider along, squirting gore all the way! And even better, the lance could stick into non-meat objects too. Charging beneath a low bridge, the rider forgets to lower their lance and pow! The rider is dismounted by his own lance, left hanging off the bridge for a moment until the lance drops out.
I don't think I can convey how lovely this is, because there's no way to convey how elegantly the code will do all of this, with almost no effort at all. The same physics code also effortlessly does flowing cloth and, with only a little more effort, jelly physics (which I'm not doing right now). I think only a programmer might understand my joy.
Relatedly, I finally decided to take the plunge and try C#, and it's actually not bad at all. Not really much different from C++, practically, but by being higher level it stops me trying to optimise everything when I know perfectly well I don't have to. And XNA is certainly less of a pain in the arse than DirectX. Also, the compiling is lightning fast compared to C/C++, presumably by virtue of the redesign leading to the equivalent of precompiled preloaded headers automatically. Also, no messing with header files. I'm quite impressed. If only they'd called it something you could type into search engines! C# and .NET, you bastards Microsoft. You must have done this on purpose. Surely.
I'm sure there's a fair amount of "another new project? But you didn't finish the last one, or the one before that, etc.!" reaction, which is appropriate. Hopefully this one will be a good one because it meets all three of the criteria whose absence I've identified as reasons why I've dropped other projects.