I am trying to make a raycaster game in Javascript, and to do so, I am following this tutorial, which is written in C .
My problem stems from trying to convert the following two lines to javascript:
int tx = (int)(texWidth * (floorX - cellX)) & (texWidth - 1);
color = (color >> 1) & 8355711; // make a bit darker
I don't know what the "&" and ">>" mean in those two lines. Is there an equivalent in Javascript?
CodePudding user response:
>>
is the right bit-shift operator and &
is the bitwise-and operator, both of them are available in JavaScript
CodePudding user response:
The code directly translates to JS with the removal of the (int) typecast and the replacement of int with let/var/const.
let tx = (texWidth * (floorX - cellX)) & (texWidth - 1);
color = (color >> 1) & 8355711; // make a bit darker
&
is the bitwise and, >>
is the bitshift right, explained well here.