From 6c195374bb51d3ee97489f8b91bbc7b86436fb1c Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Wed, 10 Jul 2013 21:54:14 +0200 Subject: [PATCH] Allow cursor keys (or joystick/gamepad) to control the mouse cursor. With this, the game can be played completely with only the keyboard, a joystick or a gamepad. --- code/intermission.cpp | 4 ++-- code/player.cpp | 31 ++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/code/intermission.cpp b/code/intermission.cpp index 0a00dd9..ca96b68 100644 --- a/code/intermission.cpp +++ b/code/intermission.cpp @@ -34,8 +34,8 @@ static void doCursor() { getPlayerInput(); - limitInt(&engine.cursor_x, 10, screen->w - 10); - limitInt(&engine.cursor_y, 10, screen->h - 10); + limitInt(&engine.cursor_x, 10, screen->w - 10 - shape[0]->w); + limitInt(&engine.cursor_y, 10, screen->h - 10 - shape[0]->h); blit(shape[0], engine.cursor_x, engine.cursor_y); } diff --git a/code/player.cpp b/code/player.cpp index 2b15502..35f3df9 100644 --- a/code/player.cpp +++ b/code/player.cpp @@ -299,15 +299,6 @@ void flushInput() void getPlayerInput() { - if (engine.gameSection == SECTION_INTERMISSION) - { - // Get the current mouse position - int x, y; - SDL_GetMouseState(&x, &y); - engine.cursor_x = x; - engine.cursor_y = y; - } - while (SDL_PollEvent(&engine.event)) { switch (engine.event.type) @@ -387,6 +378,28 @@ void getPlayerInput() engine.keyState[SDLK_F11] = engine.keyState[SDLK_LALT] = engine.keyState[SDLK_RETURN] = 0; } } + + if (engine.gameSection == SECTION_INTERMISSION) + { + // Get the current mouse position + static int px = -1, py = -1; + int x, y; + SDL_GetMouseState(&x, &y); + if (px == x && py == y) { + if(engine.keyState[SDLK_UP] && engine.cursor_y > 0) + engine.cursor_y -= 4; + if(engine.keyState[SDLK_DOWN] && engine.cursor_y < screen->h - 4) + engine.cursor_y += 4; + if(engine.keyState[SDLK_LEFT] && engine.cursor_x > 0) + engine.cursor_x -= 4; + if(engine.keyState[SDLK_RIGHT] && engine.cursor_x < screen->w - 4) + engine.cursor_x += 4; + } else { + engine.cursor_x = px = x; + engine.cursor_y = py = y; + } + } + } void leaveSector()