Saturday, March 28, 2009

Mountains



It's surprising the variety of things you can do graphically, as far as tiles go, with just a few simple techniques. For example, I'm rather pleased with the way the mountain tiles have turned out, for such a simple technique. Pictured is a tilesheet for mountains. It's not the transition tiles. In the engine as so far implemented, terrains come in 2 tilesheets; one sheet for fully enclosed (non-transitional) terrain elements, and one sheet with the partially transparent border tiles. The fully-enclosed sheets are lain out in a 4x4 grid of slightly different alternatives to sort of help break up the pattern of repetition.

To generate the mountains, I began with a tiling cellular function. If you are unfamiliar with cellular functions, I recommend reading Texturing and Modeling: A Procedural Approach 3rd Edition. It's a good all-around book for anyone looking to do procedural graphics of any sort. Awesome book, one of the best in my library. Anyway....

I created a method for tiling cellular functions. It's an explicit method, rather than implicit as the cellular methods in the above book are. I begin with an array and I scatter a few random points around inside it. Then I set the value of each array point equal to the distance to the nearest point (F1 function). By making 9 copies of the seed point list, and arranging the copies in a 3x3 block pattern, then taking the array values from just the central block, I end up with a function that tiles with itself seamlessly on all 4 edges.

The value of the F1 function resembles a series of cusps with raised edges; by simply inverting the values I end up with a series of peak-like shapes.




Kind of looks like mountains, but far, far too smooth. But with the application of some turbulence, we're in business.



From here, it's a simple matter of creating a bump map and a colormap, and combining them. The color map is a simple elevation-indexed color scale ranging from a brown dirt color, through a bluish gray stone color, and to the white of snow at the peaks. The exact characteristics of the peaks can be tweaked by manipulating the color scale.

Variants of the tile can be produced by changing the seeds for the turbulence applied. I created a special procedure for generating the noise buffers used to apply turbulence. Two seamlessly tiling buffers are combined into one using a blending mask. By keeping the same seed for the buffer that results in the edges, and using different seeds for the buffer blended for the center, I can create patterns that are different in the centers but that match up with each other on the edges. If you look at the final mountain tile pictured above you can see that some of the individual mountains are similar, yet slightly different. Any of the tiles in the 4x4 block will seamlessly tile with all of the others.

Like I said, it's a simple technique, but the results, I think, are quite pleasing.

Friday, March 27, 2009

Introducing: Archipelago


Experimenting with randomly generating a game world is much easier when the framework upon which it is built is simple, especially for a lone developer. In the past I have built much more complex efforts than this one, with more elaborate graphical styles and more complex graphics and asset pipelines. It's easy for a project to get lost in the complexity. So, with that in mind, I introduce Archipelago (working title). Set amidst a randomly generated cluster of islands, Archipelago is a game of pirate-treasure-seeking, monster slaying, cave-looting hack and slash fun. Built in a somewhat old-school top-down tile based fashion, Archipelago harkens back to the days I spent as a kid playing such golden nuggets as Dragon Warrior and the original Zelda and Final Fantasy games on the old 8-bit Nintendo system.

This image is a preliminary first shot of the framework as it currently stands. (Ignore the red arrow; it is a placeholder avatar.) The map generation scheme in this shot is placeholder, just a random scattering of terrain elements without any regard to layout or structure. The interesting thing to note, however, is that each terrain element is itself randomly generated, rather than drawn by hand using image editing software. Each element combines aspects of color-map generation (random speckle maps of color for dirt/sand/grass/water, to height-variegated elevation color maps for the mountains) and shading/bump-mapping, performed at application start-up, with additional processing to generate the tile sheets that form the border or transition areas where one type of terrain fades out into another. Eventually, I will solidify the assets and merely load from file, as the processing time for generating a whole terrain set can result in a pretty decent pause. However, there is something neat (to me) about the idea of a game that procedurally generates everything. I know that at this time it's not completely practical; but still, it's cool.

The framework is based upon a codebase I have been building over the last several years, that integrates various means of random number generation and procedural noise, color-mapping, Lua-script embedding and encapsulation, scrolling map structures, etc... I call it the Accidental Engine, though I use the term engine loosely, as it is in no way a comprehensive, all-inclusive game framework. Merely a large set of utilities.

As it stands, the game incorporates smooth-scrolling of a randomly generated tiled world, with animated sprites, basic lighting and a fluctuating day/night cycle. I'll keep things updated as I progress.