summary refs log tree commit diff
path: root/src/tilemap.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tilemap.c')
-rw-r--r--src/tilemap.c26
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});
 	}
 }