-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathAccelerationVectorPair.jack
80 lines (73 loc) · 1.93 KB
/
AccelerationVectorPair.jack
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
/**
* The AccelerationVectorPair module, used to rudimentarily simulate physics
* These come in pairs for RAM memory efficiency
*/
class AccelerationVectorPair {
field int x;
field int y;
field int x2;
field int y2;
static Array cache;
function void init() {
var int i;
var int j;
var int k;
var int l;
var int c;
let cache = Array.new(169);
let i = -2;
while (i < 3) {
let j = -2;
while (j < 3) {
if ((Math.abs(i) + Math.abs(j)) < 3) {
let k = -2;
while (k < 3) {
let l = -2;
while (l < 3) {
if ((Math.abs(k) + Math.abs(l)) < 3) {
let cache[c] = AccelerationVectorPair.new(
i,
j,
k,
l
);
let c = c + 1;
}
let l = l + 1;
}
let k = k + 1;
}
}
let j = j + 1;
}
let i = i + 1;
}
}
constructor AccelerationVectorPair new(int _x, int _y, int _x2, int _y2) {
let x = _x;
let y = _y;
let x2 = _x2;
let y2 = _y2;
return this;
}
function AccelerationVectorPair random() {
var int rand;
let rand = 32767;
while (~(rand < 169)) {
let rand = (Util.random() & 32640) / 128;
}
return cache[rand];
}
method int getX() {
return x;
}
method int getY() {
return y;
}
method int getX2() {
return x2;
}
method int getY2() {
return y2;
}
}