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 / Grid Dungeon Generator

Author
Message
Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 19th Aug 2012 11:47 Edited at: 19th Aug 2012 11:49
For my first serious DB Project I am trying to generate a 2D rogue like dungeon.
I understood the algorithm on paper but have trouble implementing it using 2D Arrays.

I am following the example layed here:


I am also using a simple table like this:



I am trying to make a master array, and then divide it into two cells. The problem lies in the division of the array. If I use step in the if statement I get strange results.

I am currently stumped on how to "carve" out the two cells out of my array and store them so that I can randomly choose several cells. (one in my case).

This is my code so far:

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 19th Aug 2012 13:35
I like to avoid having cell divisions lying in between tiles, because it necessitates extra arrays and values. I prefer letting the tiles themselves act as the walls. Here i s an example of what I'm talking about with what you want to do implemented.
Two things to note: I used the #constant keyword to define key tile values. Normally in my own programs I make them shorter and lowercase so that they're not a pain to type. I also swapped the row and column values, because I hate using the row/column coordinates and always get mixed up with x and y values. (I always think "X is the first coordinate, Y is the second coordinate, X is horizontal, Y is vertical" xD)


Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 19th Aug 2012 14:07 Edited at: 19th Aug 2012 17:26
Ok, I think I understand your method.
It's actually pretty simple.
However, you're code does not seem modular. What if I want 30x30 grid and choose only a random set of grids in order to create the rooms?

For example I want to create a huge grid. Choose several grids and make their outer edhes into a wall.
However if I want to do this, I should have an array for each grid I think, right?

How would I do this in code?

I have something like this:


Out of a 15x15 array I can have a 9 cells of 5x5.
How would I do store this cells into separate arrays?
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 20th Aug 2012 00:03
You don't really need to store the cells into separate arrays. You're right that that would be a problem, because DBPro makes creating arrays a pain.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th Aug 2012 00:28
So if I don't store the cells into separate arrays, how do I store them? I need to store SOME info in order to recreate the cells? I'm kind of stumped here.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 20th Aug 2012 03:19
Quote: "So if I don't store the cells into separate arrays, how do I store them? I need to store SOME info in order to recreate the cells? I'm kind of stumped here."

I think you're thinking about it wrong. each room doesn't have to be a separate array!

Look at this code by enderleit: http://forum.thegamecreators.com/?m=forum_view&t=196012&b=1

The array definition is in dungeonmap.dba, defined as:

The "cell" variable is one of the constants defined:

(I'm not sure why he defined the #constants like he did - it might make some algorithm down the line simpler)

The "room" variable gives an id for each room (not quite sure if it's used for anything though)

So, the awesome generation algorithm just is responsible for filling DGMAP_Map with the correct information.

I'm not totally sure what you're asking, but you should be able to manage with a single two-dimensional UDT array for storing all your data in.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th Aug 2012 12:55 Edited at: 20th Aug 2012 12:56
Wel, I am basically asking on how to do the first step,

So, I create an array for my grid. Done.
Next, how do I divide the cells and store them in the UDT array?

That's what I was asking. So let's say I got this larger grid:



I am creating a an array.

dim DNGGrid(15, 15)

I iterate through the array. During the iteration, how do I save my grids?
That's whats troubling me. Might seem really easy to do, but I cannot wrap my head around it, algorithms kill me
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 20th Aug 2012 13:22
I'm still not totally sure what you're asking.

What I said earlier applies here:
Quote: "I like to avoid having cell divisions lying in between tiles, because it necessitates extra arrays and values."


So, lets say you want to move from tile (0,0) to tile (1,0) and you want to have a wall in the way. This is a bit difficult to do, because there's no array element at (.5,0) where you can store information whether or not there's a wall there. My method - if you REALLY want to have walls in between tiles - is to have separate arrays. The tiledata array of size (X,Y), the horizontal wall array of size (X-1,Y) and the vertical wall array of size (X,Y-1).

BUT the better way to go is to have the tiles themselves be the walls. So if you wanted to move from tile (0,0) to tile (1,0), you could always do that if the tile at (1,0) wasn't a wall tile.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th Aug 2012 14:05
Ok, I don't really wrap my head around this.
I am not talking about moving anything.

In very clear english this is what I want.

I want to generate a master grid and divide it in cells as you saw in the image above.
Then I want to store those cells each in a different data unit.
After that I want to choose a number of data units (cells).
After that I create walls for those cells.

That's about it. Is it possible to do this? How?

I am not really interested in making a game, if that would be the case i'd took the algorithm enderleit did and be on my way.
I am trying though to make one myself. Hope you understood what I wanted.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 20th Aug 2012 14:20
I was using the example of moving to talk about the existence or non-existence of a wall.

I mean that making walls in between cells is less straightforward and having the cells themselves be walls is easier. Enderleit's code shows the latter.

In both cases, even though you may have multiple arrays (in the case of walls between cells), you won't have a different array per room.

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th Aug 2012 14:24
You missunderstood me.

I want the (0,0)(0,1) ... to be walls. So the extremities of the cells would be the walls. Of course not in between ...

How can I do this in simple code? Just this. Generate the huge grid, divide it and choose a random cell.
Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 20th Aug 2012 19:54 Edited at: 20th Aug 2012 20:01
Alkerak, I don't think you are explaining what you want to do.

Are all the "rooms" the same size? If so, then why is your array 15 x 15? You only have nine "rooms" so you only need a 3 x 3 array.

Does each room need to be 5 x 5 so that you can have 25 locations in each "room"?

I think what Neuro is saying is that you can't keep track of the "walls" very well if they are on cell boundaries. To keep track of walls that block movement, your grid would look more like this...



And each array element could store a value, perhaps "1" is a wall, and "0" is empty space, or whatever scheme you need for your data.

So, are you trying to generate a dungeon? Maybe like this...



Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th Aug 2012 20:50
Yes, exactly, I want to learn how to generate a dungeon like that, like you showed in the screenshot
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 20th Aug 2012 20:52
Well Rogue is mentioned, and this is rogue if that helps anyone...

http://www.themarriedgamers.net/2010/12/go-hard-go-rogue/

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th Aug 2012 21:32
I know rogue, I used to play it ALOT, still boot up nethack on os x now and then ...
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 20th Aug 2012 22:06
Quote: "I know rogue, I used to play it ALOT, still boot up nethack on os x now and then ... "


Yes, lol. You are the one who mentioned it in the OP. That's why I posted a link for other people to see the dungeon that you want.

Rich Dersheimer
AGK Developer
17
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 20th Aug 2012 23:09
Well, here's a link for the code I used to make that random dungeon map...

http://forum.thegamecreators.com/?m=forum_view&t=174914&b=5

Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 20th Aug 2012 23:51 Edited at: 20th Aug 2012 23:58
Thanks for the code.
Seems complicated but I will try to dupplicate it in an effort to understand it.
Seems to me I really need to learn basic algorithms
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 21st Aug 2012 00:42 Edited at: 21st Aug 2012 01:14
Not sure if you mean randomly generated or not, but here is an excellent example of where you can create this style of dungeon in 3D. It's a tutorial, so it comes with a PDF explaining itself and the project as an example:

http://www.thegamecreators.com/?m=view_product&id=2000&page=tutorials

Just scroll down to 'Huge Dungeons'. I hope that helps.

[edit]

Based on the above link, I attempted my own code, but I did encounter one issue and that's the size of the arrays. In theory if I'm using a 10x10 grid in the Map, I should be able to load it as a 10x10 grid, but the results were skewed. I found if I took '2' away from 'x' and '3' from 'y', it gave results. So in the map file, it's 8x7, in the object array it's 8x7 but in the load array? 10x10. I'm not sure why that is, maybe somebody can point out the error in my code. But anyway, I gave it a shot and I hope that it is useful to you.

Code (images can be take from DBP's Media folder)

Map.txt


Alkerak
15
Years of Service
User Offline
Joined: 7th Mar 2011
Location:
Posted: 21st Aug 2012 13:07
A tutorial would be nice in wich such an algorithm would be explained step by step.
WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 22nd Aug 2012 03:26
I also made a couple of examples (with source code) quite some time ago while I was experimenting with various algorithms: Example_1 and Example_2

Mental arithmetic? Me? (That's for computers) I can't subtract a fart from a plate of beans!
Warning! May contain Nuts!

Login to post a reply

Server time is: 2026-07-21 20:34:45
Your offset time is: 2026-07-21 20:34:45