First I'm going to talk about how rooms work in our game. Rooms are defined as rectangles with a length and width, they can have doors generate on any (or all) sides. This is determined when the room is created by our designer and hallways attach to available doorways using a few algorithms. They are split up into tiles with the top left being 0,0 and the bottom right being RoomX-1,RoomY,-1 as shown in this below picture. The doors have their designated coordinates being outside the bounds of the room.
Up until now our rooms were locked to one orientation. This was due to the difficulty of calculating the transform of the doors. Eventually I boiled it down to a math problem.
I have a plane (the room).
The doors are points on this plane listed as relative to 0,0 (the origin)
By rotating a plane 90 degrees around the origin I can calculate the final points of the doorway relative to the origin.
This is X'=-Y and Y'=X and repeating that as many times for as many rotations as needed. Then it was an issue of this would spawn the room in a different position so I had to account for that. That was real issue, by rotating the room it gets wildly different max and minimum coordinates. This was fixed by translating the room post rotation by the negative bounds of the room if it goes negative.
This is all very simple after the fact but it took hours to figure out how to do this properly.
Did you like this post? Tell us
Leave a comment
Log in with your itch.io account to leave a comment.