diff --git a/src/galaxy/galacticMap.c b/src/galaxy/galacticMap.c index 38bae28..b2fa652 100644 --- a/src/galaxy/galacticMap.c +++ b/src/galaxy/galacticMap.c @@ -57,6 +57,7 @@ static int pulseTimer; static float ssx, ssy; static float arrowPulse; static int show; +static int scrollingMap; static Widget *startMissionButton; void initGalacticMap(void) @@ -151,39 +152,40 @@ static void doStarSystems(void) StarSystem *starSystem; int cx, cy; - cx = app.mouse.x - 32; - cy = app.mouse.y - 32; - - selectedStarSystem = NULL; - - for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) + if (!scrollingMap) { - if (starSystem->totalMissions > 0 && collision(cx, cy, 64, 64, starSystem->x - camera.x, starSystem->y - camera.y, 4, 4)) + cx = app.mouse.x - 32; + cy = app.mouse.y - 32; + + selectedStarSystem = NULL; + + for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next) { - if (selectedStarSystem != starSystem) + if (starSystem->totalMissions > 0 && collision(cx, cy, 64, 64, starSystem->x - camera.x, starSystem->y - camera.y, 4, 4)) { - selectedStarSystem = starSystem; - - if (app.mouse.button[SDL_BUTTON_LEFT]) + if (selectedStarSystem != starSystem) { - selectStarSystem(); + selectedStarSystem = starSystem; - app.mouse.button[SDL_BUTTON_LEFT] = 0; + if (app.mouse.button[SDL_BUTTON_LEFT]) + { + selectStarSystem(); + + app.mouse.button[SDL_BUTTON_LEFT] = 0; + } } } - } - - if (starSystem->side != SIDE_PANDORAN && starSystem->fallsToPandorans && starSystem->completedMissions == starSystem->totalMissions && starSystem->totalMissions > 0) - { - starSystem->side = SIDE_PANDORAN; + + if (starSystem->side != SIDE_PANDORAN && starSystem->fallsToPandorans && starSystem->completedMissions == starSystem->totalMissions && starSystem->totalMissions > 0) + { + starSystem->side = SIDE_PANDORAN; + } } } } static void scrollGalaxy(void) { - int dist; - float dx, dy; int lastX, lastY; lastX = camera.x; @@ -191,20 +193,13 @@ static void scrollGalaxy(void) ssx = ssy = 0; - dist = getDistance(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, app.mouse.x, app.mouse.y); - if (dist > 256) + if (scrollingMap) { - dx = (SCREEN_WIDTH / 2) - app.mouse.x; - dy = (SCREEN_HEIGHT / 2) - app.mouse.y; + camera.x -= app.mouse.dx * 1.5; + camera.y -= app.mouse.dy * 1.5; - dx /= 35; - dy /= 35; - - camera.x -= dx; - camera.y -= dy; - - ssx = -(dx / 5); - ssy = -(dy / 5); + 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)); @@ -591,10 +586,16 @@ static void handleKeyboard(void) static void handleMouse(void) { - switch (show) + if (app.mouse.button[SDL_BUTTON_LEFT]) { - case SHOW_STATS: - break; + if (app.mouse.dx != 0 || app.mouse.dy != 0) + { + scrollingMap = 1; + } + } + else + { + scrollingMap = 0; } } diff --git a/src/main.c b/src/main.c index 52b260b..005ba93 100644 --- a/src/main.c +++ b/src/main.c @@ -60,6 +60,10 @@ int main(int argc, char *argv[]) { switch (event.type) { + case SDL_MOUSEMOTION: + doMouseMotion(&event.motion); + break; + case SDL_MOUSEWHEEL: doMouseWheel(&event.wheel); break; @@ -124,6 +128,9 @@ int main(int argc, char *argv[]) expireTextTimer = SDL_GetTicks() + (1000 * 10); } + + /* always zero the mouse motion */ + app.mouse.dx = app.mouse.dy = 0; SDL_Delay(1); } diff --git a/src/main.h b/src/main.h index 5615343..a504a91 100644 --- a/src/main.h +++ b/src/main.h @@ -34,6 +34,7 @@ extern void saveScreenshot(void); extern void doMouseDown(SDL_MouseButtonEvent *event); extern void doMouseUp(SDL_MouseButtonEvent *event); extern void doMouseWheel(SDL_MouseWheelEvent *event); +extern void doMouseMotion(SDL_MouseMotionEvent *event); extern void doDevKeys(void); extern void expireTexts(int all); diff --git a/src/structs.h b/src/structs.h index aac61b0..ce6753a 100644 --- a/src/structs.h +++ b/src/structs.h @@ -356,6 +356,8 @@ typedef struct { int y; int w; int h; + int dx; + int dy; int button[MAX_MOUSE_BUTTONS]; } Mouse; diff --git a/src/system/input.c b/src/system/input.c index a80ad0c..5730390 100644 --- a/src/system/input.c +++ b/src/system/input.c @@ -54,6 +54,12 @@ void doMouseWheel(SDL_MouseWheelEvent *event) } } +void doMouseMotion(SDL_MouseMotionEvent *event) +{ + app.mouse.dx = event->xrel; + app.mouse.dy = event->yrel; +} + void setMouse(int x, int y) { SDL_Event event;