-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfiber.java
More file actions
77 lines (61 loc) · 2.3 KB
/
fiber.java
File metadata and controls
77 lines (61 loc) · 2.3 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
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
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
//import javax.swing.JPanel;
import java.awt.image.ImageObserver;
public class fiber {
private BufferedImage image; // image to represent fibrs
public Point pos; // fiber's position on the screen
//public Point rectPos;
public int x = 100; //CHANGE THESE X, Y TO CHANGE WHERE THE FABRIC SPAWNS. SAME FOR ALL OBJECTS
public int y = 100;
public fiber() { // put the fiber on the screen (its just a F for now but ill make some pictures
// later)
loadImage();
pos = new Point(x, y);
//pos.x = x;
//pos.y = y;
}
private void loadImage() { // function to actually load in the image, throws error if image not found or
// smth
try {
final String imageName = "fibers.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) { // draw the image
//if (image != null) {
g.drawImage(
image, pos.x, pos.y, 50, 50, observer
);
System.out.println("x: " + pos.x + " y: " + pos.y);
//}
}
public boolean contains(Point point) {
//rectPos.x = 200;
//rectPos.y = 200;
Rectangle bounds = new Rectangle(pos.x, pos.y, image.getWidth(), image.getHeight());
return bounds.contains(point);
/*
int objectWidth = image.getWidth();
int objectHeight = image.getHeight();
// Calculate the bounding box of the object
int objectLeft = pos.x;
int objectRight = pos.x + objectWidth;
int objectTop = pos.y;
int objectBottom = pos.y + objectHeight;
// Check if the point is within the bounding box
return (point.x >= objectLeft && point.x <= objectRight &&
point.y >= objectTop && point.y <= objectBottom);
*/
}
public void setPosition(Point newPosition) {
this.pos = newPosition;
}
}