From 2e5e37b0a5c77f0b3f1cc217b431236b51af5767 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Ortega=20Froysa?= Date: Mon, 16 Mar 2026 21:49:02 +0100 Subject: [PATCH] Fix display transformation and star generation for fullscreen mode. --- src/main.c | 21 +++++++++++++++------ src/starfield.c | 6 +++--- src/starfield.h | 4 +++- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index fb7c007..ff78ac2 100644 --- a/src/main.c +++ b/src/main.c @@ -55,6 +55,9 @@ const char *info_format = int main() { char title[32]; float zoom = 1.0f; + float display_width = WINDOW_WIDTH; + float display_height = WINDOW_HEIGHT; + sprintf(title, "SpaceShipSim v%s", VERSION); puts(title); @@ -121,6 +124,12 @@ int main() { // only redraw or run simulation if the timer event has occurred if(redraw) { + if(just_toggled_fullscreen) + { + display_width = al_get_display_width(display); + display_height = al_get_display_height(display); + } + if(paused == old_paused && key_is_down(KEY_PAUSE)) paused = !paused; else if(paused != old_paused && !key_is_down(KEY_PAUSE)) @@ -176,11 +185,11 @@ int main() { al_identity_transform(&transform); al_scale_transform(&transform, zoom, zoom); al_translate_transform(&transform, - WINDOW_WIDTH / 2.0f - ship.x * zoom, - WINDOW_HEIGHT / 2.0f - ship.y * zoom); + display_width / 2.0f - ship.x * zoom, + display_height / 2.0f - ship.y * zoom); al_use_transform(&transform); - starfield_draw(ship.x, ship.y, zoom); + starfield_draw(ship.x, ship.y, zoom, display_width, display_height); ship_draw(&ship); al_identity_transform(&transform); @@ -196,7 +205,7 @@ int main() { ship.velX * FPS, ship.velY * FPS); al_draw_multiline_text(font, al_map_rgb(0xFF, 0xFF, 0xFF), - 5, 5, WINDOW_WIDTH, 10.0f, + 5, 5, (int)display_width, 10.0f, ALLEGRO_ALIGN_LEFT, info); } @@ -205,8 +214,8 @@ int main() { { al_draw_multiline_text(font, al_map_rgb(0xFF, 0xFF, 0xFF), - (float)WINDOW_WIDTH / 2, (float)WINDOW_HEIGHT / 2 - 50, - WINDOW_WIDTH, 10.0f, + display_width / 2, display_height / 2 - 50, + (int)display_width, 10.0f, ALLEGRO_ALIGN_CENTRE, help); } diff --git a/src/starfield.c b/src/starfield.c index 4d99269..70c0acf 100644 --- a/src/starfield.c +++ b/src/starfield.c @@ -51,9 +51,9 @@ static void generate_chunk_stars(int chunk_x, int chunk_y) { } } -void starfield_draw(float camera_x, float camera_y, float zoom) { - float view_width = WINDOW_WIDTH / zoom; - float view_height = WINDOW_HEIGHT / zoom; +void starfield_draw(float camera_x, float camera_y, float zoom, float width, float height) { + float view_width = width / zoom; + float view_height = height / zoom; float left = camera_x - view_width / 2.0f; float right = camera_x + view_width / 2.0f; diff --git a/src/starfield.h b/src/starfield.h index 1ba6a2e..70bfec8 100644 --- a/src/starfield.h +++ b/src/starfield.h @@ -24,5 +24,7 @@ * @param camera_x The x position of the camera center. * @param camera_y The y position of the camera center. * @param zoom The zoom level (scale factor). + * @param width The display width in pixels. + * @param height The display height in pixels. */ -void starfield_draw(float camera_x, float camera_y, float zoom); +void starfield_draw(float camera_x, float camera_y, float zoom, float width, float height);