Session was a total loss. Do not read: Still working on letting the Princess get out of room one. After creating doorway-hallways as rooms, we’re getting close.

Andrew Travis provided a notion that has improved things. Now there are full-fledged rooms connecting the original rooms in the dungeon. These new rooms amount to hallways, sometimes very short, between the normal larger rooms.

There is a small but fundamental issue that has made the problem of moving between rooms more difficult: walls. Yes, walls make it difficult to move between rooms. Who knew?

The rooms in our dungeon program are simple rectangles. I felt we should show them with walls around the outside (where else would a room wall go?) so they look like this:


The greyish line around the outside of each room is a visual wall. It also acts like a wall, and the princess can’t step into it:

against wall

But if she goes to a door, we’d like her to be able to walk right to, and past, the edge of the current room, and into the next. The next will be one of our new hallway rooms, of course. For this to look right, we’ll need to do something graphically to make the doorway look open compared to a wall.

But for it to work right, we have to allow the avatar, while inside a given room, to walk past where the wall would normally stop her, if and only if she’s at a doorway.

One alternative

One alternative would be to let her walk right up to the edge of a room, kind of into the wall, and then stop her. That would make transition to the next room easier. Suppose she’s right on the edge of room 1, and lined up with a hallway, room 20. Then she tries to move forward. That would set her coordinate outside room 1, and if she were not in a doorway, she’d just be put back and would seem not to move.

But when we check the legality of a move, we first check the adjacent rooms, if any. In this case we check room 20, to see if she is inside its bounds. She is, so we set her room position to the edge of room 20. She can now proceed to explore room 20.


However, if we keep her from going all the way to the edge, so that she doesn’t appear to walk into the walls, when she tries to enter the room 20 hallway, her attempt is illegal in room 1 … and does not reach into room 20, so it can’t accept her.

And therefore …

When I started this article a few minutes ago, I was planning to make hallways have a logical extension overlapping the rooms they connect, so that a few pixels inside the room would also be pixels in the hallway. Then everything would work just fine.

I didn’t think that would be too difficult. We’ve begun to more to doing these checks simply by asking if a given point is inside a given rectangle, so with that in place, if a hallway room just reported a rectangle that was, I don’t know, 5, 6, or 7 pixels longer than the hallway, the hallway would receive the avatar before she ever got to the wall.

But what seems simpler to me is just to let her walk all the way to the edge. Then her next move will take her into the hallway, if she’s near one, and we don’t have to have any special handling (yet) for hallways.

This is the elegance of Andrew’s idea of turning doorways into rooms. Well done, Andrew.

Hours pass …

I’m thrashing. I’m going to revert and wind this article back to the beginning.

It’s not even worth it taking you through all the thrashing. Today, so far (it’s only about 1230) I’ve accomplished nothing but to confuse myself. The core issue is a tiny change to the legalMoveTo method:

function Room:legalMoveTo(aRoomPosition)
    for i,room in ipairs(self.neighbors) do
        local stop, position = room:contains(aRoomPosition)
        if stop then 
            return position
    return self:stayInRoom(aRoomPosition)

This, plus the implementation underneath it, is intended to detect, in the upper loop, whether any of the neighbors to the current room accept the provided RoomPosition (the position of the avatar). If they do, the loop is to stop, and the returned position is used. It’s supposed to be the position of the player now in the neighboring room.

I’ve spent hours printing, and then hours trying to get a test that shows the problem. I actually did get a test to fail but by then I was so confused that I trashed it and reverted.

I’ve got a copy of it, so when I return, I might reuse it, or create a new one. But this session is a total loss.

It happens. If I weren’t writing “warts and all”, I’d skip telling you this, and look smarter later. As it is, no. Some days you wipe out. I’ll talk more about that next time.

For now, I think I need a turkey sandwich.