DEV Community

Graham Long
Graham Long

Posted on

Gamedevlog: Tilemap Part 3d

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
  3. One which had a crossroads
  4. One which had a 90° Corner path

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

Test map

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.

Parsing the base model rotation

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.

Two intersections

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

Distance calcs

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.

intersection calculation and offset

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

Setting the next tile

Adding to the map

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.

Game Object Definition in VTF file

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.

gameObjects ArrayList definition

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.

Parsing GO Tags

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 Triples passed into the class and create/modify objects based on their values.

Adding Game Objects to a tile

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.

Populated Tile

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.

Top comments (2)

Collapse
 
longevitysoftware profile image
Graham Long

Hi Robert, I haven’t moved the dev log yet but I am thinking of going to itch.io, I did a game jam on that platform and noticed they do dev logs as well.
As I haven’t moved yet, I can’t comment on what the platform is like for dev logs but it was good for the game jam submission, and it’s been good for downloading game assets.

Collapse
 
robertogongora profile image
Roberto Gongora

Hey man, I've been meaning to write a devlog here too, but I'm curious to know if you ever found a more proper platform for that?

Thanks and hope you're great!