From 91aef268319a77ee8f5a082ca89264bf2671e212 Mon Sep 17 00:00:00 2001 From: quou Date: Sat, 6 May 2023 10:39:19 +1000 Subject: Map rendering and camera movement. --- render.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) (limited to 'render.c') diff --git a/render.c b/render.c index b2a59e2..c18d74d 100644 --- a/render.c +++ b/render.c @@ -261,3 +261,122 @@ void render_bitmap_col( src += sstride; } } + +void blit( + Bitmap* to, + const Bitmap* from, + int x, + int y, + const Rectangle* rect +) { + int i, j, stride, sstride, n; + Colour* dst; + const Colour* src; + Rectangle sub; + + sub = *rect; + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + if (sub.w > from->w) { return; } + if (sub.h > from->h) { return; } + + if ((n = -x) > 0) { + sub.w -= n; + sub.x += n; + x += n; + } + + if ((n = -y) > 0) { + sub.h -= n; + sub.y += n; + y += n; + } + + if ((n = x + sub.w - to->w) > 0) { + sub.w -= n; + } + + if ((n = y + sub.h - to->h) > 0) { + sub.h -= n; + } + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + + dst = to->pixels + (x + y * to->w); + src = from->pixels + (sub.x + sub.y * from->w); + + stride = to->w - sub.w; + sstride = from->w - sub.w; + + for (i = 0; i < sub.h; i++) { + for (j = 0; j < sub.w; j++) { + *dst = blend(*dst, *src); + dst++; + src++; + } + dst += stride; + src += sstride; + } +} + +void blit_col( + Bitmap* to, + const Bitmap* from, + int x, + int y, + const Rectangle* rect, + Colour colour +) { + int i, j, stride, sstride, n; + Colour* dst; + const Colour* src; + Rectangle sub; + + sub = *rect; + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + if (sub.w > from->w) { return; } + if (sub.h > from->h) { return; } + + if ((n = -x) > 0) { + sub.w -= n; + sub.x += n; + x += n; + } + + if ((n = -y) > 0) { + sub.h -= n; + sub.y += n; + y += n; + } + + if ((n = x + sub.w - to->w) > 0) { + sub.w -= n; + } + + if ((n = y + sub.h - to->h) > 0) { + sub.h -= n; + } + + if (sub.w <= 0) { return; } + if (sub.h <= 0) { return; } + + dst = to->pixels + (x + y * to->w); + src = from->pixels + (sub.x + sub.y * from->w); + + stride = to->w - sub.w; + sstride = from->w - sub.w; + + for (i = 0; i < sub.h; i++) { + for (j = 0; j < sub.w; j++) { + *dst = blend_mod(*dst, *src, colour); + dst++; + src++; + } + dst += stride; + src += sstride; + } +} -- cgit v1.2.3-54-g00ecf