My father often despairs at my career choices- I wanted to make a game that he'd understand and hopefully enjoy.
Right now it's really just an adaptation of my Tower Beefence code, but the experiment is teaching me about "random" expansion and subtler recursion than what I was taught at uni.
Fire's a tricky critter- it definitely follows some basic rules and is predictable in defined cases; we know how to hold a matchstick to have it grow or shrink. But in the bush your intelligence of the situation is imperfect, the rules are a little looser, and firefighters have to compensate for a certain degree of unpredictability. If fire in 'Backburn' moved on an obvious algorithm, it'd lose some of that character as a ravenous unpredictable monster.
So what does the algorithm look like? Well, loosely in pseudo-code-
- Test the ferocity of the fire- if ferocious enough, and with enough loose vegetation to throw around as embers- attempt to spread to adjacent tiles at random.
- Test the randomly selected tiles for 'resistance'- a combination of available fuel, altitude difference and favourable/unfavourable wind direction.
- Test ferocity against resistance, if successful, spread the fire. If unsuccessful, give up.
- Wait a random amount of time to try again!
So it's more of a random growth tempered by real-world limitations than a "correct" model with a random element introduced. A variation of this also defines the vegetation spread during terrain generation.
Given that I'm keeping track of the fire's ferocity, I'll use this to modify the fire particle effect- this still needs a lot of tweaking, but for now it does a good job of representing this variable visually.
For anyone having difficulty animating fire- particles or by-hand, there're some main rules I follow every time I'm drawing/animating fire-
- Fire is comprised of 'flame' and 'particles/embers' which should be modelled acting individually to the same forces. I consider smoke a separate effect, as fire doesn't always emit smoke, and smoke can come from embers with no fire present!
- Colour through time/space- white, through yellow, orange, into reds and maybe even purples. Think about colours of molten metal cooling. Particles/embers will tend to hold onto heat/colour a little better than individual sheets of flame that change colour and extinguish in just a few frames!
- Fire moves fastest where it's hottest- That means sheets of flame, particles/chunks of fuel, everything is whizzing upwards from the base of the fire before being cooled by the air and starting to slow down. Think of a big fan sitting under an origin point!
- At the base of the fire, everything's forced pretty directly upwards, but once the particles/flames escape that 'fan force', they can spread laterally and float around a little.
That's it for now, obviously there's a lot more to do- I'm hoping to have a player firefighting mechanic working in the next few days, but the way my progress with code moves in inspirational jumps and starts, who knows!
I'm mostly writing this for my own edification, but if there's anything here that folks would like to see more of, I'd love to hear about it! I can take a few moments to include some full-resolution assets or downloadable test-builds if folks would like? Leave a comment, or bug me on twitter!