Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2002 Bolton Institute Explosions Andrew Williams

Similar presentations


Presentation on theme: "Copyright © 2002 Bolton Institute Explosions Andrew Williams"— Presentation transcript:

1 Copyright © 2002 Bolton Institute Explosions Andrew Williams http://www.bolton.ac.uk/staff/adw1

2 Copyright © 2002 Bolton Institute Explosions Explosions are hard to do properly –Specifically, it is hard to get rid of the sprite once the explosion animation is done One of the advantages of the AWSprite classes is their simplicity –Sprites are autonomous But this makes it hard to make them do one thing and then do something else

3 Copyright © 2002 Bolton Institute Explosions Explosions are an example of making a sprite do one thing and then do something else –We want to show an animation sequence –Then we want the sprite to disappear, without any further intervention from us AWSprites “want” to be told what to do and then to be left alone to do it –In general, it’s hard to capture the moment when they stop doing something

4 Copyright © 2002 Bolton Institute set_auto_destruct(..) This function tells the sprite to: 1.Animate through a sequence of frames one or more times 2.Disappear after the sequence is over Once started, the auto-destruct sequence cannot be countermanded!! –This is not Star Trek!!

5 Copyright © 2002 Bolton Institute set_auto_destruct(..) The function is a bit like setting an animation subset and an automatic animation set_auto_destruct(1, 12, 60); Animate frames 1 to 12, with a new frame every 60 milliseconds Once the animation is over, make the sprite invisible

6 Copyright © 2002 Bolton Institute set_auto_destruct(..) set_auto_destruct(7, 12, 90, 3); Animate frames 7 to 12 three times, with a new frame every 90 milliseconds Once the animation is over, make the sprite disappear

7 Copyright © 2002 Bolton Institute Using Auto-Destruct There are two approaches: 1.Incorporate the explosion frames in the sprite that is going to explode 2.Have a separate explosion sprite, which is substituted in at the point of explosion For rather complex reasons, 2 is slightly simpler

8 Copyright © 2002 Bolton Institute 1. Incorporated // Load in the rocket AWSprite *rocket; rocket = new AWSprite(“rocket.bmp”, 14); rocket->set_animation_subset(1,2); rocket->set_auto_animate(120); etc etc etc.. // Explode the rocket rocket->set_auto_destruct(3, 14, 100);

9 Copyright © 2002 Bolton Institute 1. Incorporated (problems) Problem is that this clears the animation stack, which means that if you want to use the sprite again, you must tell it an animation subset: rocket->set_animation_subset(1, 2); It’s a small point, but one you must be aware of

10 Copyright © 2002 Bolton Institute 2. Separate Explosion rocket.bmp explode.bmp

11 Copyright © 2002 Bolton Institute 2. Separate Explosion // Load in the rocket and explosion sprites AWSprite *rocket = new AWSprite(“rocket.bmp”, 2); rocket->set_animation_subset(1,2); rocket->set_auto_animate(120); AWSprite* explosion = new AWSprite(“explode.bmp”, 12); explosion->make_invisible();.. // The rocket is hit rocket->make_invisible(); explosion->set_world_position(rocket->get_x(), rocket->get_y()); explosion->set_auto_destruct(3, 14, 100);.. explosion->update_everything(); // Don’t forget!!

12 Copyright © 2002 Bolton Institute 3. Separate Explosion (magazine) For multiple explosions: AWMagazine *explosions = new AWMagazine(5, “explosion.bmp”, 12);.. rocket->make_invisible(); exp = explosions->allocate_a_bullet(); if(exp != NULL) { exp->set_auto_destruct(1, 12, 90); exp->set_world_position(rocket->get_x(), rocket->get_y()); }.. explosions->update_everything(); // Don’t forget


Download ppt "Copyright © 2002 Bolton Institute Explosions Andrew Williams"

Similar presentations


Ads by Google