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.
This commit is contained in:
parent
1853044891
commit
6c195374bb
|
@ -34,8 +34,8 @@ static void doCursor()
|
||||||
{
|
{
|
||||||
getPlayerInput();
|
getPlayerInput();
|
||||||
|
|
||||||
limitInt(&engine.cursor_x, 10, screen->w - 10);
|
limitInt(&engine.cursor_x, 10, screen->w - 10 - shape[0]->w);
|
||||||
limitInt(&engine.cursor_y, 10, screen->h - 10);
|
limitInt(&engine.cursor_y, 10, screen->h - 10 - shape[0]->h);
|
||||||
blit(shape[0], engine.cursor_x, engine.cursor_y);
|
blit(shape[0], engine.cursor_x, engine.cursor_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -299,15 +299,6 @@ void flushInput()
|
||||||
|
|
||||||
void getPlayerInput()
|
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))
|
while (SDL_PollEvent(&engine.event))
|
||||||
{
|
{
|
||||||
switch (engine.event.type)
|
switch (engine.event.type)
|
||||||
|
@ -387,6 +378,28 @@ void getPlayerInput()
|
||||||
engine.keyState[SDLK_F11] = engine.keyState[SDLK_LALT] = engine.keyState[SDLK_RETURN] = 0;
|
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()
|
void leaveSector()
|
||||||
|
|
Loading…
Reference in New Issue