Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Help with procedural generation

Author
Message
madmaz
17
Years of Service
User Offline
Joined: 14th Mar 2009
Location:
Posted: 5th Jul 2013 22:37
Hello guys

I'm starting out with a new 2D game called "The Bank Robber" and I was wondering if there was anyone here any good at explaining Procedural Generation. I've done quite a lot of research on it but can't really apply it in programming.

There were a few things I wanted to do with it. First of all I wanted to generate whole cities. With roads buildings the lot.

Secondly I also wanted to generate the building inside (Well banks).

I'm not sure how to go around it. But as soon as i've got this figured out (With your help) i'll be sure to place the game on the WIP board.

Thanks in advance to anyone who decides to help out.

Programing is not as easy as it seems at first... the learning is never really over...
ShellfishGames
13
Years of Service
User Offline
Joined: 6th Feb 2013
Location:
Posted: 5th Jul 2013 23:49
I think the first step would be to think of a possible logical representation of your scene, e.g. a city of buildings. The (probably pseudo-random?) procedural generation process will ultimately result in a 3D mesh, but it makes things a lot easier if you've got a more abstract representation in between that is reduced to the most simple set of attributes required to describe it.

For instance, if you want to generate a city consisting of buildings, you could define a type tBuilding that contains a building's position, size, texture etc. You can then create a certain amount of instances of that type with randomized attributes, make sure they are distributed well in space, don't overlap etc., and once this is done it can all be transformed into a mesh.

At least that's one way to approach it. But I think the general premise is really to reduce your problem to a set of attributes (and randomize them in some way), while making sure certain constraints are not violated.

Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Jul 2013 21:04
I have started a tutorial series on procedural generation: http://forum.thegamecreators.com/?m=forum_view&t=203786&b=1
I've only covered the very basics so far (which might be of use to you anyway) but I'm in the process of writing the next part, which will be about designing rules to produce useful outcomes.

I've never done buildings or cities before but I'm sure I can work something out to help you. Should be fun.
madmaz
17
Years of Service
User Offline
Joined: 14th Mar 2009
Location:
Posted: 7th Jul 2013 16:21
hey guys, I've made a little code for generating a city.

What it does is quite simple, generates a city width and height, then the city will be a big rectangle. After that I made it erode every side of rectangle. But I have a small problem.

Sometimes I have city sections that are not in the main city sector.
I've attached an image so you guys can see what I mean

also, I'm sure there is a way to fix this just with math, just not sure how.

If it helps out at all the red areas are all 1 and the white is 0.

Programing is not as easy as it seems at first... the learning is never really over...
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 7th Jul 2013 16:36 Edited at: 7th Jul 2013 16:36
Quote: "If it helps out at all the red areas are all 1 and the white is 0."


This could be your answer.. sorta.. Basically, even though it will slow the generation down a little, it wont slow it down much. But have each block check its surroundings. If the surrounding doesn't have at least a 3rd of it covered, then remove it by changing it from a 1 to a 0. You would do this after your done generating.

https://soundcloud.com/toraktu
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 7th Jul 2013 16:55 Edited at: 7th Jul 2013 17:00
If you had an array 200*100 and you put a 1 in random slots that are adjacent but not diagonal you get the same effect with no bugs. But I don't think that you are considering roads. I would make the roads first, and then fill in the gaps with buildings.

I made a building generator. I just randomly selected windows, and doors, and walls. Windows repeat on nearly all buildings, so you only need one section of a window, and then repeat it. The roofs, can be flat, or whatever you like.. Empire State style. I don't think that buildings are much of a coding challenge, because it was one of my first projects in DBC.

Mage
Valued Member
19
Years of Service
User Offline
Joined: 3rd Feb 2007
Location:
Posted: 7th Jul 2013 17:57 Edited at: 7th Jul 2013 18:00
Quote: "If you had an array 200*100 and you put a 1 in random slots that are adjacent but not diagonal you get the same effect with no bugs. But I don't think that you are considering roads. I would make the roads first, and then fill in the gaps with buildings."


I agree. I would break everything into a grid. I would start with an empty space and fill it with a generic flat/empty city variation like generic grass lawn or paved parking lot.

Then I would begin laying roads. Maybe the roads would be in square city block orientations. Or possibly randomly placed horizontal and vertical roads.

Id then have code to run through all of the squares looking for intersecting roads, changing those areas to intersection grid pieces.

I'd plot any essential buildings or parts at this point.

Then I'd begin selecting buildings or building parts, starting with the largest variety and searching for random roadside spaces for them to be plotted. Id work my way down to the smaller pieces.

There's a lot of places where randomness can be inserted.

For more sophisticated things like diagonal roads, etc. You really just need to build on a framework like this. Create all of the grid based segments for what ever you are making, in a way where they can snap together with basically any other part. Some exceptions are okay. Such as you really don't want road to cut away immediately to grass. So make a dead end roadway piece, and program the city generator to always cap the ends of roads with it. In that specific case it might be good to have several dead end variations that the generator selects for variety.

madmaz
17
Years of Service
User Offline
Joined: 14th Mar 2009
Location:
Posted: 7th Jul 2013 19:21
This is to get my main city layout. each one of these little white blocks will have 4 buildings. Well not 4 buildings it will be a 4 block area. Some items that will be placed on the city will be 8 or ever 16 blocks in size. Roads will be placed between each one of the white blocks.

However the generator would after making the city and the roads delete
delete some road segments to give the city a less grid like appearance. In a way you could have dead end roads, but that would be up to the generator to work out.

after the road deletion I would place all important buildings in. since buildings like banks will be some very large buildings they will be placed in first, because the city might ran out of places to position these elements. after all important buildings are placed in I would fill the rest of the map with filler buildings.

Programing is not as easy as it seems at first... the learning is never really over...
JackDawson
14
Years of Service
User Offline
Joined: 12th Jul 2011
Location:
Posted: 7th Jul 2013 21:27
I have to agree, your ideas you all have is way better then mine.

https://soundcloud.com/toraktu
Libervurto
20
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Jul 2013 00:20
I haven't read through this yet but it looks amazing: http://citygen.net/files/images/Procedural_City_Generation_Survey.pdf you should definitely take a copy. This guy seriously knows his stuff. Got it from here: http://www.citygen.net/
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 8th Jul 2013 01:13 Edited at: 8th Jul 2013 01:15
Quote: "I haven't read through this yet but it looks amazing:"


He he, the document has an example exactly the same as I said, almost word, for word, but in greater detail.

Login to post a reply

Server time is: 2026-07-07 20:23:44
Your offset time is: 2026-07-07 20:23:44