Try letting the currentX and prevX values stack up as high as need be, then use a normalization function (like the one I wrote below) to put the value inside the desired range when you need to use it:
Code:// Recursive normalization function
// Moves supplied value inside min/max constraints
int normalize(int n, int min, int max) {
int diff = max - min;
if(n < min) {
return normalize(n+diff, min, max);
} else
if(n > max) {
return normalize(n-diff, min, max);
} else return n;
}
Also, if you take the difference of two values and feed it through the above normalization function you will get the same difference whatever the offset.
In this example the normalized difference between x and y is always 66 because the actual difference is always the same (1134):
Code:int x1 = -512; int y1 = 622;
int x2 = -24; int y2 = 1110;
int x3 = 0; int y3 = 1134;
int min = 0;
int max = 100;
println(normalize(x1-y1, min, max));
println(normalize(x2-y2, min, max));
println(normalize(x3-y3, min, max));