Day 5


Day 5 was better. I had a bit more time today in the evening and even managed to stay mostly on task from my feature list.

I started out by adding two arrays for tracking map data, one for Map Tiles and another for visibility information. I'm using linear arrays with a simple x/y to index calculation. The map tiles array-of-structs keeps information about the tile's type, its glyph,  colour and wether it is a blocking tile or not. This allows me to have any number of different visual styles for tile types. I then defined some basic tile instances for things like grass, trees and rocks. These static 'templates' are used in the copy constructor of the structs in the array. Not really complicated, just a choice. The visibility data only holds if the tile was explored, and is visible.

The Fog of War system right now is REALLY simple. Like, dead simple. Every frame the game loops through the visible array and sets them to all !visible. Then it loops through all the entities calling a function called 'RevealNearPosition'. This simply takes a position and a radius and then does an iteration on the x/y box bounded by +/- radius, testing for the squared distance against the squared radius. Why squared? To avoid the square root on the magnitude, that's all. I'm not optimizing the algorithm but I couldn't bring myself to use the magnitude of the vector. I'm not a savage. Anyway... there are a lot of ways to improve this but for now it 'works'.

After getting the Fog of War going I had a bit more time and really wanted to play with making the map. I spent about 10 minutes looking for some good resources on procedurally generating a 2D ascii map. All I could find was overwhelming search results on how to construct a rogue-like dungeon, which wasn't what I wanted at all. Then I remembered that I didn't really care about the ascii part, just 2D terrain generation. This led me down a rabbit hole for a few more minutes before I had to pull myself away. I'm not making a proc-gen masterpiece here, just something that works! So... I went simple.

The map has a river. The river goes from left to right. Conveniently I double loop over the map coordinates with the outer loop being x. This means that the inner loop is building the map column by column. The river starts at map height divide by 2, and is 4 tiles tall. Every frame the code tests a random chance to offset the river up or down by one tile. It also test a random chance to grow or shrink the river size by 1 tile. These two allow the river to 'wander' a bit. 

The river has bridges. There are between 1 and 4 of them. The code then simply divides the map into num_bridges + 1 regions, and when creating the river it checks if the region is a 'bridge'. If it is, then it becomes a bridge instead of a river.

That's it! As simple as it is though, it already makes for a more interesting map than the empty random field of trees, grass and boulders. Plus, it fits with my plan to have 2 teams fighting it out. Rivers are fun! They create choke points. They divide the land!

Anyway, more tomorrow. Probably pathfinding. Maybe buildings creating units. Maybe units wandering around... we'll see.

Leave a comment

Log in with itch.io to leave a comment.