1.1 --- a/lib/image.c Sat Nov 10 18:53:06 2018 +0100
1.2 +++ b/lib/image.c Sat Nov 10 19:06:08 2018 +0100
1.3 @@ -17,6 +17,7 @@
1.4 * along with this program. If not, see <http://www.gnu.org/licenses/>.
1.5 */
1.6
1.7 +#include "display.h"
1.8 #include "image.h"
1.9
1.10
1.11 @@ -34,3 +35,49 @@
1.12 {
1.13 return r->image + r->size * frame;
1.14 }
1.15 +
1.16 +
1.17 +
1.18 +/* Copy a region from the screen to the store, then blit the image. */
1.19 +
1.20 +void image_plot_sprite(sprite_t *s, int x, int y, int key)
1.21 +{
1.22 + int frame = s->cfg->frame;
1.23 + position_t *p = image_get_stored_position(s->regions, frame);
1.24 +
1.25 + /* Copy to the stored region. */
1.26 +
1.27 + display_copy(s->cfg, image_get_stored_region(s->regions, frame),
1.28 + s->image->width, s->image->height / s->yscale, 1,
1.29 + x, y, -1, 0);
1.30 +
1.31 + /* Plot to the screen. */
1.32 +
1.33 + display_copy(s->cfg, s->image->image,
1.34 + s->image->width, s->image->height, s->yscale,
1.35 + x, y, key, 1);
1.36 +
1.37 + /* Record the stored background details. */
1.38 +
1.39 + p->x = x;
1.40 + p->y = y;
1.41 +
1.42 + if (frame >= s->regions->stored)
1.43 + s->regions->stored = frame + 1;
1.44 +}
1.45 +
1.46 +/* Copy a region from the store to the screen, restoring the original
1.47 + background. */
1.48 +
1.49 +void image_unplot_sprite(sprite_t *s)
1.50 +{
1.51 + int frame = s->cfg->frame;
1.52 + position_t *p = image_get_stored_position(s->regions, frame);
1.53 +
1.54 + /* Only unplot the sprite if a region was stored for the frame. */
1.55 +
1.56 + if (s->regions->stored > frame)
1.57 + display_copy(s->cfg, image_get_stored_region(s->regions, frame),
1.58 + s->image->width, s->image->height / s->yscale, 1,
1.59 + p->x, p->y, -1, 1);
1.60 +}