-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMonster.java
64 lines (53 loc) · 1.81 KB
/
Monster.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
//Static image of skeleton character
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
public class Monster extends GameObj {
public static final String IMG_FILE = "files/skull.png";
public static final int SIZE = 16;
public static final int INIT_VEL_X = 0;
public static final int INIT_VEL_Y = 0;
private static BufferedImage img;
private Room r;
public Monster(Room r, Dungeon d) {
super(INIT_VEL_X, INIT_VEL_Y, r.getX() + (3 * SIZE) + (int) (Math.random() * (Room.getSize() - (7 * SIZE))),
r.getY() + (3 * SIZE) + (int) (Math.random() * (Room.getSize() - (7 * SIZE))), SIZE, SIZE, r.getX(),
r.getY(), r.getX() + Room.getSize(), r.getY() + Room.getSize(), d);
this.r = r;
try {
if (img == null) {
img = ImageIO.read(new File(IMG_FILE));
}
} catch (IOException e) {
System.out.println("Internal Error:" + e.getMessage());
}
}
public Room monsterRoom() {
return r;
}
@Override
public boolean equals(Object o) {
if (o == null || this.getClass() != o.getClass()) {
return false;
} else {
Monster p = (Monster) o;
boolean b = (this.getPx() == p.getPx() && this.getPy() == p.getPy());
return b;
}
}
@Override
public int hashCode() {
int prime = 31;
int result = prime + this.getPx();
result = result * prime + this.getPy();
return result;
}
@Override
public void draw(Graphics g) {
if (r.getVisibility()){
g.drawImage(img, this.getPx(), this.getPy(), this.getWidth(), this.getHeight(), null);
}
}
}