-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathglass.java
More file actions
47 lines (38 loc) · 1.43 KB
/
Copy pathglass.java
File metadata and controls
47 lines (38 loc) · 1.43 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
import java.awt.image.BufferedImage;
import java.awt.Point;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import java.awt.Graphics;
import java.awt.image.ImageObserver;
import java.awt.Rectangle;
public class glass {
private BufferedImage image; // image to represent glass
public Point pos; // glass's position on the screen
public int x = 200;
public int y = 200;
public glass() { // put the glass on the screen (its just a G for now but ill make some pictures later)
loadImage();
pos = new Point(x, y);
}
private void loadImage() { // function to actually load in the image, throws error if image not found or smth
try {
final String imageName = "glass.png";
image = ImageIO.read(new File("res/" + imageName)); // load in the image. placeholder image rn
} catch (IOException exc) {
System.out.println("Error opening image file: " + exc.getMessage());
}
}
public void draw(Graphics g, ImageObserver observer) { // i guess draw the image on the board
g.drawImage(
image, pos.x, pos.y, 50, 50, observer
);
}
public boolean contains(Point point) {
Rectangle bounds = new Rectangle(pos.x, pos.y, image.getWidth(), image.getHeight());
return bounds.contains(point);
}
public void setPosition(Point newPosition) {
this.pos = newPosition;
}
}