Graham Long

Posted on

# Generating a test map

The first thing I did for this development was to generate a test map, I created 4 new simple tiles in blender:

1. One with a straight path running through it
2. One with a T Junction path
4. One which had a 90° Corner path

I then mocked up a simple map in Paint, see below:

And then updated the existing .VTF files and created the necessary new ones to bring this level to life in my game.

It immediately became apparent that to do this I would need to be able to rotate the base tile model, so I added a new line to the .vtf files, the new line used `BR` (Base Rotation) tags and had the possible values:

• `None` - No rotation
• `Left` - 90° Rotation Left
• `Right` - 90° Rotation Right
• `Flip` - 180° Rotation

I then needed to pass this to the Tile class and parse it to apply the correct rotation to the model.

Once this was done, The test map was recreated as expected in the game and I could walk around from one end to the next and back again.

# Dealing with Diagonal movement between tiles

This was an outstanding issue from the Last development and was only a slight change compared to the already implemented single direction movements.
I started by calculating where the players trajectory would intersect both of the edges that the player crosses.

Then I calculated the distance from the start position to each of the intersection points.

Whichever point is the closest is the point that the player leaves the current tile, special consideration must be given to when the player leaves the tile at one of the corners i.e. when the intersection distance is equal for both edges, knowing this we can set the intersection point and adjust the tile accordingly.

The Calculations for each of the 3 possibilities is nearly identical so I shall just show one:

The intersection point is selected based on which point is closest and the next tile and offset are then set based on which way the tile map is shifting.

Finally, the `currentTile` is adjusted the same way as in the previous development.

After a short period playing the demo map I soon grew tired of the look of the paths, and set all the tiles to have the grass base model.

I then decided to add the ability to add models to each of the tiles, to do this I needed to specify the following in the .vtf files:

1. The object to place on the map.
2. The position of the object relative to the tile.
3. The rotation of the object (only Y axis rotation for now).

The easiest way to implement this for now was on a single line, starting with a `GO` (Game Object) tag, followed by the x offset, y offset, z offset, rotation and a final closing `GO` tag.

I created two models to test this out, a new rock model and a tree model which I extracted from the previous tree base model.

Next I updated the `VrTileFormatParser` class to parse the Game Object definitions and pass them onto the generated tile class as an `ArrayList` called `gameObjects`.

Parsing the GO tags was slightly more involved than the other tags as there are multiple information points on the single line, but this is no more complicated than parsing the obj files.

Finally I needed to process the game object data in the `Tile` class, in the `initialise` method I added a loop to go through all the `Triple`s passed into the class and create/modify objects based on their values.

# Conclusions

This seems to work pretty well, I have one tile with a few trees and rocks dotted across it and it looks pretty cool so far, it does remain to be seen if there are any performance issues with this but that can be looked at in future.

One final thing, As this platform (dev.to) doesn't seem to have any other game development logs on it, I am going to move this one to somewhere more appropriate, when I decide where this will be I shall update this post with details.