Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411476 Posts in 69369 Topics- by 58424 Members - Latest Member: FlyingFreeStudios

April 23, 2024, 03:05:32 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Connecting rooms in procedurally generated platformer
Pages: [1]
Print
Author Topic: Connecting rooms in procedurally generated platformer  (Read 843 times)
Kentz
Level 0
**


zenith au lait


View Profile
« on: March 26, 2017, 06:52:35 PM »

so I'm trying to work on an algorithm to generate a map for a 2D platformer, but I'm having trouble on how to connect the rooms.

the map is a 3x5 grid where the middle row will always have 5 rooms, and the top and bottom lines will always have 2 randomly positioned rooms just like this:

Code:
[  ][  ][7][ ][4]
[10][11][6][3][5]
[  ][17][ ][ ][2]

i already got the map generation and room positioning done, but how should I work with the room connections? I have two ideas so far:

- make a giant room composed of 9 mini-rooms and connect them by erasing walls
- set a variable that will direct the "room change event" to the correct one (kinda like a linked list)

any tips?
Logged
Meteorbyte
Level 0
**



View Profile WWW
« Reply #1 on: April 12, 2017, 03:06:49 AM »

Hi!

I would divide this problem into a double solution:

FIRST: I would simply make a practical solution for where to put the entrances and exits to each room: Make each of the 4 walls in the room have 5 "parts":
 
Code:
   1 2 3 4 5
   _ _ _ _ _
  |         | 1
  | (This   | 2
  |  is a   | 3
  |  room)  | 4
  |_ _ _ _ _| 5


This way, you can simply remove one part to connect with an adjacent room. Of course, you can divide each wall into 7, or 9 parts, or whatever number you wish, depending on the size of your character and how you want the game to feel. In any case, I think odd numbers will work better (3, 5, 7, 9...).

====================

And SECOND: Design every room to have ONLY entrances, and no exits. Wait- what? Yup! That's what I said.

Then, when you start the game, every room will check for the entrances to the rooms around it, and will create exits from itself into those rooms, by removing the corresponding wall "parts" which I told you about in the first point. This should be done at runtime, of course, during the execution of the game.

Hope this helps! Happy coding! Beer!
Logged

Check out WOODPUNK, a fast-paced action game with procedural WEAPON generation, hundreds of enemies to battle and fully destroyable enviroments:
http://steamcommunity.com/sharedfiles/filedetails/?id=895158311

Follow us on twitter: https://twitter.com/meteorbyte_stu/
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic