-
Notifications
You must be signed in to change notification settings - Fork 0
/
Translation.h
65 lines (54 loc) · 1.3 KB
/
Translation.h
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
class Translation {
public:
char hMomentum;
char vMomentum;
boolean flip;
char framesShown;
char framesPerMove;
Position pos;
Translation(char h, char v, boolean f, char fpm) {
framesShown = 0;
hMomentum = h ;
vMomentum = v;
flip = f;
framesPerMove = fpm;
}
Position* initialize() {
pos.hOffset=0;
pos.vOffset=0;
pos.flip = flip;
// if moving right, start all the way left
if (hMomentum > 0) pos.hOffset = -7;
// if moving left, start all the way right
if (hMomentum < 0) pos.hOffset = 7;
// if moving right, start all the way left
if (vMomentum > 0) pos.vOffset = -7;
// if moving left, start all the way right
if (vMomentum < 0) pos.vOffset = 7;
return &pos;
}
void apply(Position* pos) {
framesShown++;
if (framesShown >= framesPerMove) {
framesShown = 0;
//
// do horizontal moves
pos->hOffset += hMomentum;
if (pos->hOffset > 8) {
pos->hOffset = -7;
}
if (pos->hOffset < -8) {
pos->hOffset = 7;
}
//
// do vertical moves
pos->vOffset+= vMomentum;
if (pos->vOffset > 8) {
pos->vOffset = -7;
}
if (pos->vOffset < -8) {
pos->vOffset = 7;
}
}
}
};