Generating non-overlapping rooms with an array

0 favourites
  • 5 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • [Hi - posted this in another thread, but thought I'd throw it out to the group!]

    As you can see with the capx below, I'm auto-generating rooms of random length and width using just a single map array, but I can't figure out a way to stop them overlapping.

    I tried making a function to test if the cells at Map.PositionX and Y + Roomsize X and Y etc, were anything other than zero before the rooms were drawn, but that didn't seem to work - I'm quite new to arrays though so I probably got something wrong.

    Ideally, I'd like each room to be spaced at least one 'earth' tile apart (walls included) so I can then connect them with corridors. If anyone could please give me a hand with this, I'd be really grateful!

    dl.dropboxusercontent.com/u/106247621/ProcGenDungeon.capx

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • OK, I think I have a solution to this, but I'm not quite sure how to make it happen. Here comes the pseudocode:

    Make a second array ("RoomTest") with the same properties as "Map" and run the room-generating algorithm through that instead.

    Once room is drawn, test whether any 1s on "RoomTest" are also currently present at the same position on "Map"

    If not, transfer all 1s on "Roomtest" to the same position on "Map"

    If so, clear "Roomtest" and start the loop again. This should keep generating new rooms at new positions until a valid room is found.

    That's how I think it would work, but I'm not sure how to code it exactly... any help? <img src="smileys/smiley4.gif" border="0" align="middle" />

  • If anyone's interested, I figured it out in the end - capx below. Might be useful for anyone who's working on a roguelike-style game. Next step: corridors!

    dl.dropboxusercontent.com/u/106247621/ProcGenDungeon.capx

  • very cool.. thanks for posting!

  • Very good thanks for sharing

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)