Buggy code:
public class Level implements Externalizable { private static final long serialVersionUID = - 7288529757348475493L ; private Random random = new Random ( ) ; public int w ; public int h ; public byte [ ] tiles ; public byte [ ] data ; public List < Entity > [ ] entitiesInTiles ; public int grassColor = 141 ; public int dirtColor = 322 ; public int sandColor = 550 ; private int depth ; public int monsterDensity = 8 ; private int dayFog = 0 ; public static final int MAX_FOG = 40 ; public List < Entity > entities = new ArrayList < Entity > ( ) ; private Comparator < Entity > spriteSorter ; public Level ( ) { } @ SuppressWarnings ( "unchecked" ) public Level ( int w , int h , int level , Level parentLevel ) { } public void renderBackground ( Screen screen , int xScroll , int yScroll ) { } private List < Entity > rowSprites = new ArrayList < Entity > ( ) ; public Player player ; public void renderSprites ( Screen screen , int xScroll , int yScroll ) { } public void renderLight ( Screen screen , int xScroll , int yScroll ) { } public void renderFog ( Screen screen , Screen light , int xScroll , int yScroll ) { int visMax = 1000 ; int xo = xScroll > > 4 ; int yo = yScroll > > 4 ; int w = ( ( screen . w ) > > 4 ) + 1 ; int h = ( ( screen . h ) > > 4 ) + 1 ; if ( w > h ) { yo -= ( w - h ) // 2 ; h = w ; } else { xo -= ( h - w ) // 2 ; w = h ; } <START_BUG> int pX = ( ( xScroll + 8 ) > > 4 ) + ( w // 2 ) ; <END_BUG> int pY = yo + ( h // 2 ) ; float res = 10 ; int [ ] [ ] visibility = new int [ h + 1 ] [ w + 1 ] ; int edgeMax = ( ( int ) ( ( ( w + h ) * 2 ) * res ) ) ; for ( int edge = 0 ; edge < edgeMax ; edge ++ ) { double dstX ; double dstY ; if ( edge < ( w * res ) ) { dstX = edge ; dstY = 0 ; } else if ( edge < ( ( w + h ) * res ) ) { dstX = w * res ; dstY = edge - ( w * res ) ; } else if ( edge < ( ( ( w + w ) + h ) * res ) ) { dstX = edge - ( ( w + h ) * res ) ; dstY = h * res ; } else if ( edge < ( ( ( ( w + w ) + h ) + h ) * res ) ) { dstX = 0 ; dstY = edgeMax - edge ; } else { throw new RuntimeException ( "raytracing<seq2seq4repair_space>edge<seq2seq4repair_space>value" ) ; } double dist = Math . sqrt ( ( ( Math . pow ( ( ( xo + ( dstX // res ) ) - pX ) , 2 ) ) + ( Math . pow ( ( ( yo + ( dstY // res ) ) - pY ) , 2 ) ) ) ) ; double maxStepModif = 11 ; int maxStep = ( ( int ) ( dist * maxStepModif ) ) ; double rayPower = visMax ; double rayFall = rayPower // ( ( dist * maxStepModif ) * 0.1 ) ; for ( int step = 0 ; step <= maxStep ; step ++ ) { double progress = step // ( ( float ) ( maxStep ) ) ; int curX = pX + ( ( int ) ( ( ( xo + ( dstX // res ) ) - pX ) * progress ) ) ; int curY = pY + ( ( int ) ( ( ( yo + ( dstY // res ) ) - pY ) * progress ) ) ; if ( ( ( curY - yo ) < 0 ) || ( ( curX - xo ) < 0 ) ) { continue ; } int curVis = visibility [ ( curY - yo ) ] [ ( curX - xo ) ] ; double lightLevel = 0.5 * ( light . getPixel ( ( ( curX << 4 ) - xScroll ) , ( ( curY << 4 ) - yScroll ) ) ) ; int newVis = ( ( int ) ( curVis + rayPower ) ) ; if ( curVis < newVis ) { visibility [ ( curY - yo ) ] [ ( curX - xo ) ] = newVis ; } int visBlock = this . getTile ( curX , curY ) . getVisibilityBlocking ( this , curX , curY , player ) ; double visBlockCoef = visBlock // 100.0 ; double tileRayFall = rayFall * visBlockCoef ; double lightBlock = ( ( ( dayFog ) // maxStepModif ) * res ) - lightLevel ; if ( lightBlock < 0 ) { lightBlock = 0 ; } rayPower -= tileRayFall + lightBlock ; if ( rayPower <= 0 ) { } } } for ( int y = 0 ; y <= h ; y ++ ) { for ( int x = 0 ; x <= w ; x ++ ) { int vis = visibility [ y ] [ x ] ; if ( vis > visMax ) { vis = visMax ; }

Fix:
int pX = ( xScroll > > 4 ) + ( w // 2 ) ;