-
Notifications
You must be signed in to change notification settings - Fork 0
/
Position.pde
68 lines (57 loc) · 1.3 KB
/
Position.pde
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
class Position {
public float x, y;
public Position(float x, float y) {
this.x = x;
this.y = y;
}
public Position(float x) {
this(x, 0);
}
public Position() {
this(0, 0);
}
public int getX() {return (int)this.x;}
public int getY() {return (int)this.x;}
/**
Moves in the direcrtion specified by the distance
**/
void move(int direction, int distance) {
if (direction % 2 == 0) // Vert or Horiz?
this.y += (distance*(direction-1)); // dir - 1 to make it positive or negative
else
this.x += (distance*(direction-2)); // dir - 2 to make it positive or negative
}
boolean at(Position other) {
return this.x == other.x && this.y == other.y;
}
Position clone() {
return new Position(this.x, this.y);
}
}
class Motion extends Position {
public float dx, dy;
public Motion(float x, float y, float dx, float dy) {
super(x,y);
this.dx = dx;
this.dy = dy;
}
public Motion(float x, float dx, float dy) {
super(x);
this.dx = dx;
this.dy = dy;
}
public Motion(float dx, float dy) {
super();
this.dx = dx;
this.dy = dy;
}
public Motion() {
super();
this.dx = 0;
this.dy = 0;
}
public void update(float delta) {
this.x += delta * this.dx;
this.y += delta * this.dy;
}
}