Sign in to follow this  

Generated tile map arrays, seeds, populating questions

This topic is 2115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a working tile engine which draws tiles based off an array. It uses 3 arrays, which have some corresponding parts as far as layout and size.

The first array is the tile array, which distinguishes which tile which tile from the tile image to draw like:

[code]//Array #1--map tiles
0,0,0,0,0,0,0,0,0,0,
0,9,9,9,9,9,9,9,9,0,
0,9,9,9,9,9,9,9,9,0,
0,9,9,9,9,9,9,9,9,0,
0,0,0,0,0,0,0,0,0,0[/code]

Where 0 tells it to draw a wall, 9 is a floor tile.

The second array draws any objects/items on a layer above the map.
[code]//Array #2--items
0,0,0,0,0,0,0,0,0,0,
0,44,44,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,52,0,0,0,
0,0,0,0,0,0,0,0,0,0[/code]
Where 0 means draw nothing while 44 and 52 are index numbers of tiles from a sprite sheet of items to draw.

While yet the 3rd array determines which tiles are passable or walkable. 1 means impassible, 0 means passable.
[code]//Array #3--physics
1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,0,1,
1,1,1,1,1,1,1,1,1,1,[/code]

For testing purposes I just multiplied the above arrays 50x wide and 100 times long to make a map 500x500 (250k tiles). I found that it worked best up to 500x300 (150k entries in each array).

The actual physical size of having an array 150k entries long is almost 3 megabytes of text, while the actual code to draw the map is a few hundred kilobytes.

[b]I want to make basically roguelike maps, and am wondering how they go about generating the arrays.[/b] Like clearly I could just randomly add 150k entries, but the edges of rooms wouldn't have walls, they'd be randomly everywhere.

[b]Ideally I'd use some pre-defined "pattern" arrays for individual rooms, and just randomize "seeds" in the jumbo arrays [/b]which determine the index locations to add my pattern arrays.

Anyone have any ideas? You can see what I'm talking about here (runs best in chrome browser) http://simplehotkey.com/Tiles/main.html

Share this post


Link to post
Share on other sites
I've developed a library for generating such maps (for personal use only) for my game [url="http://www.jungle-troll.com"]here[/url]. One of the algorithm I currently do not use has the following generation strategy:

1. Split the map in chunks. The size of them is up to you, but they should be equal.
2. Randomly decide in which chunks do you create rooms and in which you don't.
3. Create predefined rooms in the ones you decided to do so
4. Determine (randomly or not) which rooms should be connected to which rooms.
5. Generate paths between these rooms. Paths may also intersect with other paths.
6. You got yourself a nice rogue-like map.

This is simple, but you can tweak it more. Also I do find it is inefficient to use 3 arrays for it. I use only one, and in each one I use objects (like C#/C++ ones) called "cells" that hold all the information I need, including items and collision data. That would save you some memory.

After you have the base map, you could go on with smart algorithms for items generation.

Share this post


Link to post
Share on other sites

This topic is 2115 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this