-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolidObject.java
More file actions
44 lines (36 loc) · 1.16 KB
/
Copy pathSolidObject.java
File metadata and controls
44 lines (36 loc) · 1.16 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
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
public class SolidObject {
private int x;
private int y;
private int width;
private int height;
private Rectangle2D.Double bounds;
private BufferedImage image;
// Constructor for solid objects. width and height are derived from the image dimensions.
public SolidObject(double xPos, double yPos, BufferedImage img) {
x = (int) xPos;
y = (int) yPos;
image = img;
if (image != null) {
width = image.getWidth();
height = image.getHeight();
} else {
width = 0;
height = 0;
}
bounds = new Rectangle2D.Double(x, y, width, height);
}
// Draws the solid object image at the specified offset.
public void draw(Graphics2D g2, int offsetX, int offsetY) {
int drawX = x - offsetX;
int drawY = y - offsetY;
if (image != null) {
g2.drawImage(image, drawX, drawY, null);
}
}
public Rectangle2D.Double getBoundingRectangle() {
return bounds;
}
}