Game Development

Blog 718: Fun With Fog o’ War (and More)

So many features, so little time. I said I would build 34 features into my game in three weeks over the festive break; it is now three months later.

But what features! I might have had to unwind a couple of stinkers along the way, but I’m fairly sure the epic combination of fog o’ war and a minimap more than make up for it.

Progress Report

A. Level Generation: 8/8

I finally did it. I added decorations — shelves! And a couple of pipe props.

The important thing is that there is now a system in place to line decorations up along certain walls, completing feature A8 and finally closing off this category. Now I need to think about free-standing decorations that will divide up the empty chambers, but they should be much easier to slot in now I have the systems in place.

Having said that, although I might have added and removed some of my named features, the level generator continues to be a source of headaches and I did have to spend a good two weeks re-writing both sides of it to get to this stage. I think we’re there now, though. I think the architecture is finally sustainable for the future.

B. Level Navigation: 2/2 + 1

I WAS RIGHT! I poked around the internet and my intended approach to fog of war was absolutely the same as everyone else’s: draw lines out from the player’s position on the coarse level tile grid and reveal every tile until you hit a wall or the end of the vision radius.

Although my main aim was to build a minimap (feature L2), I did fog of war (bonus feature!) first because it required less fiddling with the user interface and I knew the same code would apply to both anyway. In this case, I paint the fog overlay as a single black bitmap with one pixel equal to one tile, then stretch it across the entire level. As the player traverses the world, tiles that they can see have their pixels turned transparent, revealing the level underneath — since the fog texture is scaled up, the black pixels fade into the transparent pixels naturally from the stretching so I don’t even have to build my own soft edges.

The minimap uses identical code but does the opposite — its bitmap starts transparent, with floors turning black and walls white to paint an outline of the map as you go. Rotate that to match the level orientation, shift it about a bit so the player’s yellow cell is always in the centre and the job is done. Phew!

Isn’t it beautiful?

There was one awful performance issue in the beginning that had me feeling squiffy for a bit, in that the first draft of the system took the frame-rate down to stupid levels. Turns out it wasn’t any flaw in my algorithm, more that I was calling Apply() on my texture far too often. Once you have updated the colours of some pixels you need to call this to make it real (presumably this function fires it off to the graphics card?), but you only need to call it once after you’ve done everything… not after setting every individual pixel. Ahem.

In other news, I’ve abandoned the wall occlusion system entirely (feature L1). I tried to improve it using some of the line-of-sight systems developed for the fog of war, but it just became annoying for a different suite of edge cases. I’ve decided it just isn’t worth the effort, especially since I’ll eventually move to hand-crafted levels that won’t have convenient modular tiles that can be shown and hidden on demand. No, the real answer is much simpler: keep the walls low or broken enough that things are never hidden behind them at all!

C. Item Systems: 4/4

D. Ability Systems: 2/2

E. Power-Ups: 3/3

F. Neutral Passive: 0/3

G. Enemies: 5/5 + 1

H. Traps: 0/4

I. User Interface: 3/3 + 2

I finally added status feedback messages to the bottom half of the screen. These will relay basic information about abilities being in cooldown, how much gold or ammunition you just picked up, and so on. Basic stuff but it’s another of those features that makes it feel less like a janky tech demo and more like a real game. (Also more like Nox.)


So that’s 27 + 4 features out of 34 + 4, leaving 7 to go before I can close off this planned development nonsense and go back to freewheeling. Traps and neutral units are the only feature categories that remain untouched — what new fun shall they unleash? (Yes, I haven’t forgotten, feature H4 is a Towers of Hanoi puzzle. Har har har.)

And you tell me...

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

You are commenting using your 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 )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.