Google+

Major Rework

Leave a comment

November 16, 2015 by jonmillymiles


Following the last stage of my project I identified a few concerns:

  • Some of the rooms overlap
  • The rooms overlap the tiles
  • When the rooms overlap we get glitching
  • There are no structured corridors – yes we need to raise this one now

So to begin to fix this we need to do a few things… we need to combine our room building algorithm into the Map blueprint rather than having them separate. By doing this:

  • Rooms will still overlap – more on this later
  • Rooms will be part of the same entity as the tiles and will not overlap
  • There will be no glitching of meshes, as only one mesh will be created
  • We will still have no corridors

As an added bonus, we will be preserving resources as there will only be a single tile created at a time.

So to begin – first I want to change our Map array in quite a deep way. I want to make it a structure. A structure is a name given to a collection of variables that mean something. In this instance I am going to assign three variables to each element:

  • Active – A Boolean value that says whether there is a tile there or not.
  • Type – An enumerated value (a list of words) that describes what the tile is – Empty/Corridor/Room
  • Colour – The colour of the tile

So to begin I created my Enumerated variable as so:

EnumThen I created my structure like so:

Struct

Then I replaced every instance of my simple array with the more complex one. I won’t put a picture up for each one that I changed, I’ll trust you to believe me. 🙂

This actually changes nothing at this point, we end up where we were before. But we have an important change we can now add variables into our map tiles that provide more information for our build engine. For example, we could add an additional Enum value “Door” so that a door object is placed on the tile. We could add a value for damage to each tile that can then be read and the mesh/material can be updated accordingly. So we have, by doing this, built in an incredible amount of scope for future development.

So getting on with the case in hand and integrating the room build. Firstly I need to move the simple room build mechanism into the the code for the map. I will create a separate function for this. Initially I will simply place down random rectangular rooms and later I’ll build in a routine for checking whether they overlap and separate them.

I also need a function that will allow me to set the value of a cell, that way as the rooms are generated I can update each tile properly. This function is simple enough and utilizes our formula from before:

Set Tile.fw

We now change our room generation script to include our code for generating the rooms. One alteration does need to be made which incorporates the random placing script from the Level Blueprint into the code within the function.

What I have found is that the map only creates a three rooms. On further examination I found the “Expose on Spawn” check box and this has allowed me to feed my random number of rooms directly into the map blueprint. Similarly there was an error in the room generation logic which started the initial For loop at 2 rather than 0. The output is now considerably more complex:

Now I need to stop the rooms from overlapping and to do this we simply “scan” the map first where we are going to place our room and if it is clear then we will build our room. We will include a one tile border too so that we can place doorways between at a later stage. What I will need to do though is turn off the random tile generator that I used to give some sense of space to the map as this will interfere with the tests.

Here is the code to check for overlaps, initially without the space around the room:

Overlap CheckThere was a problem with this too, there was still overlap. Looking at the code now the loops are not configured correctly and it moves on to the next stage of the code in the y loop and not the instigating X loop. So here is the correct code with the one square border:

Correct Overlap Check

And here is a video of the room generation working correctly.

So to review our problems:

  • Some of the rooms overlap – Fixed
  • The rooms overlap the tiles – Fixed
  • When the rooms overlap we get glitching – Fixed
  • There are no structured corridors – This is our next challenge!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog Stats

  • 10,074 hits

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 580 other followers

Archive

%d bloggers like this: