-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDirection.pde
More file actions
56 lines (52 loc) · 1019 Bytes
/
Direction.pde
File metadata and controls
56 lines (52 loc) · 1019 Bytes
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
// possible moving directions of the snake
// diagonal moves are not allowed
enum Direction {
left,
right,
up,
down;
// turn left
Direction left() {
if (this == left)
return down;
else if (this == right)
return up;
else if (this == up)
return left;
else
return right;
}
// turn right
Direction right() {
if (this == left)
return up;
else if (this == right)
return down;
else if (this == up)
return right;
else
return left;
}
// velocity of the current direction
PVector velocity() {
if (this == left)
return new PVector(-1, 0);
else if (this == right)
return new PVector(1, 0);
else if (this == up)
return new PVector(0, -1);
else
return new PVector(0, 1);
}
// direction to degree
int toDegree() {
if (this == left)
return 90;
else if (this == right)
return 270;
else if (this == up)
return 0;
else
return 180;
}
}