-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrip.java
More file actions
66 lines (53 loc) · 1.59 KB
/
Copy pathStrip.java
File metadata and controls
66 lines (53 loc) · 1.59 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
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.image.BufferedImage;
import java.awt.*;
public abstract class Strip
{
public final int SIZE = 14;
public int index;
public int[] parts;
public static BufferedImage loadImage(String file) {
BufferedImage sprite = null;
try {
sprite = ImageIO.read(new File(file + ".png"));
} catch (IOException e) {
e.printStackTrace();
}
return sprite;
}
public int[] getObjects(){
return parts;
}
//integer value 0-19 designating x-axis location
public int getIndex(){
return index;
}
public void setIndex(int i){
index = i;
}
public BufferedImage addStrip(Map m, BufferedImage frame){
final BufferedImage finalImage = new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics2D g = finalImage.createGraphics();
g.drawImage(frame,0,0,null);
for (int i = 0; i < parts.length; i++){
if (parts[i] == 1){
g.drawImage(m.getObjects()[parts[i]],50*index,50*i-50,null);
} else {
g.drawImage(m.getObjects()[parts[i]],50*index,50*i,null);
}
}
g.dispose();
return finalImage;
}
public int getRandomEmptySpace(){
int r = (int) (Math.random()*SIZE);
for (int i = r; i < r+SIZE; i++){
if (parts[i%SIZE] == 0){
return i%SIZE;
}
}
return -1;
}
}