same idea here.

you can simply this by doing

return not(( player.gridX == box.gridX ) and ( (player.gridY + (dy * 64)) == box.gridY ))