DEADSOFTWARE

License project under GNU GPL 3.
[LongFlight.git] / src / code / kalter / longflight / game / explosion / Explosion.java
1 package code.kalter.longflight.game.explosion;
3 import code.kalter.longflight.Animation;
4 import code.kalter.longflight.Loader;
5 import java.io.IOException;
6 import javax.microedition.lcdui.Graphics;
7 import javax.microedition.lcdui.Image;
9 /**
10 * Не приблежаться, рванёт!
11 *
12 * @author KalterFive
13 */
14 public class Explosion implements Detonator {
16 public static Explosion createExplosion(String path) throws IOException {
17 final Loader loader = Loader.getInstance();
18 final Image image = loader.getImage(path);
19 return createExplosion(image);
20 }
22 public static Explosion createExplosion(Image image) {
23 return new Explosion(image);
24 }
26 private static final int MAX = 5;
27 private final Animation[] boom;
28 private final int[] positionX;
29 private final int[] positionY;
31 // каждый кадр должен быть квадратным
32 private Explosion(Image explosion) {
33 boom = new Animation[MAX];
34 positionX = new int[MAX];
35 positionY = new int[MAX];
36 for (int i = 0; i < MAX; i++) {
37 boom[i] = Animation.createAnimation(explosion,
38 explosion.getHeight(), 80);
39 }
40 }
42 public void deactivateAll() {
43 for (int i = 0; i < boom.length; i++) {
44 boom[i].stop();
45 }
46 }
48 public void activate(int x, int y) {
49 for (int i = 0; i < boom.length; i++) {
50 if (!boom[i].getState()) {
51 boom[i].start();
52 this.positionX[i] = x;
53 this.positionY[i] = y;
54 break;
55 }
56 }
57 }
59 public void paint(Graphics graphics) {
60 for (int i = 0; i < boom.length; i++) {
61 boom[i].paint(graphics, positionX[i], positionY[i]);
62 }
63 }
65 public void update() {
66 for (int i = 0; i < boom.length; i++) {
67 boom[i].next();
68 }
69 }
70 }