- // hit something -- check out what it was
- ELX = getLevelFromLaserX(LX + XS);
- ELY = getLevelFromLaserY(LY + YS);
+ // check if laser scan has hit two diagonally adjacent element corners
+ boolean diag_1 = ((hit_mask & HIT_MASK_DIAGONAL_1) == HIT_MASK_DIAGONAL_1);
+ boolean diag_2 = ((hit_mask & HIT_MASK_DIAGONAL_2) == HIT_MASK_DIAGONAL_2);
+
+ // check if laser scan has crossed element boundaries (not just mini tiles)
+ boolean cross_x = (getLevelFromLaserX(LX) != getLevelFromLaserX(LX + 2));
+ boolean cross_y = (getLevelFromLaserY(LY) != getLevelFromLaserY(LY + 2));
+
+ if (cross_x || cross_y)
+ {
+ // hit something at next tile -- check out what it was
+ ELX = getLevelFromLaserX(LX + XS);
+ ELY = getLevelFromLaserY(LY + YS);
+ }
+ else
+ {
+ // hit something at same tile -- check out what it was
+ ELX = getLevelFromLaserX(LX);
+ ELY = getLevelFromLaserY(LY);
+ }