Building rooms with blocks...?

For questions about using Classic.

Post » Tue Nov 22, 2011 7:56 am

Hi... again. This question is in relation to the one I asked just before, beleive it or not...

Anyway, I've got a system going where the player can build a "starship" out of square blocks, which are aligned on a grid. There are solid wall blocks, and ground blocks. I'm trying to make it so the player needs to build walls to build a room in the starship, and also need to place ground blocks in the empty space so the room is enclosed.

What method should I use to "detect" whether the room is "complete", ex there is wall blocks enclosing the entire room and there is ground blocks taking up the whole floor (no holes). Or better yet, is there a way to detect if a whole room is created, and then fill it in with ground?

As I said, the placing thing is all working. Just not the detection.

Or is this too complex a thing to do?spacewarguy2011-11-22 07:57:52
B
8
S
2
G
2
Posts: 144
Reputation: 1,588

Post » Tue Nov 22, 2011 11:29 am

Hmmm, that is a tough one. I imagine it'd possible using an array in the same way a paint bucket tool is used in a paint program, but it seems a bit inefficient since if a room isn't complete it'll have a lot of checking to do... but it might be a start:

http://en.wikipedia.org/wiki/Flood_fill
B
15
S
6
G
6
Posts: 103
Reputation: 2,968

Post » Tue Nov 22, 2011 7:28 pm

Store the walls in an array and flood fill the area outside the walls, then any place that isn't filled create a floor sprite.

I made an example capx but then noticed that this was in the CC section. I'll post it anyway since it doesn't use anything that CC doesn't have.
http://dl.dropbox.com/u/5426011/examples%208/fill.capx
B
79
S
24
G
52
Posts: 4,725
Reputation: 39,713

Post » Tue Jan 28, 2014 6:13 am

Thanks for this. This helped a lot. R0J0hound, your create fill keeps repeating and takes up processor. How can I make it so that it only creates the fill once per space rather than infinite times?
Check out my games on Google Play:

BEAST ATTACK (500,000+ downloads!)

ASTROJUMP
B
34
S
8
G
1
Posts: 398
Reputation: 3,499

Post » Sun Feb 09, 2014 5:47 am

It crashes when I place multiple filled blocks.
Check out my games on Google Play:

BEAST ATTACK (500,000+ downloads!)

ASTROJUMP
B
34
S
8
G
1
Posts: 398
Reputation: 3,499


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests