diff options
author | zlago | 2025-01-28 18:35:26 +0100 |
---|---|---|
committer | zlago | 2025-01-28 18:35:26 +0100 |
commit | f2cae9dbd96fde6eeb47d2f3ba3404944230dfba (patch) | |
tree | 8d7489133d6c5e0937a4e4408640ff6afd2a3683 /src/tilemap.c | |
parent | f67cdf08cb3dba9c176eb81e137e2da4648d9ace (diff) |
Diffstat (limited to 'src/tilemap.c')
-rw-r--r-- | src/tilemap.c | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/tilemap.c b/src/tilemap.c index 34e7c43..4819053 100644 --- a/src/tilemap.c +++ b/src/tilemap.c @@ -90,14 +90,36 @@ collision_T tilemap_area(struct tilemap *tilemap, int x1, int y1, int x2, int y2 void tilemap_background(struct tilemap *tilemap, int x, int y, int w, int h) { SDL_SetRenderDrawColor(renderer, tilemap->backdrop.r, tilemap->backdrop.g, tilemap->backdrop.b, tilemap->backdrop.a); SDL_RenderFillRect(renderer, &(SDL_Rect) {0, 0, w, h}); + int bx = 0, by = 0, vw = w, vh = h; + if (x < 0) { + bx = -x; + vw = w + x * 2; + x = 0; + } + if (y < 0) { + by = -y; + vh = h + y * 2; + y = 0; + } for (int i = 0; i < tilemap->middleground; i++) { - SDL_RenderCopy(renderer, tilemap->tilemaps[i], &(SDL_Rect) {x * tilemap->parallax[i].x, y * tilemap->parallax[i].y, w, h}, &(SDL_Rect) {0, 0, w, h}); + SDL_RenderCopy(renderer, tilemap->tilemaps[i], &(SDL_Rect) {x * tilemap->parallax[i].x, y * tilemap->parallax[i].y, vw, vh}, &(SDL_Rect) {bx, by, vw, vh}); } } void tilemap_foreground(struct tilemap *tilemap, int x, int y, int w, int h) { + int bx = 0, by = 0, vw = w, vh = h; + if (x < 0) { + bx = -x; + vw = w + x * 2; + x = 0; + } + if (y < 0) { + by = -y; + vh = h + y * 2; + y = 0; + } for (int i = tilemap->middleground; i < tilemap->layers; i++) { - SDL_RenderCopy(renderer, tilemap->tilemaps[i], &(SDL_Rect) {x * tilemap->parallax[i].x, y * tilemap->parallax[i].y, w, h}, &(SDL_Rect) {0, 0, w, h}); + SDL_RenderCopy(renderer, tilemap->tilemaps[i], &(SDL_Rect) {x * tilemap->parallax[i].x, y * tilemap->parallax[i].y, vw, vh}, &(SDL_Rect) {bx, by, vw, vh}); } } |