Sunday, March 19, 2006

Did Jesus poo? (if so, was it, or is it still, magic?)

I have pile of notes about writing my city generation code in a modular manner. But there's not much actual code. I've got a very simple line plotting demo.

I want my cities to have some sense. I also want to generate meta data - what's a building, what are walls, what are rooms, a court yard, a road, an alleyway - etc etc. This is too much work to do in one coding swoop, rather I'll do one little piece and then add the rest in increments.

The simplest city generation code I can think of is to have a box drawer on a tile map. You give it coordinates and dimensions.

DrawABox(int startX, int startY, int width, int height) {//...}

Then it can be loaded with constrained random parameters and whoo boxes everywhere, some even overlap. But wait doors! How will our little NPCs get into their houses in New Megasupraopolis?

If you record each point where you place a wall then our function can return a list of it's wall-tiles.

List DrawABox(int startX, int startY, int width, int height) {//...}

One more step and we could add doors - of course we need nicely placed doors.

A 3x3 room A poorly place door

### ###
# # # #
### ##+

So we need a test for corner positions.

bool IsCorner(Point suspectWall, List walls) {//...}

Then with this we can add a door to each random generated room.

Point MakeDoor(List roomWalls)
int r = random.Next(roomWalls.Count);

while(IsCorner(roomWalls[r], roomWalls) != true)
r = random.Next(roomWalls.Count);

return r;

You might want to add code to ensure the loop terminates under crazy conditions where you've managed to create a room of corner tiles.

And with those functions, there's your simple city.

Real cities generally have more structure though - think Sim City. There are important key buildings, and there are roads that buildings are lined up against.

Anyway I'm getting off track. All I've done this weekend is make a new grass tile, which is probably less attractive than the previous grass tile :D I'm currently deciding how big I'm going to make my building walls.

I also need to create a list box in my GUI. Tuesday is a bank holiday, so this is the day I'll probably get cracking.

I need a goal for Tuesday - 9 new tiles: dirt, and 8 grass dirt transitions (maybe some flipping, if I get bored!). a city generation frame work and some rudimentary city generation, a city management structure (linked into the turn scheme).

Usually I like one goal ... so there are three here, I'm being ambitious :D Tile art will probably cause me the most grief because I'm so out of touch with it. (To be honest I was never really in touch with it)

Also a few days back I got fullscreen back in, so that's nice.

(all code here was written off the top of my head - if it doesn't compile, there's the reason!)

No comments: