-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQBox.java
More file actions
200 lines (179 loc) · 4.34 KB
/
QBox.java
File metadata and controls
200 lines (179 loc) · 4.34 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/**
* @author Edgar Quillion <edgarquill@gmail.com>
* @version Version 1
* @since 1.6
*/
import java.awt.Graphics2D;
import java.awt.Color;
/**
* Quillion Box
*/
public class QBox
{
private double x, y;
private int width, height;
/**
* A constructor for the box
* QBox does not contain any offsets, it is just a box
* All the values are set to 0 on creation
*/
public QBox()
{
this.x = 0;
this.y = 0;
this.width = 0;
this.height = 0;
}
/**
* Sets the value of x to whatever you choose to
* @param x the value to which x will be set to
*/
public void setX(double x)
{
this.x = x;
}
/**
* Return x value of the object
* I return int because it is easier to use for collision detection
* @return returns the x value of the object
*/
public int getX()
{
return (int)this.x;
}
/**
* Increment the object's x value, very useful for movement
* @param x the value by which to increment x by
*/
public void incrementX(double x)
{
this.x += x;
}
/**
* Sets the value of y to whatever you choose to
* @param y the value to which y will be set to
*/
public void setY(double y)
{
this.y = y;
}
/**
* Return y value of the object
* I return int because it is easier to use for collision detection
* @return returns the y value of the object
*/
public int getY()
{
return (int)this.y;
}
/**
* Increment the object's y value, very useful for movement
* @param y the value by which to increment y by
*/
public void incrementY(double y)
{
this.y += y;
}
/**
* Sets the width value to whatever you choose to
* @param width the value to which objetc's width will be set to
*/
public void setWidth(int width)
{
this.width = width;
}
/**
* returns the object's width
* @return the width of this object
*/
public int getWidth()
{
return this.width;
}
/**
* Increments the object's width by a set amount
* @param amount how much to increment this object's width by
*/
public void incrementWidth(int amount)
{
this.width += amount;
}
/**
* Sets the height value to whatever you choose to
* @param height the value to which object's height will be set to
*/
public void setHeight(int height)
{
this.height = height;
}
/**
* returns the objetc's height
* @return the width of this object
*/
public int getHeight()
{
return this.height;
}
/**
* Increments the object's height by a set amount
* @param amount how much to increment this object's height by
*/
public void incrementHeight(int amount)
{
this.height += amount;
}
/**
* returns the object's left x coordinate,
* is used for collision detection checking
* @return the object's left x coordinate
*/
public int getLeftX()
{
return (int)this.x;
}
/**
* returns the object's right x coordinate,
* is used for collision detection checking
* @return the object's right x coordinate(which is x+widht)
*/
public int getRightX()
{
return (int)(this.x+this.width);
}
/**
* returns the object's top y coordinate,
* is used for collision detection checking
* @return the object's top y coordinate
*/
public int getTopY()
{
return (int)this.y;
}
/**
* returns the object's bottom y coordinate,
* is used for collision detection checking
* @return the object's bottom y coordinate(which is y+height)
*/
public int getBottomY()
{
return (int)(this.y+this.height);
}
/**
* Draws the box into to the graphics passed,
* box outline will be black color
* @param g graphics where the box will be drawn into
*/
public void drawBox(Graphics2D g)
{
g.setColor(Color.BLACK);
g.drawRect(this.getX(), this.getY(), this.width, this.height);
}
/**
* Same as drawBox
* @param g graphics where the box will be drawn into
*/
public void draw(Graphics2D g)
{
this.drawBox(g);
}
}