http://stackoverflow.com/questions/707370/clean-efficient-algorithm-for-wrapping-integers-in-c
>
> It's also possible that I mistranslated the C code in the above link, as
> I don't know C.
>
Yes, because Gambas makes automatic conversions and thus the line where
division is, gives sometimes
different answers than in C. Example kX += range_size * 1.5 instead of 1
like in C.
int Wrap(int kX, int const kLowerBound, int const kUpperBound)
{
int range_size = kUpperBound - kLowerBound + 1;
if (kX < kLowerBound)
kX += range_size * ((kLowerBound - kX) / range_size + 1);
return kLowerBound + (kX - kLowerBound) % range_size;
}
-->
Private Function Wrap(iX As Integer, iLowerBound As Integer, iUpperBound As
Integer) As Integer
Dim iRange As Integer = iUpperBound - iLowerBound + 1
If iX < iLowerBound Then
iX += iRange * CInt((iLowerBound - iX) / iRange + 1)
Endif
Return iLowerBound + ((iX - iLowerBound) Mod iRange)
End
How is your game progressing?
Games like yours require a lot of work even with Gambas.
It's interesting to see what you will come up to.
Jussi
------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60134071&iu=/4140/ostg.clktrk
_______________________________________________
Gambas-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gambas-user