top of page

Internship - Week 4 - Road generator

Hey there,

This week we will continue working on the road generator. Last week we had a couple problems that remained. one of these problems is that the algorithm creates some small road connections. these roads do not leave enough space for the creation of a building. This means the code that tries to find a suitable place to connect the road to, is not working correctly. This is what we will try to fix this week.

First we will have a look at how the old code worked. After this we will look at the changes that were made and how the code works now.

This image shows the old search pattern. It searches diagonally from bottom-left to top-right. The algorithm only stops when it finds a road it can connect to or when it runs out of tiles to search. When it encounters a road tile, it will calculate the distance from the start point and combine the x and y of the calculated distance. If this combined value is bigger than the minimum road length, the road can be connected to the current tile.

In this image you can see two of the problems the old version of the generator was having.

On the left, it creates a connection that leaves no space between the roads in the horizontal direction. We do not want to connect to this road, but because the combined size(x + y of the light blue road) is bigger than the minimum road length, the algorithm will create the connection.

On the right, it creates a connection that leaves enough horizontal space but now it leaves too little vertical space to create a building. This means we have problems with both the horizontal and vertical directions of the connection.

From our analyzation of the problems we can conclude that adding the x and y together to form the combined size, is creating the problems. We should try to keep these values separate and check if both are bigger than the minimum road length. This means we should change the code from "if(combined size > minimum length)" to "if(x > minimum length && y > minimum length)". This will make sure that the connection is big enough in both the horizontal and vertical direction.

As you can see in the image, checking the connection length is not the only thing I changed. The search pattern underwent some changes aswell. It used to have a diagonal pattern but I changed it to have a simple horizontal pattern. creating the diagonal pattern was more complicated in code and did not add any kind of significant improvement in comparison to the horizontal pattern. For the sake of simplicity in the code, I changed it to the horizontal pattern


Featured Posts
Recent Posts
Archive
Search By Tags
No tags yet.
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square

Lars Temmink

Game Programmming Portfolio

bottom of page