Fire Tutorial
Describes a fire technique using palette animation.
First thing we need to do is set up two arrays. The size of the arrays depends on the many things: screen mode, speed of computer etc. It's not really important, just that they should both be the same size... I'll use 320x200 (64000 byte) arrays for this text, because that happens to be the size needed for using a whole screen in VGA mode 13h.
The next thing we need to do is set a gradient palette, this can be smoothly gradiated through ANY colours, but for the purpose of this text let's assume the maximum value is a white/yellow and the bottom value is black, and it grades through red in the middle.
Ok, we have two arrays, lets call them startbuffer and screenbuffer, so we know whats going on. Firstly, we need to setup an initial value for the start buffer... so what we need is a random function, that returns a value between 0 and 199 (because our screen is 200 bytes wide) this will give us the initial values for our random "hotspots" so we do this as many times as we think is needed, and set all our bottom line values of the start buffer to the maximum colour value. (so we have the last 300 bytes of the start buffer set randomly with our maximum colour, usually if we use a full palette this would be 255 but it can be anything that is within our palette range.)
Ok, that's set the bottom line up.. so now we need to add the effect, for this we need to copy the start buffer, modify it and save it to the screenbuffer, we do this by averaging the pixels (this is in effect what each byte in our array represents) surrounding our target. It helps to think of these operations in X,Y co-ordinates. Lets try a little diagram for a single pixel.....
|---+---+---+---+---|[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]|---+---+---+---+---|
|0,0|0,1|0,2|0,3|0,4|[nbsp]etc...[nbsp][nbsp][nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|
|---+---+---+---+---|[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]|---+---+---+---+---|
|1,0|1,1|1,2|1,3|1,4|[nbsp]etc..[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|X,Y|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|
|---+---+---+---+---|[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]|---+---+---+---+---|
|2,0|2,1|2,2|2,3|2,4|[nbsp]etc..[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|[nbsp][nbsp][nbsp]|
|---+---+---+---+---|[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]|---+---+---+---+---|[/bquote][/color][/font]
- The fire stays on the bottom line....
- It's slow....
- The fire colours don't fade...
The second problem can be approached in a few ways.. first and easiest is to actually calculate less pixels in our averaging.. so instead of the 8 surrounding pixels we calculate for example, 2 pixels, the one above and the one below our target pixel (and divide by 2 instead of 8) this saves a lot of time, another approach is to use a screen mode, where you can set 4 pixels at a time, or set up the screen so that you can use smaller arrays (jare's original used something like 80X50 mode) which in effect reduces to 1/4 the number of pixels needed to be calculated.
The third problem is just a matter of decrementing the calculated value that we get after averaging by 1 (or whatever) and storing that value.
Last but not least, we need to think about what else can be done... well, you can try setting a different palette, you can also try setting the pixel value we calculated from to another place, so say, instead of calculating from one pixel below our target pixel, you use one pixel below and 3 to the right of our target... FUN! )
Related Tutorials
Procedural Generation of 2D Tile Maps in Games
The article explains how to build a procedural 2D cave map generator using cellular automata. It covers map representat…
Localizing A Game Into French — Which Variant Should You Choose?
So, you’re making an awesome indie game, and now you’re thinking about localizing it into French? Great idea! There ar…
How Long Does It Take To Localize An Indie Game?
So you’re planning on localizing your indie game, but you’re not sure how much time to schedule in. While the timing o…
Creating game videos: best practices and pitfalls to avoid
Game video production: practical tips on how to create a game trailer or teaser that you can be proud of. Give your aud…
Adopting CI/CD: How Midwinter Entertainment iterates at speed with the help of IMS
Game development was once like one long sprint: a huge effort until you reached the finish line — at which point you co…
GameDev.net
5 Things to Consider When Making a Video to Promote Your App or Game
How can you show an app or game in your video in a way that attracts new users? Let’s take a look at what to go by when…
Discussion
More from Phil Carlisle
Comparing Shadow Mapping Techniques with Shadow Explorer
New Incentives and a Whole New Platform From The Intel AppUp developer program
The final installment in this series on Intel's AppUp program details additional incentives and opportunities for devel…
The Game Maker
This book excerpt contains the first chapter of the book that introduces beginning game developers to the Game Maker pr…
Discussion