From 6b25cc3c8bb0ebd5f3239a12322824e91eb0e71a Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 25 Feb 2016 16:00:42 +0000 Subject: [PATCH] Clip camera using star systems. --- src/galaxy/galacticMap.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index 8c0f262..ac9d59d 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -60,6 +60,7 @@ static float ssx, ssy; static float arrowPulse; static int show; static int scrollingMap; +static PointF cameraMin, cameraMax; static Widget *startMissionButton; void initGalacticMap(void) @@ -185,10 +186,19 @@ static void doStarSystems(void) cx = app.mouse.x - 32; cy = app.mouse.y - 32; + cameraMin.x = cameraMin.y = 99999; + cameraMax.x = cameraMax.y = -99999; + selectedStarSystem = NULL; for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) { + cameraMin.x = MIN(cameraMin.x, starSystem->x); + cameraMin.y = MIN(cameraMin.y, starSystem->y); + + cameraMax.x = MAX(cameraMax.x, starSystem->x); + cameraMax.y = MAX(cameraMax.y, starSystem->y); + if (starSystem->availableMissions > 0 && collision(cx, cy, 64, 64, starSystem->x - camera.x, starSystem->y - camera.y, 4, 4)) { if (selectedStarSystem != starSystem) @@ -204,6 +214,12 @@ static void doStarSystems(void) } } } + + cameraMin.x -= SCREEN_WIDTH / 2; + cameraMin.y -= SCREEN_HEIGHT / 2; + + cameraMax.x -= SCREEN_WIDTH / 2; + cameraMax.y -= SCREEN_HEIGHT / 2; } } @@ -224,8 +240,8 @@ static void scrollGalaxy(void) ssx = -(app.mouse.dx / 3); ssy = -(app.mouse.dy / 3); - camera.x = MAX(-800, MIN(camera.x, 2464)); - camera.y = MAX(-475, MIN(camera.y, 1235)); + camera.x = MAX(cameraMin.x, MIN(camera.x, cameraMax.x)); + camera.y = MAX(cameraMin.y, MIN(camera.y, cameraMax.y)); } if (lastX == camera.x)