summary refs log tree commit diff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c49
1 files changed, 37 insertions, 12 deletions
diff --git a/src/main.c b/src/main.c
index 41c239b..ce94712 100644
--- a/src/main.c
+++ b/src/main.c
@@ -240,10 +240,19 @@ int game_load_level(char *level) {
 
 			game_state = STATE_FADE_OUT;
 			fade = 255;
-			int x = (entities.player[0].x / 16) - (WINDOW_WIDTH / 2);
-			int y = (entities.player[0].y / 16) - (WINDOW_HEIGHT / 2);
-			if (x < 0) {x = 0;} else if (x + WINDOW_WIDTH > tilemap->width * 8) {x = tilemap->width * 8 - WINDOW_WIDTH;}
-			if (y < 0) {y = 0;} else if (y + WINDOW_HEIGHT > tilemap->height * 8) {y = tilemap->height * 8 - WINDOW_HEIGHT;}
+			int x, y;
+			if (tilemap->width < WINDOW_WIDTH / 8) {
+				x = -((WINDOW_WIDTH - tilemap->width * 8) / 2);
+			} else {
+				x = (entities.player[0].x / 16) - (WINDOW_WIDTH / 2);
+				if (x < 0) {x = 0;} else if (x + WINDOW_WIDTH > tilemap->width * 8) {x = tilemap->width * 8 - WINDOW_WIDTH;}
+			}
+			if (tilemap->height <= WINDOW_HEIGHT / 8) {
+				y = -((WINDOW_HEIGHT - tilemap->height * 8) / 2);
+			} else {
+				y = (entities.player[0].y / 16) - (WINDOW_HEIGHT / 2);
+				if (y < 0) {y = 0;} else if (y + WINDOW_HEIGHT > tilemap->height * 8) {y = tilemap->height * 8 - WINDOW_HEIGHT;}
+			}
 			
 			game_render(framebuffer, x, y);
 			SDL_SetRenderTarget(renderer, NULL);
@@ -654,10 +663,18 @@ void main_loop(void) {
 					}
 				}
 				
-				x = (entities.player[0].x / 16) - (WINDOW_WIDTH / 2);
-				y = (entities.player[0].y / 16) - (WINDOW_HEIGHT / 2);
-				if (x < 0) {x = 0;} else if (x + WINDOW_WIDTH > tilemap->width * 8) {x = tilemap->width * 8 - WINDOW_WIDTH;}
-				if (y < 0) {y = 0;} else if (y + WINDOW_HEIGHT > tilemap->height * 8) {y = tilemap->height * 8 - WINDOW_HEIGHT;}
+				if (tilemap->width < WINDOW_WIDTH / 8) {
+					x = -((WINDOW_WIDTH - tilemap->width * 8) / 2);
+				} else {
+					x = (entities.player[0].x / 16) - (WINDOW_WIDTH / 2);
+					if (x < 0) {x = 0;} else if (x + WINDOW_WIDTH > tilemap->width * 8) {x = tilemap->width * 8 - WINDOW_WIDTH;}
+				}
+				if (tilemap->height <= WINDOW_HEIGHT / 8) {
+					y = -((WINDOW_HEIGHT - tilemap->height * 8) / 2);
+				} else {
+					y = (entities.player[0].y / 16) - (WINDOW_HEIGHT / 2);
+					if (y < 0) {y = 0;} else if (y + WINDOW_HEIGHT > tilemap->height * 8) {y = tilemap->height * 8 - WINDOW_HEIGHT;}
+				}
 				
 				game_render(framebuffer, x, y);
 				game_render_flush(framebuffer);
@@ -675,10 +692,18 @@ void main_loop(void) {
 				if (fade == 255) {
 					if (game_load_level(game_next_level)) {
 						game_state = STATE_FADE_OUT;
-						x = (entities.player[0].x / 16) - (WINDOW_WIDTH / 2);
-						y = (entities.player[0].y / 16) - (WINDOW_HEIGHT / 2);
-						if (x < 0) {x = 0;} else if (x + WINDOW_WIDTH > tilemap->width * 8) {x = tilemap->width * 8 - WINDOW_WIDTH;}
-						if (y < 0) {y = 0;} else if (y + WINDOW_HEIGHT > tilemap->height * 8) {y = tilemap->height * 8 - WINDOW_HEIGHT;}
+						if (tilemap->width < WINDOW_WIDTH / 8) {
+							x = -((WINDOW_WIDTH - tilemap->width * 8) / 2);
+						} else {
+							x = (entities.player[0].x / 16) - (WINDOW_WIDTH / 2);
+							if (x < 0) {x = 0;} else if (x + WINDOW_WIDTH > tilemap->width * 8) {x = tilemap->width * 8 - WINDOW_WIDTH;}
+						}
+						if (tilemap->height <= WINDOW_HEIGHT / 8) {
+							y = -((WINDOW_HEIGHT - tilemap->height * 8) / 2);
+						} else {
+							y = (entities.player[0].y / 16) - (WINDOW_HEIGHT / 2);
+							if (y < 0) {y = 0;} else if (y + WINDOW_HEIGHT > tilemap->height * 8) {y = tilemap->height * 8 - WINDOW_HEIGHT;}
+						}
 						
 						game_render(framebuffer, x, y);
 						SDL_SetRenderTarget(renderer, NULL);