package code.kalter.longflight.game.explosion; import code.kalter.longflight.Animation; import code.kalter.longflight.Loader; import java.io.IOException; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; /** * Не приблежаться, рванёт! * * @author KalterFive */ public class Explosion implements Detonator { public static Explosion createExplosion(String path) throws IOException { final Loader loader = Loader.getInstance(); final Image image = loader.getImage(path); return createExplosion(image); } public static Explosion createExplosion(Image image) { return new Explosion(image); } private static final int MAX = 5; private final Animation[] boom; private final int[] positionX; private final int[] positionY; // каждый кадр должен быть квадратным private Explosion(Image explosion) { boom = new Animation[MAX]; positionX = new int[MAX]; positionY = new int[MAX]; for (int i = 0; i < MAX; i++) { boom[i] = Animation.createAnimation(explosion, explosion.getHeight(), 80); } } public void deactivateAll() { for (int i = 0; i < boom.length; i++) { boom[i].stop(); } } public void activate(int x, int y) { for (int i = 0; i < boom.length; i++) { if (!boom[i].getState()) { boom[i].start(); this.positionX[i] = x; this.positionY[i] = y; break; } } } public void paint(Graphics graphics) { for (int i = 0; i < boom.length; i++) { boom[i].paint(graphics, positionX[i], positionY[i]); } } public void update() { for (int i = 0; i < boom.length; i++) { boom[i].next(); } } }