image_index = (direction + 22.5) / 45; if (direction + 22.5 >= 360 ) { image_index = 0; }