forked from mcyapan/CSCI205Project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrawingObject.java
More file actions
153 lines (118 loc) · 3.77 KB
/
DrawingObject.java
File metadata and controls
153 lines (118 loc) · 3.77 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import java.awt.*;
import java.util.ArrayList;
public abstract class DrawingObject {
private ArrayList<Shape> shapes;
private ArrayList<Color> colors;
private String name;
private boolean collision;
private int worldX, worldY;
private Rectangle solidArea = new Rectangle(0,0,48,48);
private ArrayList<Shape> tileShapes;
private ArrayList<Color> tileColors;
// solidAreaDefaultX and solidAreaDefaultY needed for CollisionChecker
private int solidAreaDefaultX = 0;
private int solidAreaDefaultY = 0;
public DrawingObject(boolean collision) {
shapes = new ArrayList<>();
colors = new ArrayList<>();
tileShapes = new ArrayList<>();
tileColors = new ArrayList<>();
this.collision = collision;
}
/**
* draw method for tiles and entities
* @param g2d
* @param sc
*/
public void draw(Graphics2D g2d, SceneCanvas sc) {
int screenX = worldX - sc.getPlayer().getWorldX() + sc.getPlayer().getScreenX();
int screenY = worldY - sc.getPlayer().getWorldY() + sc.getPlayer().getScreenY();
// Only draw the object if it is within the player's visible screen
if (worldX > sc.getPlayer().getWorldX() - sc.getPlayer().getScreenX() - sc.getTileSize() &&
worldX < sc.getPlayer().getWorldX() + sc.getPlayer().getScreenX() + sc.getTileSize() &&
worldY > sc.getPlayer().getWorldY() - sc.getPlayer().getScreenY() - sc.getTileSize() &&
worldY < sc.getPlayer().getWorldY() + sc.getPlayer().getScreenY() + sc.getTileSize()) {
// Translate to world position and draw the shapes
g2d.translate(screenX, screenY);
for (int i = 0; i < shapes.size(); i++) {
g2d.setColor(colors.get(i));
g2d.fill(shapes.get(i));
}
g2d.translate(-screenX, -screenY); // Reset translation
}
}
public void addTile(Shape shape, Color color) {
tileShapes.add(shape);
tileColors.add(color);
}
public void drawTile(Graphics2D g2d) {
int i;
for (i = 0; i < tileShapes.size(); i++) {
g2d.setColor(tileColors.get(i));
g2d.fill(tileShapes.get(i));
}
}
public ArrayList<Shape> getShapes() {
return shapes;
}
public ArrayList<Color> getColors() {
return colors;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean getCollision() {
return collision;
}
public void setCollision(boolean collision) {
this.collision = collision;
}
public int getWorldX() {
return worldX;
}
public void setWorldX(int worldX) {
this.worldX = worldX;
}
public int getWorldY() {
return worldY;
}
public void setWorldY(int worldY) {
this.worldY = worldY;
}
public Rectangle getSolidArea() {
return solidArea;
}
public int getSolidAreaX() {
return solidArea.x;
}
public int getSolidAreaY() {
return solidArea.y;
}
public int getSolidAreaWidth() {
return solidArea.width;
}
public int getSolidAreaHeight() {
return solidArea.height;
}
public void setSolidAreaX (int x) {
this.solidArea.x = x;
}
public void setSolidAreaY (int y) {
this.solidArea.y = y;
}
public void setSolidAreaWidth (int width) {
this.solidArea.width = width;
}
public void setSolidAreaHeight (int height) {
this.solidArea.height = height;
}
public int getSolidAreaDefaultX() {
return solidAreaDefaultX;
}
public int getSolidAreaDefaultY() {
return solidAreaDefaultY;
}
}