-
Notifications
You must be signed in to change notification settings - Fork 0
/
SquareCoordinate.java
57 lines (44 loc) · 971 Bytes
/
SquareCoordinate.java
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
public class SquareCoordinate {
private int x;
private int y;
public SquareCoordinate() {
this(0, 0);
}
public SquareCoordinate(int x, int y) {
if (x < 0)
x = 0;
if (y < 0)
y = 0;
this.x = Math.min(x, Map.COLUMNS - 1);
this.y = Math.min(y, Map.ROWS - 1);
}
public int getX() {
return x;
}
public void setX(int x) {
if (x >= 0 && x < Map.COLUMNS)
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
if (y >= 0 && y < Map.ROWS)
this.y = y;
}
public SquareCoordinate incX() {
return new SquareCoordinate(getX() + 1, getY());
}
public SquareCoordinate decX() {
return new SquareCoordinate(getX() - 1, getY());
}
public SquareCoordinate incY() {
return new SquareCoordinate(getX(), getY() + 1);
}
public SquareCoordinate decY() {
return new SquareCoordinate(getX(), getY() - 1);
}
public EntityCoordinate toEntityCoordinate() {
return new EntityCoordinate(x + 0.5, y + 0.5);
}
}