Generating non-overlapping rooms with an array

Get help using Construct 2

Post » Wed Jan 29, 2014 11:52 am

[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!

https://dl.dropboxusercontent.com/u/106247621/ProcGenDungeon.capx
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Wed Jan 29, 2014 6:34 pm

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? lolpaca2014-01-29 18:35:07
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Thu Jan 30, 2014 1:39 pm

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!

https://dl.dropboxusercontent.com/u/106247621/ProcGenDungeon.capx
B
15
S
4
G
1
Posts: 286
Reputation: 1,988

Post » Thu Apr 17, 2014 1:37 am

very cool.. thanks for posting!
B
98
S
32
G
16
Posts: 1,204
Reputation: 16,715

Post » Sat Apr 19, 2014 8:53 am

Very good thanks for sharing
B
251
S
39
G
15
Posts: 1,964
Reputation: 40,721


Return to How do I....?

Who is online

Users browsing this forum: 25games, Ashley, mcscooter, TRMG and 30 guests