The map IS the territory

OK, so I’m at the point where I have to create the map to fill the tiles to play my game on. To do that, I need a map generation technique.

There’s a couple of conditions to any technique I choose:

  • it has to generate a random world map which tiles in the x and y direction
  • it has to support the creation/generation of coastlines and mountains. The other biomes will be generated from those two (in combination with a self chosen prevailing wind direction); the mountains are surrounded by hills, and these combined with the prevailing winds give me a rain shadow to place the deserts. The underlying data structure must also support the generation of rivers going to the cost and lakes/oases on the way.
  • This is going to run on mobile phones, so the data structure has to be able to run within a decent time frame and use a limited amount of memory.

I’ve already decided how to represent the final map; I want it to look like cartography, like a fantasy map instead of a realistic map. To do that I have some post processing thought out which I can apply to the tiles. But that means all I need to get from my map generation process is a heightmap, which simplifies the requirements.

So, after some research, it seems there are a number of techniques which could apply:”

  1. a basic diamond square routine: you take a 2D array of floats with possible values between [-1,1] and fill it with 0’s. Maybe prefilled with lines of 1’s to ensure mountain ranges. Then you take the edge vertices of a square and apply random + or – noise to the value of that vertice. Then you take the midpoints of that square (this is the diamond step) and do the same, taking into account the heights of the surrounding array entries. The good thing about this technique is that you only need an array of n by n filled with a single float.
  2. a fBM (fractal Brownian Motion) approach; here you would need to fill each array entry with three floats and apply a Perlin Noise function to each node. This could be modified to get a system where you would only need one float, but that would require a bit of a re-write. The advantage to this system is that you can evaluate each array entry separately. The disadvantages are a higher memory consumption. This is offset by the fact that you can dis-assemble the array into subarrays the size of each tile and process them separately, but you would still be using an array where each entry has three floats. Trying to create an algorithm which just takes one float per entry would not look differently and it would take time to see if it looked decent enough and it might not work in the end, which would be time wasted.
  3. creation using Voronoi cells, as described here:http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/ Somehow, that seems like massive overkill, as there is a lot of information I would not be using and would discard, as well as the fact that I would have to input a lot of rules which in the end I wouldn’t be using after map creation. But it sure does look nice 🙂

I’m afraid I’ll just have to try out all three options to see what the reults look like and what kind of time it takes to generate what I want…

Posted in android, programming | Tagged , , , , , | Leave a comment

Android 9 patches and scaling

Yesterday I decided to pretty up the placeholder UI of my civ/PCG (procedural content generation) map game. I wanted to have some buttons with a background image and, thinking I knew what I was doing, created some ninepatches:

Now, this is a place holder too, but it does kinda suggest what I want to do: have a button with a background so it looks like a wax seal. The activity it’s on has a nice nine patch parchment scroll, so I thought this would look quite nice.

Enter a couple of hours of frustration.

I could not, for the life of me, get the button background to scale correctly. The image was there, the text was there, the text of the button was on the image, centered in the way the content should be. But the background image of the button was scaled WAY too large!

Why would my button image background, which I had taken the trouble to turn into a proper ninepatch, not correctly scale?

After much google-fu, much swearing and even wierd combinations of LinearLayouts, FrameLayouts, ImageViews and TextViews, the solution was depressingly simple: my nine-patch was too large.
It turns out nine patches (those .9.png files) scale up really well. BUT THEY DO NOT SCALE DOWN! So my 256×256.9.png looked HUGE and drowned the centered text.

Making it much smaller (64×64), and all of the sudden everything works perfectly: the image scales and wraps my text very well.

So, to answer the question: “why does my android button image background not scale properly?”, it is because ninepatch images do not scale down.

Posted in android, art | Tagged , , , , , | Leave a comment

BTW

I just wanted to note that I’m not pulling my info out of thin air. I’ve got an application (AppGrouper) and a game (Ringi) out on Google Play.

Here’s Ringi (available for free!):

Making those two taught me a lot about Android. Actually releasing them and have people play them, and more importantly CRASH them, on all their devices taught me more.

At the moment I’m working on a second game which will feature procedurally generated content. Not only will it make it’s own maps, but I’m planning on having them filled with procedurally distributed factions which inhabit procedurally distributed cities, each generating procedurally generated but logically coherent quests and mission.

I just finished up on the main outline of the program (Activities all managed by a “quarter-back” activity, which manages the activities) and it only took me two days to write a tile manager (from scratch!) to handle loading and displaying of the map tiles. I guess the “quarter-back” activity manager is worth a post.

At the moment however, I’m still researching map generation. I’ve pretty much got it sorted; using eiether voronoi graphs or multiharmonic fractals I’ll fill up a large array with heights and use that as a map. Then I’ll use that to create the tiles and do some image processing (enlarging and XOR-ing , that kind of thing) to create the style I want (basically I want the map to look like cartography, like the maps you find in Lord of the Rings/Fantasy books). After that’s done, I use the same backing array and map tile to fill the tiles with little pictures of mountains, trees, cacti etc., all depending on the biome on the tile.
I haven’t yet decided if I want to bake those trees and mountains/hills into the tile or display them dynamically as/when the tile gets loaded. I guess the second, as although that would mean a second drawing pass, it also allows me to do dynamic things (reduce forrests due to logging, create mountains passes).

Anyway, I have the map tiling system in place, now it’s time to generate the filling 🙂

Posted in android, art, programming | Tagged , , , , , | 1 Comment

Hello World!

I’ve been programming for a while now. Certain sites have helped a lot in finding my way, but often the most useful things on the internet are the blog posts by other people who have stumbled around the same issues.

One of the things which I have noticed is that the solutions hardly ever seem to be complete. There’s always something missing, some bit of information which is missing or just plain wrong, toggles which should have been toggled or settings which should have been left un-set.

I hope that this blog will contain a compilation of all those little bits which just don’t seem to come together online.

Posted in Uncategorized | Leave a comment