Thanks for replying. Not sure I understand hehe
2 ^ 6 = 64 (fractional part of the fix16 is 6 bits)
So let's check
Code: Select all
...
int enemyPosx = 260; //starter position
...
int sinSpeed = 2;
int Amplitude = 1;
enemyPosx = enemyPosx - 1; //moves 1 pixel (60 pixels/sec aprox)
enemyPosy = contsY + sinFix16(enemyPosx * sinSpeed) * Amplitude;
...
Enemy is moving from right to left:
enemyPosy = 84 + sinFix16(260 * 2) * 1 = 84 + sinFix16(520) = 81 ( then sinFix16(520) = -3 )
enemyPosy = 84 + sinFix16(259 * 2) * 1 = 84 + sinFix16(518) = 82 ( then sinFix16(518) = -2 )
enemyPosy = 84 + sinFix16(258 * 2) * 1 = 84 + sinFix16(516) = 82 ( then sinFix16(516) = -2 )
enemyPosy = 84 + sinFix16(257 * 2) * 1 = 84 + sinFix16(514) = 83 ( then sinFix16(514) = -1 )
enemyPosy = 84 + sinFix16(256 * 2) * 1 = 84 + sinFix16(512) = 84 ( then sinFix16(512) = 0 )
...
SINE WAVE table have 1024 entries ( varies 2 every time):
1024 -> 0 ---> that means sinFix16(1024) = 0
1022 -> -1
1020 -> -2
1018 -> -2
1016 -> -3
...
768 -> -64
...
516 -> -2
514 -> -1
512 -> 0
510 -> 1
508 -> 2
...
2 -> 1
0 -> 0
That means starts with negative values (SIN wave starts moving down... then goes up to 0, goes up and goes down again)
from 0 to -64, from -64 to 0 to 64, again from 64 to 0
IF Amplitude = 2, then sinFix16() will go from 0 to -128, from -128 to 0 to 128, again from 128 to 0
And so