masking with grid for collision detection