Now scrolling the galactic map by clicking and dragging.
This commit is contained in:
parent
855abe77cb
commit
17c55ec080
|
@ -57,6 +57,7 @@ static int pulseTimer;
|
||||||
static float ssx, ssy;
|
static float ssx, ssy;
|
||||||
static float arrowPulse;
|
static float arrowPulse;
|
||||||
static int show;
|
static int show;
|
||||||
|
static int scrollingMap;
|
||||||
static Widget *startMissionButton;
|
static Widget *startMissionButton;
|
||||||
|
|
||||||
void initGalacticMap(void)
|
void initGalacticMap(void)
|
||||||
|
@ -151,39 +152,40 @@ static void doStarSystems(void)
|
||||||
StarSystem *starSystem;
|
StarSystem *starSystem;
|
||||||
int cx, cy;
|
int cx, cy;
|
||||||
|
|
||||||
cx = app.mouse.x - 32;
|
if (!scrollingMap)
|
||||||
cy = app.mouse.y - 32;
|
|
||||||
|
|
||||||
selectedStarSystem = NULL;
|
|
||||||
|
|
||||||
for (starSystem = game.starSystemHead.next ; starSystem != NULL ; starSystem = starSystem->next)
|
|
||||||
{
|
{
|
||||||
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 (selectedStarSystem != starSystem)
|
||||||
|
|
||||||
if (app.mouse.button[SDL_BUTTON_LEFT])
|
|
||||||
{
|
{
|
||||||
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)
|
if (starSystem->side != SIDE_PANDORAN && starSystem->fallsToPandorans && starSystem->completedMissions == starSystem->totalMissions && starSystem->totalMissions > 0)
|
||||||
{
|
{
|
||||||
starSystem->side = SIDE_PANDORAN;
|
starSystem->side = SIDE_PANDORAN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void scrollGalaxy(void)
|
static void scrollGalaxy(void)
|
||||||
{
|
{
|
||||||
int dist;
|
|
||||||
float dx, dy;
|
|
||||||
int lastX, lastY;
|
int lastX, lastY;
|
||||||
|
|
||||||
lastX = camera.x;
|
lastX = camera.x;
|
||||||
|
@ -191,20 +193,13 @@ static void scrollGalaxy(void)
|
||||||
|
|
||||||
ssx = ssy = 0;
|
ssx = ssy = 0;
|
||||||
|
|
||||||
dist = getDistance(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, app.mouse.x, app.mouse.y);
|
if (scrollingMap)
|
||||||
if (dist > 256)
|
|
||||||
{
|
{
|
||||||
dx = (SCREEN_WIDTH / 2) - app.mouse.x;
|
camera.x -= app.mouse.dx * 1.5;
|
||||||
dy = (SCREEN_HEIGHT / 2) - app.mouse.y;
|
camera.y -= app.mouse.dy * 1.5;
|
||||||
|
|
||||||
dx /= 35;
|
ssx = -(app.mouse.dx / 3);
|
||||||
dy /= 35;
|
ssy = -(app.mouse.dy / 3);
|
||||||
|
|
||||||
camera.x -= dx;
|
|
||||||
camera.y -= dy;
|
|
||||||
|
|
||||||
ssx = -(dx / 5);
|
|
||||||
ssy = -(dy / 5);
|
|
||||||
|
|
||||||
camera.x = MAX(-800, MIN(camera.x, 2464));
|
camera.x = MAX(-800, MIN(camera.x, 2464));
|
||||||
camera.y = MAX(-475, MIN(camera.y, 1235));
|
camera.y = MAX(-475, MIN(camera.y, 1235));
|
||||||
|
@ -591,10 +586,16 @@ static void handleKeyboard(void)
|
||||||
|
|
||||||
static void handleMouse(void)
|
static void handleMouse(void)
|
||||||
{
|
{
|
||||||
switch (show)
|
if (app.mouse.button[SDL_BUTTON_LEFT])
|
||||||
{
|
{
|
||||||
case SHOW_STATS:
|
if (app.mouse.dx != 0 || app.mouse.dy != 0)
|
||||||
break;
|
{
|
||||||
|
scrollingMap = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
scrollingMap = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,6 +60,10 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
|
case SDL_MOUSEMOTION:
|
||||||
|
doMouseMotion(&event.motion);
|
||||||
|
break;
|
||||||
|
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
doMouseWheel(&event.wheel);
|
doMouseWheel(&event.wheel);
|
||||||
break;
|
break;
|
||||||
|
@ -125,6 +129,9 @@ int main(int argc, char *argv[])
|
||||||
expireTextTimer = SDL_GetTicks() + (1000 * 10);
|
expireTextTimer = SDL_GetTicks() + (1000 * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* always zero the mouse motion */
|
||||||
|
app.mouse.dx = app.mouse.dy = 0;
|
||||||
|
|
||||||
SDL_Delay(1);
|
SDL_Delay(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,7 @@ extern void saveScreenshot(void);
|
||||||
extern void doMouseDown(SDL_MouseButtonEvent *event);
|
extern void doMouseDown(SDL_MouseButtonEvent *event);
|
||||||
extern void doMouseUp(SDL_MouseButtonEvent *event);
|
extern void doMouseUp(SDL_MouseButtonEvent *event);
|
||||||
extern void doMouseWheel(SDL_MouseWheelEvent *event);
|
extern void doMouseWheel(SDL_MouseWheelEvent *event);
|
||||||
|
extern void doMouseMotion(SDL_MouseMotionEvent *event);
|
||||||
extern void doDevKeys(void);
|
extern void doDevKeys(void);
|
||||||
extern void expireTexts(int all);
|
extern void expireTexts(int all);
|
||||||
|
|
||||||
|
|
|
@ -356,6 +356,8 @@ typedef struct {
|
||||||
int y;
|
int y;
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
|
int dx;
|
||||||
|
int dy;
|
||||||
int button[MAX_MOUSE_BUTTONS];
|
int button[MAX_MOUSE_BUTTONS];
|
||||||
} Mouse;
|
} Mouse;
|
||||||
|
|
||||||
|
|
|
@ -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)
|
void setMouse(int x, int y)
|
||||||
{
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
|
|
Loading…
Reference in New Issue