-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNPC.java
94 lines (79 loc) · 1.95 KB
/
NPC.java
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
import java.util.ArrayList;
import java.awt.geom.*;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import java.util.ArrayList;
public class NPC{
BufferedImage image;
boolean visited;
int numVisited;
int x;
int y;
String name;
int height;
int width;
ArrayList<ArrayList<String>> dialogues;
String currMsg;
int currRow;
int currC;
public NPC(String name, String dialogueFn, int a, int b){
x=a*10;
y=b*5;
this.name = name;
String fn = name + ".png";
loadOriginalImage(fn);
dialogues = new ArrayList<ArrayList<String>>();
dialogues.add(new ArrayList<String>());
readDialogue(dialogueFn);
currMsg = dialogues.get(0).get(0);
currRow = 0;
currC =0;
//System.out.println("dialogues:" + dialogues.get(0).get(0));
}
public void updateNPC(){
if(visited == false){
visited = true;
numVisited++;
}
numVisited = currRow+1;
}
public void updateMsg(int r, int c){
currMsg = dialogues.get(r).get(c);
currRow = r;
currC = c;
}
public void readDialogue(String fn){
File file = new File(fn);
try{
BufferedReader br = new BufferedReader(new FileReader(file));
String st = br.readLine();
int i=0;
while(st != null){
String[] line = st.split("//");
for(String s : line){
//System.out.println("reading dialogue., adding " + s);
dialogues.add(new ArrayList<String>());
dialogues.get(i).add(s);
}
i++;
st= br.readLine();
}
}catch(IOException e){
e.printStackTrace();
}
}
public void loadOriginalImage(String fileName) {
try {
image = ImageIO.read(new File(fileName));
height = image.getHeight();
width = image.getWidth();
//making a hit box
//height += height%10;
//width+=width%10;
} catch (IOException e) {
e.printStackTrace();
}
}
}