Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Explosions

This thread is locked; no one can reply to it. rss feed Print
Explosions
kdevil
Member #1,075
March 2001
avatar

Alright, I asked about this a couple months back, and I got a few replies, but I am still in need of the killer explosion. What I'm looking for here is how the frick to make a very cool-looking explosion that would be able to fill, say, half the screen when a boss goes kablooey.

Some sample code or a link to a good explosion generator would be much appreciated, except that I CAN'T UNDERSTAND 'EGG' SCRIPTS AND MKEXPL DOESN'T WORK. Help help help help help help thank you.

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Matt Smith
Member #783
November 2000

about six months ago I came up with a great plan involving a video camera and a bucket of petrol. . . but nobody tried it ::)

So the second best way would be to have about 100 fireballs all starting in one place, but with different random vectors so they 'explode' away.

The fireballs can be simple sprites, but you can animate them and make them translucent if you want.

23yrold3yrold
Member #1,134
March 2001
avatar

Just go apesh*t on the SFX. Big animated explosions sprites, particle engine, smoke FX .... All at the same time. Blow the player's mind!

--
Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Zaphos
Member #1,468
August 2001

Have you looked at the fire generating sample that comes in the allegro examples. I bet that, if you could center that flame loosely at a point and make it spread out in a circle from there it would look pretty cool. Don't know how I'd do that, though.

Yes, you could always draw huge transparent explosion animations and play them, but that seems a little ... wasteful.

You do want 2D, right. Good.

There's nothing wrong with the old expanding transparent layered-colorwise fire-colored rings, centered where the exlosion is and moving outwards.

Sorry for the lack of actual sample code, but I thought it might help just to give some methods, seeing as I have no sample code for that right now.

Zaphos
Member #1,468
August 2001

This is a bit messy, sorry, but here is an example of the circle explosion method. It isn't great, but it might look better if you had a routine for making the circles look more like fire, probably do-able with the do_circle command (see the docs, drawing primitives). I apologize for the length and messy coding, I wrote this very quickly:
#include "allegro.h"
int main()
{
allegro_init();
install_keyboard(); /* to use keyboard */
if (set_gfx_mode(GFX_SAFE,800,600,0,0)!=0){
set_gfx_mode(GFX_TEXT,0,0,0,0);
allegro_message("Unable to set basic graphic mode\n%s\n", allegro_error);
return 1;
}
BITMAP *backbuffer;
backbuffer = create_bitmap(SCREEN_W,SCREEN_H);
// number of flames
#define flamenum 10
int i=0;
// radius of each flame
int r[flamenum];
for (i=0;i<flamenum;i++)
{
r[i] = rand() % 3;
}
// size of each flame
int size[flamenum];
for (i=0;i<flamenum;i++)
{
size[i] = 4+ rand() % 30;
}
// speed of radius increase per flame
int speed[flamenum];
for (i=0;i<flamenum;i++)
{
speed[i] = 4+ rand() % flamenum;
}
// has the flame died yet
int exists[flamenum];
for (i=0;i<flamenum;i++)
{
exists[i] = 1;
}
// this here so that you don't miss the start because the computer is still setting res
textout(screen,font,"press key to continue",1,1,makecol(255,255,255));
readkey();
for (;; )
{
if (key[KEY_ESC]) break;
textout(backbuffer,font,"press escape to quit",1,1,makecol(255,255,255));
for (i = 0; i<flamenum; i++)
{
if (exists[i])
{
for (int q=0; q<size[i]; q++)
{
circle(backbuffer,SCREEN_W/2,SCREEN_H/2,r[i]+size[i]-q,makecol(255-5*q,0,q/2));
}
r[i]+=speed[i];
if (r[i] > SCREEN_H/2) size[i]--;
if (size[i] < 2) exists[i]=0;
}
}
blit(backbuffer,screen,0,0,0,0,SCREEN_W,SCREEN_H);
clear(backbuffer);
}
return 0;
}
END_OF_MAIN();

Zaphos
Member #1,468
August 2001

Oops, sorry, posted twice.

[ August 27, 2001: Message edited by: Zaphos ]

kdevil
Member #1,075
March 2001
avatar

I appreciate the source code, but I've just found a file called GUI4EGG, which makes the whole EGG script thing a lot easier to do. Granted, I had to update my 3.12 allegro to the latest WIP to get the thing to install, but I think it'll be worth the trouble. Thanks for all your help guys :) .

-----
"I am the Black Mage! I casts the spells that makes the peoples fall down!"

Johnny13
Member #805
October 2000
avatar

a tunnel?

Alg3D Praise my Games!!<code>#define SPAMMER (post>=666&&postperday>=6)</code><Mr.spellcaster>What post? <Mr.spellcaster>A useful post by me.

madkatt
Member #634
September 2000

Nice routine zaphos.
Johnny13:not a tunnel but a visual representation of shockwaves generated by an explosion

Bruce Perry
Member #270
April 2000

I created a nice-looking particle explosion for Set Up Us The Bomb !!!, our entry into The Allegro Team Competition. I somehow managed to splat most of the makefiles just before release , so you can compile it with the following:
gcc -O2 -ffast-math -fomit-frame-pointer -funroll-loops -Wall -Isrc -Iinclude src/*.c -o setupus.exe -ljgmod -lalleg
(If your font is anything like mine, make sure you get the eyes and ells right )
Look at s_exps.c and s_expp.c. Below I explain how it works, but note that this effect is only viable in a paletted mode (i.e. 256 colours). The same effect in true colour would involve intermediate bitmaps and extra blitting, and would be far too slow. Never let anyone tell you that 8-bit graphics is old news
s_exps.c controls the source of the explosion. The source exists for a set time and emits particles during that time. More particles are emitted initially, and the rate of emission drops as the source's time runs out.
s_expp.c controls each explosion particle. The particles are initiated at the source and move out in random directions. As they move out, they slow down as if opposed by a force proportional in magnitude to the square of the speed. The rather complex-looking code for initialising the velocities is a system for choosing a random point in a sphere with uniform spatial distribution (i.e. the average concentration of points doesn't vary from place to place).
Explosion particles are also given a life value, which is decremented. When it reaches 0, the explosion particle is removed. They fade out.
Now for the interesting bit - the colour map. First, you will have to design your palette so that colours 240 to 255 are the only colours used by the explosion particle (besides 0 = transparency), and these colours are not used by any other graphics (except other fire effects). 240 to 255 are a gradient ranging from dark brown (not black) to white. Look at the palette in our datafile (data/bomb.dat) for an example.
Even though the explosion colours are 240 to 255, the sprites will use colours 0 to 15. IMPORTANT: if your sprites use any colour greater than 15, memory overruns will occur. Do not let this happen.
Now we need a colour map. The colour map is set up so that:
1. Colour 0 is drawn transparently (no change to the destination bitmap).
2. When drawn over colours 0 to 239, the sprite is drawn opaquely.
3. When drawn over colours 240 to 255, the sprite is drawn additively, clipping at 255.
The result is a blended explosion with a sharp outline.
Note that we do not use complete colour maps. We actually only use the first [16][256] cells, instead of the full [256][256]. Thus we use a 16th of the memory, which enables most modern processors to run faster (a limited amount of memory can be stored inside the processor for fast access).
Finally, we don't just use the one colour map. We use sixteen. Before the sprite is drawn, a certain amount is subtracted from its colours, and any that go <= 0 will not be drawn. This enables us to fade our particles out in 16 steps.
generate_explosion_colours() from s_expp.c will create this array of colour maps, and draw_expp shows how it must be used.
The explosion implemented in Set Up Us The Bomb is 3D. Explosion particles slow down according to the laws of air resistance - so all three coordinates are factored into the equation for reducing any one when slowing down. Therefore, reducing the formulae to 2D would probably result in an explosion with little life in the centre. Instead, I suggest you keep all three coordinates going but only use two of them for plotting to the screen.
As a final note, I don't mind if you want to use our explosion particles and/or our colour gradient. They are in the datafile, and simply need exporting. However, please credit us for this method if you decide to use it
[ August 28, 2001: Message edited by: bdavis ]

--
Bruce "entheh" Perry [ Web site | DUMB | Set Up Us The Bomb !!! | Balls ]
Programming should be fun. That's why I hate C and C++.
The brxybrytl has you.

Bruce Perry
Member #270
April 2000

Go to: