import java.awt.*; import com.genuts.gameui.*; /** * An exploding ball wrapper.
* Change the animation of an animation, and removes itself from * its parent playfield at the end of the second animation sequence. */ public class ExplosionWrapper extends SpriteWrapper { /** * Elements of the second animation. */ private Image anim2; private int nbh2, nbv2, fr2; /** * Initializes the animated sprite with 2 animated sequences. */ public ExplosionWrapper(AnimatedSprite sprite, Image anim2, int nbh2, int nbv2, int fr2) { super(sprite); this.anim2 = anim2; this.nbh2 = nbh2; this.nbv2 = nbv2; this.fr2 = fr2; } /** * Receives the event that this sprite is collision * with another sprite * @param s Sprite with which the collision is */ protected void collisionWith(Sprite s) { if (s != null) { setBackgroundSprite(true); int oldWidth = getWidth(); int oldHeight = getHeight(); ((AnimatedSprite) getActionSprite()).setSequence(anim2, nbh2, nbv2); ((AnimatedSprite) getActionSprite()).setFrequence(fr2); ((AnimatedSprite) getActionSprite()).setCurrentPictureNumber(0); ((AnimatedSprite) getActionSprite()).setSequenceLoop(false); setPosition(getX()+(oldWidth/2 - getWidth()/2), getY()+(oldHeight/2 - getHeight()/2)); } super.collisionWith(s); } /** * Propagations of the tick event to the action event * if it is an instance of Tickable.
* Checks if the actionSprite has ended is sequenceLoop * to remove the sprite from its parent playfield. */ public void tick(int ticks) { PlayField parent = getParent(); if ((parent != null) && ((AnimatedSprite) getActionSprite()).isSequenceEnded()) { parent.removeSprite(getFinalWrapper()); } super.tick(ticks); } }