At long last, my uber-cute sheepherding game Sheeplings v1.0 is released and ready for purchase! It just might appear on a few portals as well in the near future. I ought to make a v1.1 to improve things even further, but – hopefully understandably – I really feel like diving into something new for the moment. Enter my new project – currently called New Project!
Or rather: enter prototype month.
A while ago I made an experiment with dynamic in-game music that I intended to use in a game called Crux. Recently I made a prototype of the idea, and…it just didn’t work. It was seriously lacking in fun. When it comes to (relatively) new ideas there’s just no getting around it: prototyping is invaluable to sort out the trash from the golden nuggets.
Instead, I started to examine other game ideas I’ve had: a SimCity-esque casual strategy game, a resource management game involving sheep, a game featuring automatically generated logic tests, a Guitar Hero-like casual game, and much more. I think most of them would work, but I decided to go for a game with strong, non-experimental gameplay.
Yes, I’m making a match-3 clone.
But there’s a twist to the tale: I actually like match-3 games. That is, I love the hypnotic gameplay, but I don’t like most actual games that implement it. They’re too slow or too mellow or too stagnant or too frenzied – there’s always something that leaves me un-gripped. So I won’t be making a straight clone – I’ll be making something I want to play myself. Also, given the twisted madman that I am, I won’t rest at that. There will be two different modes of match-3 play, and one special gameplay mode for “boss battles.” In short, I’m preparing a game that combines features from match-3 games, RPGs and Guitar Hero. Madness; it’s madness I tell you! Normally my cynical mind would have started to back away slowly by now, but I am approaching this in a careful way. Thanks to the power of prototyping I’ve managed to create simple versions of a few of the game modes, and they show the most important aspect: it’s fun. Even in this bare-bones manner the gameplay itself is fun. So I think I’m on to a good start.
I mentioned Guitar Hero; of course I’m not making a Guitar Hero clone in any way. It’s just some features that bear a similarity. For example, the 3D scrolling background that delivers objects to the front, along these lines:
It’s almost ridiculous, how much effort I had to put into making that. It took me all Sunday to get it running like I wanted. Let me give you a chronological summary:
- First problem: BlitzMax’s features no “draw polygon” function. In other words, BlitzMax only works with two-dimensional square bitmaps (or plotting primitives that would be too slow). Okay, some searching around gave me a DrawPolygon function that some kind BlitzMax developer on the Blitz Forums had written. Time to test it out.
- Second problem: the DrawPolygon function only implements affine texture mapping. In other words, a straight interpolation. Imagine that you have a polygon and a texture; affine texture mapping simply “smears out” all the pixels in the texture so that they’re evenly distributed. This is not a good thing for perspective.
- And this brings us to the third problem: 3D systems draw images using triangles. In order to draw a square, you draw two triangles. Imagine what happens when you move the texture coordinates in a scrolling manner while simulating perspective using affine texture mapping? It looks like two trianges that don’t really fit together.
- In order to fix this I – naively – imagined that there might be some primitive drawing function that used quads instead of triangles, and that – magically – would correct this behaviour. Hell no. Oh well, let’s leave that problem; let’s move on to the perspective issue.
- Oh, look here! Both DirectX and OpenGL have support for XYZ coordinates, and not just XY! This means that I can just modify the Z coordinate and get perspective, right? Wrong. This requires additional setup of cameras and whatnot – something that BlitzMax apparently doesn’t do by default. I simply cannot be arsed to go through that, so let’s consider the options.
“What options exist,” one may ask. “It’s a fact that affine texture mapping looks like crap and that just adding a Z coordinate doesn’t fix it. You’ll have to be satisfied with affine texture mapping and this weird shift between triangles.” Bullcrap, I say! Time to think back to the days of glory; the days of optimization; the days when no 3D graphics cards were available. I recalled that I messed around with 3D graphics and perspective correct texture mapping back in the 486 days, and there’s really no magic behind it. All you have to do is put in a (1 / z) here and there, to make sure that the z value affects the projected x and y coordinates. So how could I exploit this to make things look better?
It’s really so simple that it hurts.
In order to minimize the projection error, all I have to do is subdivide the scrolling area into chunks, calculate each chunk’s coordinates with respect to the z variable, and then draw these chunks using normal affine texture mapping! I feel pretty stupid that I didn’t think of this immediately, but better late than never. So, to sum things up: in order to draw that nice scrolling background you can see above, what I do is make a loop that draws 16 (or 32 – I haven’t decided yet) horizontal strips (since that’s where the perspective is most correct). This not only gives a very good impression of perspective, but it also takes care of the nasty issue with the sliding triangles.
Even though 3D systems are getting more and more advanced, and no-one implements software 3D engines, I still think it pays to know basic algorithms.