Wednesday, 18 July 2012

(Game Dev) Doorway generator is almost done...

I'm back. Doorway generation is almost done. But I had some stupid mistakes in the code that I fixed. First of all, the generator made a mirrored dungeon. I was sure about that Unity's z-coordinates increases downwards, but it is exactly the opposite. (silly me) So when I was checking for the doors I was looking like a stupid, why I get those weird numbers.

I'm using a very simple way to determine where the program has to add doors. Just check the neighbors, as always with a for loop. Of course, where there is no room, we don't do the check. If it finds neighbors, it has to mark, where the doorways are.

I should use 4 booleans for this, but I use only one integer. There are numbers for each direction: 1,2,4,8.
If you add them, you can't get the same number from the different combinations. Just think about binary to decimal conversion. You have a number, for example: 1101 which is 13. If 1 is eastern doorway, 2 is southern doorway, 4 is western doorway and 8 is the northern one, 13 means, there are doorways to south, west and north. 15 means, there are 4 doorways. 0 means no doorways. It's so simple.

I will use an array of booleans instead of one integer. The array will have 4 elements with 16 different possibilities / combinations. It will work as I wanted to do first time. But different elements will mark different doors. [1,1,0,1] means there will be door all the sides except the eastern side.

1 = true
0 = false

I won't have time to continue this project in the following days, I have to create some 3D models for an other projects, which will be exciting too. So, guys from the team, I didn't forget about you!

PS.: I'll will have one more post very soon, I have a little material in it which is not mine, I would like to get permit to show it. Nothing special, just some textures. Maybe, I should simple post it without consequences.

No comments :

Post a Comment