20150707

Minimap

Today, I finished up some code from yesterday, simplified the painting algorithm, and added a minimap.

The painting algorithm was a little bit pathetic: at first, I only supported 3 brush sizes. Writing the painting algorith wsas kind of trivial for these three sizes: I told Unity which tiles should we overwrite. Yes, by hand. I know, I should kill myself. But today I re-discovered some older code (it was from the map generator I wrote for a tech-demo), which was a method to create hexagon rings (a hexagon ring, in this sense, consists of every tile that has the same distance from some origin). Now I just tell how many rings (of what sizes) do I want to make, and voilá, I can have as many brush sizes I want (I made buttons up until 6, I think that's more than enough).

For the minimap, I originally thought I would have a Texture2D, and update it at every painting event, but then I did a quick google search to see how others do it. Well, it turned out, creating a second camera is way more easier, and why-the-f***-didn't-I-think-of-it-OMG... So I made a second camera, and I'm dynamically changing it's viewport size as the map gets bigger. For this, I used a bounding rectangle calculator method, which I wrote earlier today - it simply calculates every added hex's coordinates, and updates the min and max variables accordingly. It doesn't update when erasing, though - that would be a little more resource-heavy. But if you completely erase the map, it will reset to default. Hmm....probably I should have a Clear button for that...

Also, I have noticed that the tile outlines are kind of visible in the minimap. This gave me the idea to make a layer for a rectangle encompassing the area the user can see, and it would be only visible to the minimap, and then place the outlines to a different layer, which would be only visible to the main camera. Also, clicking in the minimap should reposition the main camera - I think I can read the coordinates from the minimap's camera, and set the main camera to that position. But this is not a priority right now.


No comments:

Post a Comment