-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisintegrateFX.java
More file actions
126 lines (92 loc) · 2.75 KB
/
DisintegrateFX.java
File metadata and controls
126 lines (92 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import java.util.Random;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import javax.swing.JPanel;
import java.awt.image.BufferedImage;
import java.awt.Color;
public class DisintegrateFX implements ImageFX {
private int WIDTH; // width of the image
private int HEIGHT; // height of the image
private int YPOS; // vertical position of the image
private GamePanel panel;
private int x;
private int y;
private BufferedImage spriteImage; // image for sprite effect
private BufferedImage copy; // copy of image
Graphics2D g2;
int time, timeChange; // to control when the image is grayed
public DisintegrateFX (GamePanel p, int xPos, int yPos, double height2, double width2, String name) {
panel = p;
HEIGHT = (int) height2;
WIDTH = (int) width2;
Random random = new Random();
x = xPos;
y = yPos;
time = 0;
timeChange = 1;
spriteImage = ImageManager.loadBufferedImage(name);
if (spriteImage == null) {
spriteImage = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = spriteImage.createGraphics();
g.setColor(Color.RED);
g.fillRect(0, 0, WIDTH, HEIGHT);
g.dispose();
}
copy = ImageManager.copyImage(spriteImage);
}
public void eraseImageParts(BufferedImage im, int interval) {
if (im == null) {
return;
}
int imWidth = im.getWidth();
int imHeight = im.getHeight();
int[] pixels = new int[imWidth * imHeight];
im.getRGB(0, 0, imWidth, imHeight, pixels, 0, imWidth);
for (int i = 0; i < pixels.length; i = i + interval) {
pixels[i] = 0;
}
im.setRGB(0, 0, imWidth, imHeight, pixels, 0, imWidth);
}
public void draw(Graphics2D g2) {
if (copy == null) {
if (spriteImage == null) {
g2.setColor(Color.RED);
g2.fillRect(x, y, WIDTH, HEIGHT);
return;
} else {
copy = ImageManager.copyImage(spriteImage);
if (copy == null) return;
}
}
TileMap tileMap = panel.getTileMap();
int drawX = x;
int drawY = y;
if (tileMap != null) {
drawX = (int)(x - tileMap.getCameraX());
drawY = (int)(y - tileMap.getCameraY());
}
if (time == 5)
eraseImageParts(copy, 11);
else if (time == 6)
eraseImageParts(copy, 7);
else if (time == 7)
eraseImageParts(copy, 5);
else if (time == 10)
eraseImageParts(copy, 3);
else if (time == 12)
eraseImageParts(copy, 2);
else if (time == 14)
eraseImageParts(copy, 1);
else if (time >= 15)
copy = ImageManager.copyImage(spriteImage);
g2.drawImage(copy, drawX, drawY, WIDTH, HEIGHT, null);
}
public Rectangle2D.Double getBoundingRectangle() {
return new Rectangle2D.Double (x, y, WIDTH, HEIGHT);
}
public void update() { // modify time
time = time + timeChange;
if (time >= 15)
panel.endDisintegrate();
}
}