Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » explosions code WANTED

Credits go to anto80 and Inphernic for helping out!
This thread is locked; no one can reply to it. rss feed Print
explosions code WANTED
William Labbett
Member #4,486
March 2004
avatar

hi chaps

i'm hoping someone out there has got some simple code using allegro functions for doing explosions.

I just want it for the opening of my game - lots of explosions then the game's opening picture fading through.

I will include thanks to the person in the credits of my game, but there'll be no other reward - my game'll be freeware anyway!

Thanks for any help.

Inphernic
Member #1,111
March 2001

Either use an explosion animation or particles. Or both. The code itself is trivial, so why not have a shot at it yourself? You'll learn better that way, too.

anto80
Member #3,230
February 2003
avatar

What do you mean by explosion?

IHMO i can see 2 types of 'explosion'
1) particle-like explosions

1typedef struct Particle{
2 float x, y; // instant pos
3 float dx, dy; // instant vector
4 float ay; // acceleration (gravity)
5}Particle;
6 
7void move_particle(Particle* p){
8 p->x += p->dx;
9 p->y += p->dy;
10 p->dy += p->ay;
11}
12 
13void spawn_particles(ParticleList* pl, int n, float x, float y){
14 int i;
15 Particle p;
16 for(i=0; i<n; i++){
17 p.set(x + 10.0*cos(i*2*M_PI/n), // x
18 y + 10.0*sin(i*2*M_PI/n), // y
19 1.0*cos(i*2*M_PI/n), // dx
20 1.0*sin(i*2*M_PI/n), // dy
21 0.8); // ay
22 pl->addParticle(&p);
23 }
24}

2) sprite explosions
Create a dozen of explosion sprite to do an animation.
Display them in this order.
If you want it to look more like a real explosion, use transparency.
If you want it to look even more like a real explosion, use smoke (for example smoke sprites, like your explosion sprites).
If you want it to look further more like a real explosion, combine this with particles (1).

That's what i do.
I hope it helps.

[edit]damn!! Inphernic beat me !! :P

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

A J
Member #3,025
December 2002
avatar

do some particles, with trails (x-fade the previous screen with the current one).
or just get a FLIC of an explosion and play that.

___________________________
The more you talk, the more AJ is right. - ML

William Labbett
Member #4,486
March 2004
avatar

big Thank-you to Anto80

anto80
Member #3,230
February 2003
avatar

You're welcome!!

It's very kind of you to give my name in your credits, but i can't accept because as Inphernic said, the code is so trivial we can't tell it belongs to anyone...

Thanks anyway.

If you still want to put my name on it, i wouldn't say no! ;D

And please tell us about your project revision, so that we can see the result of these great particles! 8-)

___________
Currently working on his action/puzzle game CIPHER PUSHER : Blocks/Vortexes/Seafood! Facebook - Twitter - webpage

OICW
Member #4,069
November 2003
avatar

The good particle explosion system is in demo.c I think it pregenerates some number of frames of an explosion using particles and then it draws it on screen when needed.

[My website][CppReference][Pixelate][Allegators worldwide][Who's online]
"Final Fantasy XIV, I feel that anything I could say will be repeating myself, so I'm just gonna express my feelings with a strangled noise from the back of my throat. Graaarghhhh..." - Yahtzee
"Uhm... this is a.cc. Did you honestly think this thread WOULDN'T be derailed and ruined?" - BAF
"You can discuss it, you can dislike it, you can disagree with it, but that's all what you can do with it"

ReyBrujo
Moderator
January 2001
avatar

Shawn wrote EGG, a program to prerender explosions. You should check it out.

--
RB
光子「あたしただ…奪う側に回ろうと思っただけよ」
Mitsuko's last words, Battle Royale

Avenger
Member #4,550
April 2004

EGG was not only for explosions, but other particle related things too (Spaceship engine, sparks, etc.)

Go to: