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/main.c | |
parent | f67cdf08cb3dba9c176eb81e137e2da4648d9ace (diff) |
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 49 |
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); |