-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
39 lines (35 loc) · 1.33 KB
/
Player.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
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Image;
public class Player {
public Player(int x, int y, Graphics g, boolean isCrouching) {
// Draw player
BufferedImage dino = null;
try {
String classPath = Player.class.getProtectionDomain().getCodeSource().getLocation().getPath();
String projectRoot = new File(classPath).getParentFile().getParentFile().getParentFile().getPath();
System.out.println(projectRoot);
String imagePath = projectRoot + "/assets/Dino.gif";
// Load the image using the path
dino = ImageIO.read(new File(imagePath));
} catch (IOException e) {
e.printStackTrace();
}
if (isCrouching) {
// Player if crouching
if (dino != null) {
Image scaledDino = dino.getScaledInstance(65, 40, Image.SCALE_DEFAULT);
g.drawImage(scaledDino, x - 7, y + 15, null);
}
} else {
// Draw player if not crouching
if (dino != null) {
Image scaledDino = dino.getScaledInstance(65, 65, Image.SCALE_DEFAULT);
g.drawImage(scaledDino, x - 7, y - 7, null);
}
}
}
}