- *x = g->src_x + (frame / g->anim_frames_per_line) * g->width;
- *y = g->src_y + (frame % g->anim_frames_per_line) * g->offset_y;
+ int max_height = g->anim_frames_per_line * g->height;
+
+ *x = g->src_x + (g->src_y + frame * g->offset_y) / max_height * g->width;
+ *y = (g->src_y + frame * g->offset_y) % max_height;