Need help with random map/city generator

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
arampl
Party member
Posts: 248
Joined: Mon Oct 20, 2014 3:26 pm

Re: Need help with random map/city generator

Post by arampl »

Random cave. :)
cave.png
cave.png (81.02 KiB) Viewed 2496 times
Rectangles & 90-angle lines will make random dungeon.
User avatar
Imaculata
Party member
Posts: 102
Joined: Mon Aug 10, 2015 2:51 pm

Re: Need help with random map/city generator

Post by Imaculata »

I'm thinking about having my dungeon feature some rooms that are actually attached to multiple rooms (horizontally or vertically). For example, a hallway, or a throne room. The way I want to do it, is first create all the chains, and then simply run through the maze and place random features. For example, the game may look for a suitable spot where three adjacent rooms form a neat line, and then turn that into a hallway. I have horizontal and vertical hallway templates, one template-room for the end of the hall, one for the other end, and one for the middle.

By the way, I think my afore mentioned system for remembering the origin of a chain would also work perfectly when placing Zelda-escue tools in the dungeon. Suppose for example the player can find the ladder in the dungeon, which allows you to cross rivers and pits. I can then make sure that no river-obstructions are featured in the dungeon before you've reached the start of the chain that that tool is in.

It would look something like this:

Code: Select all

........................Ladder.....................................
...........................|.......................................
.......................... V.......................................
Start..............CCCCCCCCL...................River..........Exit.
 | ............... C ........................... | ............ |..
 V ............... C ........................... V ............ V..
SMMMMMMMMMMMMMMMMMMOMMMMMMMMMMMMMMMMMHHHMMMMMMMMMRMMMMMMMMMMMMMME..
 ..................^...................^...........................
...................|...................|...........................
......... Origin of the chain.....Hallway..........................
Last edited by Imaculata on Fri Aug 21, 2015 7:52 am, edited 2 times in total.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Need help with random map/city generator

Post by Jasoco »

Use the CODE tags if you want to try and make ASCII maps like that. It'll keep it looking right on all browsers.
User avatar
Imaculata
Party member
Posts: 102
Joined: Mon Aug 10, 2015 2:51 pm

Re: Need help with random map/city generator

Post by Imaculata »

Jasoco wrote:Use the CODE tags if you want to try and make ASCII maps like that. It'll keep it looking right on all browsers.
Thanks. Done!
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Need help with random map/city generator

Post by Jasoco »

Yes. See how much cleaner it looks! So nice.
User avatar
Imaculata
Party member
Posts: 102
Joined: Mon Aug 10, 2015 2:51 pm

Re: Need help with random map/city generator

Post by Imaculata »

Well, I finally got the background animations (torches and such) and the collision detection working. I'm using placeholder Zelda graphics for now.

Image
Or click this link.

Collisions:
The game checks 3 tiles ahead of the player, and also checks how far the player is away from the tiles, because we don't want the player to collide until he actually touches the wall. The game doesn't just check the tile directly in front of you, but also those slightly to the side. There's a safety margin, so you don't get caught on tiny corners. I wanted to make sure that the player wouldn't be moving in between 2 tiles to fool the collision.

There are probably easier ways to handle collision detection, but this is my first try at it. I made a function which I provide with:

-The tiles to check for collisions (Shown in green, but turns red if there is a collision)
-The tile that the colliding object is currently on (Shown in white)
-The location of the object
-The direction of the object


The function then coughs up a boolean for whether there is a collision, and an X/Y offset to correct the location of the player (to prevent the player from pushing himself through blocks). This is to make sure that there's always a fixed distance between a colliding object and the tile it is colliding with, that self corrects itself.

Animation:
At the start of the game, the game makes a list of all background animations, and the tiles that they use. When the random-dungeon-generator copies tiles for a room from one of the templates, it checks if the tile is part of an animation set. If so, it makes a new entry in the list of background animations, and also writes down what room it is in.

This allows me to check if the player is in the same room (shown in white around the borders of the room) and the animations, and only play those that are in the same room as the player. This is also very easy for making the rooms in Tiled, because I don't have to worry about placing animations. If the tile is part of an animation set, the game will recognize it, and handle the rest.

Next up:

The next step will be coding the crawler, that generates the maze itself.
Last edited by Imaculata on Fri Aug 21, 2015 6:12 pm, edited 4 times in total.
Rickton
Party member
Posts: 128
Joined: Tue Mar 19, 2013 4:59 pm
Contact:

Re: Need help with random map/city generator

Post by Rickton »

Jasoco wrote:Yeah, the way I am currently experimenting is I'd have the start room, then keep adding chains and place the exit in one dead end and a key in another. The key would open the exit. The exit may be a boss so I guess it'd be a boss key. I don't even know what my generator is going to be used for yet actually. I don't have a plan. I'm just experimenting.

Actually the current generator I'm playing with doesn't use a grid for room placement rather uses a grid as a canvas and rooms are carved into it. I am using a method described here.
Screen Shot 2015-08-20 at 4.00.38 PM.png
So it's not really the same as the Hunt and Kill method I explained above but it works for making maps with odd shaped rooms.
Do you have any code uploaded anywhere of your method of using that kind of generation? It seems really interesting, but he talks about "sliding" the new room around until it fits, and doing that for every single new room. Is there some kind of algorithm or something for that, or a way of doing it intelligently? Because it seems like it'd be pretty inefficient and slow to do that dozens of times for a full level.
Possession - Escape from the Nether Regions, my roguelike made in LÖVE for the 2013 7-Day Roguelike Challenge
And its sequel, simply called Possession , which is available on itch.io or Steam, and whose engine I've open-sourced!
User avatar
Imaculata
Party member
Posts: 102
Joined: Mon Aug 10, 2015 2:51 pm

Re: Need help with random map/city generator

Post by Imaculata »

Small update!

Image

Or click this link.

I have the main crawler code in place, and it looks like it works! As you can see in the screenshot, there are now multiple rooms adjacent to the entrance room. The crawler reports in that it has generated the main tunnel successfully, with a certain length of rooms.

The maximum length of the main tunnel, that connects the entrance to the exit, is (levelwidth x levelheight) / 4.
So if the level is 6 by 6 rooms, that's 36 rooms max in total, so the crawler can only generate a tunnel of up to 9 rooms. I did this, because I want to leave some empty rooms for the other chains.

If the crawler reaches this number, or reaches its maximum of 24 attempts to make new rooms, it will finish building.
It randomly picks a room to the north, east, south or west, and then checks if that room is empty, and if it is not outside the level. If all those conditions are met, it builds the new room, and assigns the name of the chain, and the build depth to the room.

This allows me to always check what crawler-chain a room belongs to, and how deep it is in the chain. The 24 maximum is a safety, in case the crawler gets stuck (which I'm sure it will, since it is blindly creating the tunnels).

The crawler also makes sure that it doesn't expand the dungeon in the direction that the entrance faces. So if you enter the dungeon from the left, then the crawler is not allowed to expand to the left, only up, right and down.

The game now places the exit at the final room of the main chain (instead of randomly). This means that I could designate the room before it as the boss room. To fill in the rest of the maze, I can have the crawler make new chains out ward from any empty room in the main chain.
Last edited by Imaculata on Fri Aug 21, 2015 6:13 pm, edited 4 times in total.
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Need help with random map/city generator

Post by Jasoco »

Your images aren't showing. You need to link to the image, not the page the image is on.
User avatar
Imaculata
Party member
Posts: 102
Joined: Mon Aug 10, 2015 2:51 pm

Re: Need help with random map/city generator

Post by Imaculata »

Jasoco wrote:Your images aren't showing. You need to link to the image, not the page the image is on.
I did, it shows up fine for me. I tried uploading it to a different site, maybe it shows up now.
In case it doesn't, click this link.

Image
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 233 guests