Friday, 8 March 2013

Starts, Ends and Wall Hugging

Although the pictures from my last post looked acceptable there were some issues that would take several generations of the dungeon to see clearly.
  • Wall Hugging.
  • No clear start or end.
  • Redrawing of rooms.
Wall hugging -

You may be able to notice in the last picture i posted that the dungeon will hit a wall and stick to it, this is because once the dungeon hits a wall it will have an equal chance to move away from the wall as it does to attempt to move into the wall. I fixed this issue with a small if statement that changes the values of Yvar (the variable that effects the probability for the next room to move up or down). If the Y value is equal to gridSize or 0 then Yvar will change from 50 to 25 or 75, reducing the probability to move in the same direction. This fix is far from perfect but it does the job for the time being and produces some interesting looking dungeons.

No clear start or end -

Visibly determining whether a room is the start or end would be difficult, however as far as my script is concerned there isn't one. This may not seem like a problem right now, and that's because it's not, but when it comes to implementing other features such as; a stash at the start of every dungeon, making sure there are no enemies in the first room or have some kind of entrance door, I would like to know which room is the start and which is the end.

To do this I used an integer variable that increments every time a new room co-ordinate is decided (roomCount). From this I know the index of the array that contain the last room's co-ordinates. I then used two if statements "if(arrayPosition == 0)" and "if(arrayPosition == roomCount)". Finally to make these rooms visibly noticeable i changed their colours.

Redrawing of rooms -

This is the biggest of the 3 problems in my opinion, from the pictures it is impossible to see this but from the code you can clearly see how this is possible. Currently if a new room has been placed by incrementing Y there is nothing saying that the next room to be placed will be on a decrement of Y, this gives the dungeon the opportunity to continuously move up and down along the Y axis and never progress along the X. This causes increased loading times and lower FPS during gameplay.

Although this is the biggest issue it isn't that difficult to fix. I introduced some Boolean variables; moveEast, moveNorth, moveSouth. My aim is to check these variables when deciding where a room shall be placed. When a room moves North (incrementing Y) moveNorth will be set to true, if moveNorth is true, a room cannot be placed by decrementing Y (moveSouth), when the room is placed by incrementing X (moveEast) both moveNorth and moveSouth will be set to false allowing the possibility for the path to move North or South again.

Here's the end result of these fixes :)

No comments:

Post a Comment