• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Generate a dungeon map

 
Ranch Hand
Posts: 81
Android Python Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am creating a dungeon crawler, based off of Dungeon Crawl Stone Soup, and I want to know how I would create a method that generates a 2d char array that when printed out, resembles a dungeon map. I want to use the following chars.

# for walls
. for floors
> for stairs going down
< for stairs going up
* for items

How would I accomplish this? I am completely new to random generation, so I don't know. I am using JavaFX, so I don't know how that would affect the process.
 
Saloon Keeper
Posts: 10306
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Procedural generation is an interesting but difficult topic.

Since it's deeply rooted in artificial intelligence, a natural question to ask is: How would you generate such a dungeon by hand, as a human?
 
Rocky Rocha
Ranch Hand
Posts: 81
Android Python Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, first of all I would draw rooms, both square and round. Then I would draw paths between those rooms. Then, I would create paths between the already existing paths . Finally I would Clean it up and make it look better.

I have no experience with AI, and if I need to learn it, could you direct me to a tutorial? I have looked myself, but I haven't found any good one for Java.
 
Rocky Rocha
Ranch Hand
Posts: 81
Android Python Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is an image of what I want it to do. Just a basic idea of what I want.
Dungeon-Generation.gif
[Thumbnail for Dungeon-Generation.gif]
 
Stephan van Hulst
Saloon Keeper
Posts: 10306
217
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, so the first step is to define the basic shapes of the rooms, and to make sure that the rooms don't overlap. I suggest you use the shape classes in the java.awt sub-packages for this task. You can easily create basic shapes with java.awt.geom.Rectangle2D.Double and java.awt.geom.Ellipse2D.Double, and move them around by their x and y coordinates. To check that rooms don't overlap, you construct java.awt.geom.Area instances from their shapes, intersect() those areas and check if the resulting area is empty.

Use java.awt.image.BufferedImage to represent your entire dungeon level. Draw the dungeon by asking the image for it's java.awt.Graphics2D object, and fill() it with the shapes that represent your rooms.

Don't worry about anything else except generating some random ellipses and rectangles first, and making sure they don't overlap.

To see your algorithm in action and help you debug it, I suggest you create a GUI that displays your BufferedImage.
 
lowercase baba
Posts: 12749
51
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rocky Rocha wrote:Well, first of all I would draw rooms, both square and round.


There is just a LOT buried in that simple statement. How do you decide where to draw them? How do you decide which room is square, and which is round? How big should each be? How many? How far apart?

and there are probably a hundred other questions i've not even thought of.
 
Ranch Hand
Posts: 374
24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I advise running a google search "rogue dungeon generator code java"
It will turn up lots of useful links, tutorials and code samples which should assist you in this task.

I also advise just getting the system to work with a text string or text file output that spits out your sample generated dungeons.
Once you have verified that that is working, then try integrating it into a graphical display system such as JavaFX and rendering as you wish.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!