miniventure
miniventure copied to clipboard
Comment saying what ">> 4" is for
https://github.com/shylor/miniventure/blob/04c1c3253a2550d09c06e261477a8f75d0cdbd00/src/com/mojang/ld22/level/Level.java#L107
It is used in a few other lines too dealing with coordinates and dimensions.
>>
4 means a right bit-shift of 4 places.
E.g. 01101001 (105) becomes 0110 (6), which is subtracting the 1001 (9) = 01100000 (96) and dividing by 16 (2^4).
So overall it gives the number of times 16 goes into it, ignoring the remainder.
If 16 is the tile width, then this is converting a distance into a number of tiles.
The +15 before the >>4 makes it so that the result is +1 unless the input was a multiply of 16, effectively meaning the result is getting the ceil (rounding up) not the floor (rounding down) of dividing by 16, looking at the end of the tile not the start.
Overall the comment should probably say something like that this line will divide the screen width by 16 (the tile width) rounding up.