1.1 --- a/lib/image.c Tue Nov 13 14:35:22 2018 +0100
1.2 +++ b/lib/image.c Tue Nov 13 15:17:37 2018 +0100
1.3 @@ -98,6 +98,23 @@
1.4 p->x, p->y, -1, 1);
1.5 }
1.6
1.7 +/* Unplot a sprite by restoring a region from the background image. */
1.8 +
1.9 +void image_unplot_sprite_from_image(sprite_t *s, sprite_t *bg,
1.10 + int xorigin, int yorigin)
1.11 +{
1.12 + int frame = s->cfg->frame;
1.13 + position_t *p = image_get_stored_position(s, frame);
1.14 +
1.15 + /* Plot the region of the background using the sprite image dimensions
1.16 + converted to background image dimensions at the sprite's position on the
1.17 + display. */
1.18 +
1.19 + image_update_tiled_image(bg, xorigin, yorigin,
1.20 + s->image->width, (s->image->height / s->yscale) * bg->yscale,
1.21 + p->x, p->y);
1.22 +}
1.23 +
1.24
1.25
1.26 /* Plot a section of an image without storing the background beforehand. */
1.27 @@ -233,3 +250,21 @@
1.28 0, ydisplay);
1.29 }
1.30 }
1.31 +
1.32 +/* Plot a region of a tiled image. */
1.33 +
1.34 +void image_update_tiled_image(sprite_t *s, int xorigin, int yorigin,
1.35 + int width, int height,
1.36 + int xdisplay, int ydisplay)
1.37 +{
1.38 + /* Find the source position for the region. */
1.39 +
1.40 + int xsource = wrap_value(xorigin + xdisplay, s->image->width);
1.41 + int ysource = wrap_value(yorigin + ydisplay * s->yscale, s->image->height);
1.42 +
1.43 + /* Request tiling in the source coordinates. */
1.44 +
1.45 + image_tile_sprite(s, xsource, ysource,
1.46 + width, height,
1.47 + xdisplay, ydisplay);
1.48 +}